Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9e1ee97

Browse files
committed
Support for conditional breakpoints (Jim Fulton, with some changes).
1 parent 6683617 commit 9e1ee97

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

Lib/pdb.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,27 +96,39 @@ def do_break(self, arg):
9696
print self.get_all_breaks() # XXX
9797
return
9898
# Try line number as argument
99+
try:
100+
arg = eval(arg, self.curframe.f_globals,
101+
self.curframe.f_locals)
102+
except:
103+
print '*** Could not eval argument:', arg
104+
return
105+
106+
# Check for condition
107+
try: arg, cond = arg
108+
except: arg, cond = arg, None
109+
99110
try:
100-
lineno = int(eval(arg))
111+
lineno = int(arg)
101112
filename = self.curframe.f_code.co_filename
102113
except:
103114
# Try function name as the argument
104115
import codehack
105116
try:
106-
func = eval(arg, self.curframe.f_globals,
107-
self.curframe.f_locals)
117+
func = arg
108118
if hasattr(func, 'im_func'):
109119
func = func.im_func
110120
code = func.func_code
111121
except:
112-
print '*** Could not eval argument:', arg
122+
print '*** The specified object',
123+
print 'is not a function', arg
113124
return
114125
lineno = codehack.getlineno(code)
115126
filename = code.co_filename
116127

117128
# now set the break point
118-
err = self.set_break(filename, lineno)
129+
err = self.set_break(filename, lineno, cond)
119130
if err: print '***', err
131+
120132
do_b = do_break
121133

122134
def do_clear(self, arg):
@@ -352,10 +364,13 @@ def help_break(self):
352364
self.help_b()
353365

354366
def help_b(self):
355-
print """b(reak) [lineno | function]
367+
print """b(reak) [lineno | function] [, "condition"]
356368
With a line number argument, set a break there in the current
357369
file. With a function name, set a break at the entry of that
358-
function. Without argument, list all breaks."""
370+
function. Without argument, list all breaks. If a second
371+
argument is present, it is a string specifying an expression
372+
which must evaluate to true before the breakpoint is honored.
373+
"""
359374

360375
def help_clear(self):
361376
self.help_cl()

0 commit comments

Comments
 (0)