-
Notifications
You must be signed in to change notification settings - Fork 2
/
bdb-example-1.py
46 lines (45 loc) · 1.29 KB
/
bdb-example-1.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
import bdb
import time
def spam(n):
j= 0
for i in range(n):
j=j+ i
return n
def egg(n):
spam(n)
spam(n)
spam(n)
spam(n)
def test(n):
egg(n)
class myDebugger(bdb.Bdb):
run = 0
def user_call(self, frame, args):
name = frame.f_code.co_name or "<unknown>"
print "call", name, args
self.set_continue() # continue
def user_line(self, frame):
if self.run:
self.run = 0
self.set_trace() # start tracing
else:
# arrived at breakpoint
name = frame.f_code.co_name or "<unknown>"
filename = self.canonic(frame.f_code.co_filename)
print "break at", filename, frame.f_lineno, "in", name
print "continue..."
self.set_continue() # continue to next breakpoint
def user_return(self, frame, value):
name = frame.f_code.co_name or "<unknown>"
print "return from", name, value
print "continue..."
self.set_continue() # continue
def user_exception(self, frame, exception):
name = frame.f_code.co_name or "<unknown>"
print "exception in", name, exception
print "continue..."
self.set_continue() # continue
db = myDebugger()
db.run = 1
db.set_break("bdb-example-1.py", 7)
db.runcall(test, 1)