[Python-Dev] Enhancement to pdb in gud.el
Kevin J. Butler
python-kbutler at sabaydi.com
Fri Sep 19 10:24:58 EDT 2003
From: Nick Roberts <nick at nick.uklinux.net>
> Typing 'clear 1' gives Deleted breakpoint 1' and typing 'clear fib.py:4' gives
> no message and can't be detected. If, in both cases, the the message is
> modified to somthing like
>
> Deleted breakpoint 1 at /home/nick/python/fib.py:4
>
> then I would have enough information.
The attached modifications do it for me.
A couple of issues:
- I completely replaced the Bdb.get_break method. It was returning a
boolean indicating if the breakpoint existed or not, which appeared to
be an error (get_breaks returned the list of breakpoints). The method
was never used in bdb.py or pdb.py, so I replaced it with what I thought
it should be. :-) That is, it now returns the breakpoint instance
requested. If there is a reason, I can easily make this a new method
(get_breakpoint/get_breakpointinstance) rather than replacing get_break.
- I've duplicated logic from Bdb.clear_bpbynumber into a new method
get_bpbynumber. The logic differs only in the return error messages or
None. This seemed the simplest way to preserve the return value
semantics convention of the Bdb class.
- I'm also calling 'get', then 'clear' which does the work of 'get'
twice. I did this to preserve the return value conventions of Bdb and
make the breakpoint info available to the UI. Shouldn't be a
performance issue, right? ;-)
Suggestions before I submit these as a patch to SF?
Life-doesn't-get-any-better-than-contributing-to-emacs-in-Python-ly y'rs,
kb
Sorry for the non-CVS diffs - I don't have a copy of the 2.3 repository
right now:
*** bdb.py.1.42 Fri Sep 19 08:08:17 2003
--- bdb.py Fri Sep 19 08:00:52 2003
***************
*** 266,274 ****
self.breaks = {}
def get_break(self, filename, lineno):
! filename = self.canonic(filename)
! return filename in self.breaks and \
! lineno in self.breaks[filename]
def get_breaks(self, filename, lineno):
filename = self.canonic(filename)
--- 266,275 ----
self.breaks = {}
def get_break(self, filename, lineno):
! bplist = self.get_breaks( filename, lineno )
! if len( bplist ):
! return bplist[-1]
! return None
def get_breaks(self, filename, lineno):
filename = self.canonic(filename)
***************
*** 276,281 ****
--- 277,294 ----
lineno in self.breaks[filename] and \
Breakpoint.bplist[filename, lineno] or []
+ def get_bpbynumber(self, arg):
+ # duplicates logic from clear_bpbynumber
+ try:
+ number = int(arg)
+ except:
+ return None
+ try:
+ bp = Breakpoint.bpbynumber[number]
+ except IndexError:
+ return None
+ return bp
+
def get_file_breaks(self, filename):
filename = self.canonic(filename)
if filename in self.breaks:
*** pdb.py.1.66 Fri Sep 19 08:06:01 2003
--- pdb.py Fri Sep 19 08:07:23 2003
***************
*** 467,482 ****
except:
err = "Invalid line number (%s)" % arg
else:
err = self.clear_break(filename, lineno)
if err: print '***', err
return
numberlist = arg.split()
for i in numberlist:
err = self.clear_bpbynumber(i)
if err:
print '***', err
else:
! print 'Deleted breakpoint %s ' % (i,)
do_cl = do_clear # 'c' is already an abbreviation for 'continue'
def do_where(self, arg):
--- 467,486 ----
except:
err = "Invalid line number (%s)" % arg
else:
+ bp = self.get_break(filename, lineno)
err = self.clear_break(filename, lineno)
if err: print '***', err
+ else:
+ print 'Deleted breakpoint %s at %s:%s' % (i, bp.file,
bp.line)
return
numberlist = arg.split()
for i in numberlist:
+ bp = self.get_bpbynumber(i)
err = self.clear_bpbynumber(i)
if err:
print '***', err
else:
! print 'Deleted breakpoint %s at %s:%s' % (i, bp.file,
bp.line)
do_cl = do_clear # 'c' is already an abbreviation for 'continue'
def do_where(self, arg):
More information about the Python-Dev
mailing list