pdb patch to trace functions

Steve Kirsch (stk@infoseek.com)
Tue, 1 Mar 1994 19:43:03 +0800

Applying this patch to pdb allows the "b" command to take function
names as arguments, e.g.

b ftplib.print_line

*** pdb.py.orig Tue Mar 1 17:25:21 1994
--- pdb.py Tue Mar 1 19:32:59 1994
***************
*** 8,15 ****
import cmd
import bdb
import repr

-
class Pdb(bdb.Bdb, cmd.Cmd):

def __init__(self):
--- 8,15 ----
import cmd
import bdb
import repr
+ import codehack

class Pdb(bdb.Bdb, cmd.Cmd):

def __init__(self):
***************
*** 75,90 ****

do_h = cmd.Cmd.do_help

def do_break(self, arg):
if not arg:
print self.get_all_breaks() # XXX
return
! try:
lineno = int(eval(arg))
except:
! print '*** Error in argument:', `arg`
! return
! filename = self.curframe.f_code.co_filename
err = self.set_break(filename, lineno)
if err: print '***', err
do_b = do_break
--- 75,108 ----

do_h = cmd.Cmd.do_help

+ # Break function
+ #
+ # Args:
+ # No arg: show breakpoints
+ # Numeric: break at that line number
+ # function name: break at entry to that function
+
def do_break(self, arg):
if not arg:
print self.get_all_breaks() # XXX
return
! # Try line number as argument
! try:
lineno = int(eval(arg))
+ filename = self.curframe.f_code.co_filename
except:
! # Try function name as the argument
! try:
! g_frame=self.curframe.f_globals
! # get code object
! code=eval(arg,g_frame).func_code
! lineno = codehack.getlineno(code)
! filename = code.co_filename
! except:
! print '*** Could not eval argument:', arg
! return
!
! # now set the break point
err = self.set_break(filename, lineno)
if err: print '***', err
do_b = do_break