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

Skip to content

Commit 6ea27cc

Browse files
committed
Change clear_break() to the old signature clear_break(file, line).
Add new clear_bpbynumber() with single bpno argument. (Adapted from a patch by Richard Wolff.) Also some cleanup in error messages and moved some comments into a docstring.
1 parent 3bbef60 commit 6ea27cc

1 file changed

Lines changed: 40 additions & 26 deletions

File tree

Lib/bdb.py

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
# A generic Python debugger base class.
2-
# This class takes care of details of the trace facility;
3-
# a derived class should implement user interaction.
4-
# There are two debuggers based upon this:
5-
# 'pdb', a text-oriented debugger not unlike dbx or gdb;
6-
# and 'wdb', a window-oriented debugger.
7-
# And of course... you can roll your own!
1+
# Debugger basics
82

93
import sys
104
import types
115

126
BdbQuit = 'bdb.BdbQuit' # Exception to give up completely
137

148

15-
class Bdb: # Basic Debugger
9+
class Bdb:
1610

11+
"""Generic Python debugger base class.
12+
13+
This class takes care of details of the trace facility;
14+
a derived class should implement user interaction.
15+
The standard debugger class (pdb.Pdb) is an example.
16+
"""
17+
1718
def __init__(self):
1819
self.breaks = {}
1920

@@ -193,40 +194,46 @@ def set_break(self, filename, lineno, temporary=0, cond = None):
193194
import linecache # Import as late as possible
194195
line = linecache.getline(filename, lineno)
195196
if not line:
196-
return 'That line does not exist!'
197+
return 'Line %s:%d does not exist' % (filename,
198+
lineno)
197199
if not self.breaks.has_key(filename):
198200
self.breaks[filename] = []
199201
list = self.breaks[filename]
200202
if not lineno in list:
201203
list.append(lineno)
202204
bp = Breakpoint(filename, lineno, temporary, cond)
203-
print 'Breakpoint %d, at %s:%d.' %(bp.number, filename, lineno)
204205

205-
def clear_break(self, arg):
206-
try:
207-
number = int(arg)
208-
bp = Breakpoint.bpbynumber[int(arg)]
209-
except:
210-
return 'Invalid argument'
211-
if not bp:
212-
return 'Breakpoint already deleted'
213-
filename = bp.file
214-
lineno = bp.line
206+
def clear_break(self, filename, lineno):
215207
if not self.breaks.has_key(filename):
216-
return 'There are no breakpoints in that file!'
208+
return 'There are no breakpoints in %s' % filename
217209
if lineno not in self.breaks[filename]:
218-
return 'There is no breakpoint there!'
210+
return 'There is no breakpoint at %s:%d' % (filename,
211+
lineno)
219212
# If there's only one bp in the list for that file,line
220213
# pair, then remove the breaks entry
221-
if len(Breakpoint.bplist[filename, lineno]) == 1:
214+
for bp in Breakpoint.bplist[filename, lineno][:]:
215+
bp.deleteMe()
216+
if not Breakpoint.bplist.has_key((filename, lineno)):
222217
self.breaks[filename].remove(lineno)
223218
if not self.breaks[filename]:
224219
del self.breaks[filename]
225-
bp.deleteMe()
226220

221+
def clear_bpbynumber(self, arg):
222+
try:
223+
number = int(arg)
224+
except:
225+
return 'Non-numeric breakpoint number (%s)' % arg
226+
try:
227+
bp = Breakpoint.bpbynumber[number]
228+
except IndexError:
229+
return 'Breakpoint number (%d) out of range' % number
230+
if not bp:
231+
return 'Breakpoint (%d) already deleted' % number
232+
self.clear_break(bp.file, bp.line)
233+
227234
def clear_all_file_breaks(self, filename):
228235
if not self.breaks.has_key(filename):
229-
return 'There are no breakpoints in that file!'
236+
return 'There are no breakpoints in %s' % filename
230237
for line in self.breaks[filename]:
231238
blist = Breakpoint.bplist[filename, line]
232239
for bp in blist:
@@ -235,7 +242,7 @@ def clear_all_file_breaks(self, filename):
235242

236243
def clear_all_breaks(self):
237244
if not self.breaks:
238-
return 'There are no breakpoints!'
245+
return 'There are no breakpoints'
239246
for bp in Breakpoint.bpbynumber:
240247
if bp:
241248
bp.deleteMe()
@@ -245,6 +252,11 @@ def get_break(self, filename, lineno):
245252
return self.breaks.has_key(filename) and \
246253
lineno in self.breaks[filename]
247254

255+
def get_breaks(self, filename, lineno):
256+
return self.breaks.has_key(filename) and \
257+
lineno in self.breaks[filename] and \
258+
Breakpoint.bplist[filename, line] or []
259+
248260
def get_file_breaks(self, filename):
249261
if self.breaks.has_key(filename):
250262
return self.breaks[filename]
@@ -381,6 +393,8 @@ class Breakpoint:
381393
382394
"""
383395

396+
# XXX Keeping state in the class is a mistake -- this means
397+
# you cannot have more than one active Bdb instance.
384398

385399
next = 1 # Next bp to be assigned
386400
bplist = {} # indexed by (file, lineno) tuple

0 commit comments

Comments
 (0)