-
Notifications
You must be signed in to change notification settings - Fork 252
/
Copy pathmydbg.py
55 lines (47 loc) · 1.23 KB
/
mydbg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import sys
import linecache
def set_trace():
sys.settrace(dispatch)
def dispatch(frame, event, arg):
line = linecache.getline(
frame.f_code.co_filename,
frame.f_lineno,
)
# print(event)
# print(dir(frame))
print(line)
cmd = True
while cmd:
cmd = input('(Mydbg):')
run_cmd(cmd, frame)
# print("cmd = ", cmd)
return dispatch
def run_cmd(cmd, frame):
if cmd == 'where':
line = ''
line += " " + linecache.getline(
frame.f_code.co_filename,
frame.f_lineno - 1,
)
line += "!-->" + linecache.getline(
frame.f_code.co_filename,
frame.f_lineno,
)
line += " " + linecache.getline(
frame.f_code.co_filename,
frame.f_lineno + 1,
)
print(line)
return
if cmd == 'list':
print(frame.f_locals)
print(frame.f_globals)
if cmd in frame.f_locals:
print(frame.f_locals[cmd])
return
if cmd in frame.f_globals:
print(frame.f_globals[cmd])
if cmd == 'help':
print("'where' - view where run program")
print("'list' - view object")
print("press 'Enter' key to next step")