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

Skip to content

Commit 816a9fb

Browse files
committed
Change clear syntax to support three alternatives:
clear clear file:line clear bpno bpno ... Also print the breakpoint data after calling set_break(), because the print statement in set_break() has gone.
1 parent 6ea27cc commit 816a9fb

1 file changed

Lines changed: 47 additions & 3 deletions

File tree

Lib/pdb.py

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ def do_break(self, arg, temporary = 0):
234234
# now set the break point
235235
err = self.set_break(filename, line, temporary, cond)
236236
if err: print '***', err
237+
else:
238+
bp = self.get_breaks(filename, line)[-1]
239+
print "Breakpoint %d at %s:%d" % (bp.number,
240+
bp.file,
241+
bp.line)
237242

238243
# To be overridden in derived debuggers
239244
def defaultFile(self):
@@ -383,6 +388,10 @@ def do_ignore(self,arg):
383388
print bpnum, 'is reached.'
384389

385390
def do_clear(self, arg):
391+
# Three possibilities, tried in this order:
392+
# clear -> clear all breaks, ask for confirmation
393+
# clear file:lineno -> clear all breaks at file:lineno
394+
# clear bpno bpno ... -> clear breakpoints by number
386395
if not arg:
387396
try:
388397
reply = raw_input('Clear all breaks? ')
@@ -392,14 +401,47 @@ def do_clear(self, arg):
392401
if reply in ('y', 'yes'):
393402
self.clear_all_breaks()
394403
return
404+
if ':' in arg:
405+
# Make sure it works for "clear C:\foo\bar.py:12"
406+
i = string.rfind(arg, ':')
407+
filename = arg[:i]
408+
arg = arg[i+1:]
409+
try:
410+
lineno = int(arg)
411+
except:
412+
err = "Invalid line number (%s)" % arg
413+
else:
414+
err = self.clear_break(filename, lineno)
415+
if err: print '***', err
416+
return
395417
numberlist = string.split(arg)
396418
for i in numberlist:
397-
err = self.clear_break(i)
419+
err = self.clear_bpbynumber(i)
398420
if err:
399-
print '***'+err
421+
print '***', err
400422
else:
401423
print 'Deleted breakpoint %s ' % (i,)
402424
do_cl = do_clear # 'c' is already an abbreviation for 'continue'
425+
426+
def do_clear_break(self, arg):
427+
if not arg:
428+
self.do_clear("")
429+
return
430+
arg = string.strip(arg)
431+
# First arg is file, second is line, ignore anything else
432+
args = string.split(arg)
433+
if len(args) < 2:
434+
print '*** Specify file and line number.'
435+
return
436+
try:
437+
line = int(args[1])
438+
except:
439+
print '*** line number must be an integer.'
440+
return
441+
result =self.clear_break(args[0], line)
442+
if result:
443+
print result
444+
do_clb = do_clear_break
403445

404446
def do_where(self, arg):
405447
self.print_stack_trace()
@@ -657,10 +699,12 @@ def help_clear(self):
657699
self.help_cl()
658700

659701
def help_cl(self):
702+
print "cl(ear) filename:lineno"
660703
print """cl(ear) [bpnumber [bpnumber...]]
661704
With a space separated list of breakpoint numbers, clear
662705
those breakpoints. Without argument, clear all breaks (but
663-
first ask confirmation).
706+
first ask confirmation). With a filename:lineno argument,
707+
clear all breaks at that line in that file.
664708
665709
Note that the argument is different from previous versions of
666710
the debugger (in python distributions 1.5.1 and before) where

0 commit comments

Comments
 (0)