11 | If your browser doesn't automatically redirect to 12 | its new location, click 13 | 14 | here (http://docs.python.org/lib/lib.html). 15 |16 | 17 | 18 | -------------------------------------------------------------------------------- /test/thread/t2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ This is a script that is being used to debug whilst trying to get 3 | the thread debugging features working. 4 | """ 5 | 6 | import threading 7 | 8 | def foo(): 9 | for n in range(2): 10 | print n 11 | print "I am thread %s loop count %d" % \ 12 | (threading.currentThread().getName(), n) 13 | 14 | class MyThread(threading.Thread): 15 | def run(self): 16 | foo() 17 | 18 | def func(): 19 | for i in range(2): 20 | t = MyThread() 21 | t.start() 22 | t.join() 23 | 24 | if __name__ == '__main__': 25 | func() 26 | 27 | -------------------------------------------------------------------------------- /Doc/texinputs/pypaper.sty: -------------------------------------------------------------------------------- 1 | % 2 | % Change this to say a4paper instead of letterpaper if you want A4. These 3 | % are the latex defaults. 4 | % 5 | \newcommand{\py@paper}{letterpaper} 6 | \newcommand{\py@ptsize}{10pt} 7 | 8 | % These set up the fonts for the documents. 9 | % 10 | % The "times" package makes the default font the PostScript Times 11 | % font, which makes for smaller PostScript and a font that more people 12 | % like. 13 | % 14 | % The "avant" package causes the AvantGarde font to be used for 15 | % sans-serif text, instead of the uglier Helvetica set up by the "times" 16 | % package. 17 | % 18 | \RequirePackage{times}\typeout{Using Times instead of Computer Modern.} 19 | -------------------------------------------------------------------------------- /test/.cvsignore: -------------------------------------------------------------------------------- 1 | *.err 2 | *.out 3 | *.pyc 4 | *.pyo 5 | .pydbrc 6 | Makefile 7 | Makefile.in 8 | brkpt3.cmd 9 | brkpt3.right 10 | brkpt3t.right 11 | except.py 12 | file-2.5.right 13 | file.cmd 14 | file.right 15 | history.hst 16 | settrace.py 17 | test-complete.py 18 | test-connect.py 19 | test-contbug.py 20 | test-dbgcall.py 21 | test-disassem.py 22 | test-fifo-connect.py 23 | test-file.py 24 | test-fns.py 25 | test-help.py 26 | test-import.py 27 | test-linetrace.py 28 | test-pm.py 29 | test-run.py 30 | test-save.py 31 | test-setshow.py 32 | test-sig.py 33 | test-sighandle.py 34 | test-skip.py 35 | test-step.py 36 | test-tcp-connect.py 37 | test-trace.py 38 | test-with.py 39 | test.py 40 | trace.py 41 | -------------------------------------------------------------------------------- /test/.gitignore: -------------------------------------------------------------------------------- 1 | /*.out 2 | /*.pyc 3 | /*~ 4 | /Makefile 5 | /Makefile.in 6 | /brkpt3.cmd 7 | /brkpt3.right 8 | /brkpt3t.right 9 | /except.py 10 | /exceptbug.py 11 | /file-2.5.right 12 | /file.cmd 13 | /file.right 14 | /settrace.py 15 | /test-complete.py 16 | /test-connect.py 17 | /test-contbug.py 18 | /test-dbgcall.py 19 | /test-disassem.py 20 | /test-fifo-connect.py 21 | /test-file.py 22 | /test-fns.py 23 | /test-help.py 24 | /test-import.py 25 | /test-linetrace.py 26 | /test-pm.py 27 | /test-run.py 28 | /test-save.py 29 | /test-setshow.py 30 | /test-sig.py 31 | /test-sighandle.py 32 | /test-skip.py 33 | /test-step.py 34 | /test-tcp-connect.py 35 | /test-trace.py 36 | /test-with.py 37 | /test.py 38 | -------------------------------------------------------------------------------- /test/run.cmd: -------------------------------------------------------------------------------- 1 | # Test of restart and linetracing 2 | # $Id: run.cmd,v 1.6 2007/01/25 10:19:15 rockyb Exp $ 3 | # 4 | set basename on 5 | set trace-commands on 6 | info program 7 | continue 8 | ###################################### 9 | ### Now restart with a breakpoint 10 | ###################################### 11 | break hanoi 12 | show args 13 | run 14 | continue 15 | info args 16 | info program 17 | where 2 18 | ###################################### 19 | ### We should be at that breakpoint 20 | ### delete it and run again 21 | ### this time changing a parameter 22 | ###################################### 23 | info break 24 | delete 1 25 | run 1 26 | continue 27 | show args 28 | info args 29 | #### 30 | quit 31 | 32 | 33 | -------------------------------------------------------------------------------- /test/unit/pydbcmd.py.in: -------------------------------------------------------------------------------- 1 | #!@PYTHON@ -t 2 | 'Unit test for pydb.pydbcmd' 3 | import os, sys, unittest 4 | 5 | top_srcdir = "@top_srcdir@" 6 | if top_srcdir[-1] != os.path.sep: 7 | top_srcdir += os.path.sep 8 | sys.path.insert(0, os.path.join(top_srcdir, 'pydb')) 9 | 10 | from pydbcmd import Cmd 11 | 12 | class TestCmd(Cmd): 13 | def do_a(self): return 14 | def do_b(self): return 15 | def do_a(self): return 16 | pass 17 | 18 | class TestPydbCmd(unittest.TestCase): 19 | 20 | def test_get_cmd(self): 21 | test_cmd = TestCmd() 22 | self.assertEqual(['a', 'b', 'h', 'help'], test_cmd.get_cmds()) 23 | return 24 | pass 25 | 26 | if __name__ == '__main__': 27 | unittest.main() 28 | -------------------------------------------------------------------------------- /test/exceptbug.py.in: -------------------------------------------------------------------------------- 1 | #!@PYTHON@ -t 2 | from __future__ import with_statement 3 | import os, sys 4 | 5 | import threading 6 | 7 | top_builddir = "@top_builddir@" 8 | if top_builddir[-1] != os.path.sep: 9 | top_builddir += os.path.sep 10 | sys.path.insert(0, os.path.join(top_builddir, 'pydb')) 11 | top_srcdir = "@top_srcdir@" 12 | if top_srcdir[-1] != os.path.sep: 13 | top_srcdir += os.path.sep 14 | sys.path.insert(0, os.path.join(top_srcdir, 'pydb')) 15 | 16 | def f(): 17 | l = threading.Lock() 18 | with l: 19 | print "hello" 20 | raise Exception("error") 21 | print "world" 22 | 23 | try: 24 | f() 25 | except: 26 | import pydb 27 | # pydb.pm() 28 | pydb.pm(['set basename on','set interactive off', 'where','quit']) 29 | -------------------------------------------------------------------------------- /THANKS: -------------------------------------------------------------------------------- 1 | This debugger is an extension of the Python debugger pdb which 2 | did much of the heavy lifting. 3 | 4 | The manual also was taken from the Python debugger. But it also draws 5 | on my bashdb debugger reference and both of these at time use some of 6 | the organization and phrases from the GNU Debugger Manual (gdb). 7 | 8 | Stuart Frankel, Ph. Mad. did some amazing proof reading and editing of 9 | the manual. (I may have mucked it up some since then though.) 10 | 11 | Also thanks to: 12 | 13 | Stephen Emslie - Python Patch 1641544 14 | Matt Fleming - Gdb-style signal handling and NetBSD packaging 15 | Oleksandr Moskalenko - Debian packaging 16 | Alberto Griggio - Annotate patch #1781965 17 | 18 | $Id: THANKS,v 1.3 2007/10/30 11:37:42 rockyb Exp $ 19 | 20 | -------------------------------------------------------------------------------- /test/thread/tlock.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import sys, pydb 3 | import time 4 | import thread 5 | 6 | def myfunction(string,sleeptime,lock,*args): 7 | while 1: 8 | #entering critical section 9 | pydb.set_trace(add_threaddbg=True) 10 | lock.acquire() 11 | print string," Now Sleeping after Lock acquired for ",sleeptime 12 | time.sleep(sleeptime) 13 | print string," Now releasing lock and then sleeping again" 14 | lock.release() 15 | #exiting critical section 16 | time.sleep(sleeptime) # why? 17 | 18 | if __name__=="__main__": 19 | lock=thread.allocate_lock() 20 | thread.start_new_thread(myfunction,("Thread No:1",1,lock)) 21 | thread.start_new_thread(myfunction,("Thread No:2",1,lock)) 22 | 23 | while 1:pass 24 | 25 | -------------------------------------------------------------------------------- /test/data/noscript.right: -------------------------------------------------------------------------------- 1 | No stack. 2 | No stack. 3 | No stack. 4 | No frame selected. 5 | No frame selected. 6 | No stack. 7 | No stack. 8 | No stack. 9 | No breakpoints. 10 | No breakpoints. 11 | There are no auto-display expressions now. 12 | There are no auto-display expressions now. 13 | No frame selected. 14 | No frame selected. 15 | No line number information available. 16 | No line number information available. 17 | No frame selected. 18 | No frame selected. 19 | The program being debugged is not being run. 20 | The program being debugged is not being run. 21 | No current source file. 22 | No current source file. 23 | *** The program being debugged is not being run. 24 | No Python program loaded. 25 | *** No Python program registered. 26 | *** Perhaps you want to use the 'file' command? 27 | No stack. 28 | -------------------------------------------------------------------------------- /test/hanoi.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | """Towers of Hanoi""" 3 | import sys 4 | 5 | def hanoi(n,a,b,c): 6 | if n-1 > 0: 7 | hanoi(n-1, a, c, b) 8 | print "Move disk %s to %s" % (a, b) 9 | if n-1 > 0: 10 | hanoi(n-1, c, b, a) 11 | 12 | if __name__=='__main__': 13 | i_args=len(sys.argv) 14 | if i_args != 1 and i_args != 2: 15 | print "*** Need number of disks or no parameter" 16 | sys.exit(1) 17 | 18 | n=3 19 | 20 | if i_args > 1: 21 | try: 22 | n = int(sys.argv[1]) 23 | except ValueError, msg: 24 | print "** Expecting an integer, got: %s" % repr(sys.argv[1]) 25 | sys.exit(2) 26 | 27 | if n < 1 or n > 100: 28 | print "*** number of disks should be between 1 and 100" 29 | sys.exit(2) 30 | 31 | hanoi(n, "a", "b", "c") 32 | -------------------------------------------------------------------------------- /test/sigtestexample.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # $Id: sigtestexample.py,v 1.5 2006/10/08 19:56:27 rockyb Exp $ 3 | """Something to use to test signal handling. Basically we just need 4 | a program that installs a signal handler. 5 | """ 6 | import sys, os 7 | def signal_handler(num, f): 8 | f = open('log', 'w+') 9 | f.write('signal received\n') 10 | f.close() 11 | sys.exit(0) 12 | 13 | import signal 14 | signal.signal(signal.SIGUSR1, signal_handler) 15 | 16 | if len(sys.argv) > 1 and sys.argv[1] == 'signal': 17 | os.kill(os.getpid(), signal.SIGUSR1) 18 | # We need a statement after the above kill so we can see if the 19 | # debugger stop works. 20 | pass 21 | else: 22 | print "Pid %d" % os.getpid() 23 | reply = raw_input("Waiting in a read for signal USR1. " + 24 | "Type any key to terminate now.") 25 | 26 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | The Python community or whoever wrote pdb.py is largely responsible 2 | for this. 3 | 4 | Richard Wolff worked on the pydb.py that is in ddd. He 5 | also contributed a little to pdb.py. In email he relates: 6 | 7 | .. there was no attempt to make the two systems congruent. I 8 | haven't done any work on either for quite some time. I'm retired 9 | now and it's more than just unlikely that I'll ever do anything more 10 | on either. Which means that as far as ddd and pydb have anything to 11 | do with me, you're more than welcome to do whatever you like. 12 | 13 | This effort merges in changes that were in the ddd pydb.py but not in 14 | pdb.py. In particular, display expressions. 15 | 16 | The command interface is from GDB, and so much of the error messages 17 | and some parts of the documentation too. 18 | 19 | Coordination for putting this together is by Rocky Bernstein. 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /test/data/sighandler.right: -------------------------------------------------------------------------------- 1 | Signal Stop Print Stack Pass Description 2 | SIGHUP Yes Yes No No Hangup 3 | Signal Stop Print Stack Pass Description 4 | SIGHUP Yes Yes No No Hangup 5 | Signal Stop Print Stack Pass Description 6 | SIGINT Yes Yes No No Interrupt 7 | Signal Stop Print Stack Pass Description 8 | SIGINT No No Yes No Interrupt 9 | Signal Stop Print Stack Pass Description 10 | SIGINT No Yes Yes No Interrupt 11 | Signal Stop Print Stack Pass Description 12 | SIGINT No No No No Interrupt 13 | Signal Stop Print Stack Pass Description 14 | SIGKILL No No No Yes Killed 15 | Signal Stop Print Stack Pass Description 16 | SIGSTOP No No No Yes Stopped (signal) 17 | Signal Stop Print Stack Pass Description 18 | SIGINT No No No No Interrupt 19 | -------------------------------------------------------------------------------- /test/data/save.right: -------------------------------------------------------------------------------- 1 | +save foo bar 2 | *** Action has to be 'all', 'break' or 'settings; got 'foo'. 3 | +save foo bar baz 4 | *** Expecting 0-2 arguments, got 3. 5 | +save break ./savefile.txt 6 | Breakpoints saved to file ./savefile.txt 7 | +p len(open('./savefile.txt').readlines()) 8 | 1 9 | +source ./savefile.txt 10 | +break 17 11 | Breakpoint 1 set in file gcd.py, line 17. 12 | +save break ./savefile.txt 13 | Breakpoints saved to file ./savefile.txt 14 | +source ./savefile.txt 15 | +p open('./savefile.txt').readlines() 16 | ['break gcd.py:17\n'] 17 | +save settings ./savefile.txt 18 | Settings saved to file ./savefile.txt 19 | +source -v ./savefile.txt 20 | +p len(open('./savefile.txt').readlines()) 21 | +p len(open('./savefile.txt').readlines()) 22 | 12 23 | +save all ./savefile.txt 24 | +save all ./savefile.txt 25 | Settings and breakpoints saved to file ./savefile.txt 26 | +source ./savefile.txt 27 | +source ./savefile.txt 28 | +quit 29 | -------------------------------------------------------------------------------- /test/brkpt3.cmd.in: -------------------------------------------------------------------------------- 1 | # 2 | # Test of breakpoint handling 3 | # $Id: brkpt3.cmd.in,v 1.1 2007/02/13 11:42:54 rockyb Exp $ 4 | # 5 | set basename on 6 | set trace-commands on 7 | ############################################################### 8 | ### Test bad command parameters 9 | ############################################################### 10 | # Non integer argument 11 | commands a 12 | # No such breakpoint number 13 | commands 5 14 | ############################################################### 15 | ### Test valid command. Note that in order to do this 16 | ### here we need to use the "source" command so that 17 | ### input doesn't get confused. 18 | ### FIXME: somehow output isn't coming out. 19 | ### but at least we're testing part 20 | ### parsing to the "end" 21 | ############################################################### 22 | break 28 23 | cd @srcdir@ 24 | source comm1.cmd 25 | continue 26 | break 31 27 | source comm2.cmd 28 | cd @builddir@ 29 | continue 30 | quit 31 | -------------------------------------------------------------------------------- /test/data/pm.right: -------------------------------------------------------------------------------- 1 | +set interactive off 2 | +set basename on 3 | +show args 4 | Argument list to give program being debugged when it is started is 5 | "". 6 | +info args 7 | +list 8 | 29 pydir = os.path.join(top_builddir, "pydb") 9 | 30 pydb_short = "pydb.py" 10 | 31 pydb_path = os.path.join(pydir, pydb_short) 11 | 32 12 | 33 def raise_error(): 13 | 34 -> raise FloatingPointError 14 | 35 15 | 36 class PdbTests(unittest.TestCase): 16 | 37 17 | 38 ## Don't use assertTrue to be compatible with older version of 18 | +# Completion might not be available if no readline 19 | +# complete s 20 | +# complete help s 21 | +where 22 | +step 23 | *** The program being debugged is not being run. 24 | +next 25 | *** The program being debugged is not being run. 26 | +finish 27 | *** The program being debugged is not being run. 28 | +return 29 | *** The program being debugged is not being run. 30 | +quit 31 | (test-pm.py:34): raise_error 32 | 34 raise FloatingPointError 33 | -------------------------------------------------------------------------------- /test/except.py.in: -------------------------------------------------------------------------------- 1 | #!@PYTHON@ -t 2 | # $Id: except.py.in,v 1.4 2007/01/25 19:04:45 rockyb Exp $ 3 | """Test to see if handles an exception when an error is raised.""" 4 | import os, sys 5 | 6 | top_builddir = "@top_builddir@" 7 | if top_builddir[-1] != os.path.sep: 8 | top_builddir += os.path.sep 9 | sys.path.insert(0, os.path.join(top_builddir, 'pydb')) 10 | top_srcdir = "@top_srcdir@" 11 | if top_srcdir[-1] != os.path.sep: 12 | top_srcdir += os.path.sep 13 | sys.path.insert(0, os.path.join(top_srcdir, 'pydb')) 14 | 15 | print __doc__ 16 | 17 | import pydb 18 | pydb.debugger() # we go into the debugger 19 | print "Returning from the debugger" 20 | # Set a variable so we can show the state is 21 | # somewhere after the above set_trace() 22 | z='After set_trace' 23 | try: 24 | # The below statement should not enter the debugger 25 | x=2/0 26 | except: 27 | pass 28 | # We should enter the debugger on the next statement. 29 | y=1/0 # Bullwinkle: This time, for sure! 30 | pass 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /test/data/brkpt3.right: -------------------------------------------------------------------------------- 1 | +############################################################### 2 | +### Test bad command parameters 3 | +############################################################### 4 | +# Non integer argument 5 | +commands a 6 | *** 'commands' command: Expecting a positive integer, got: a 7 | +# No such breakpoint number 8 | +commands 5 9 | *** No breakpoint numbered 5. 10 | +############################################################### 11 | +### Test valid command. Note that in order to do this 12 | +### here we need to use the "source" command so that 13 | +### input doesn't get confused. 14 | +### FIXME: somehow output isn't coming out. 15 | +### but at least we're testing part 16 | +### parsing to the "end" 17 | +############################################################### 18 | +break 28 19 | Breakpoint 1 set in file gcd.py, line 28. 20 | +cd . 21 | +source comm1.cmd 22 | +continue 23 | +break 31 24 | Breakpoint 2 set in file gcd.py, line 31. 25 | +source comm2.cmd 26 | +cd . 27 | +continue 28 | +quit 29 | -------------------------------------------------------------------------------- /test/brkpt3.right.in: -------------------------------------------------------------------------------- 1 | +############################################################### 2 | +### Test bad command parameters 3 | +############################################################### 4 | +# Non integer argument 5 | +commands a 6 | *** 'commands' command: Expecting a positive integer, got: a 7 | +# No such breakpoint number 8 | +commands 5 9 | *** No breakpoint numbered 5. 10 | +############################################################### 11 | +### Test valid command. Note that in order to do this 12 | +### here we need to use the "source" command so that 13 | +### input doesn't get confused. 14 | +### FIXME: somehow output isn't coming out. 15 | +### but at least we're testing part 16 | +### parsing to the "end" 17 | +############################################################### 18 | +break 28 19 | Breakpoint 1 set in file gcd.py, line 28. 20 | +cd @srcdir@ 21 | +source comm1.cmd 22 | +continue 23 | +break 31 24 | Breakpoint 2 set in file gcd.py, line 31. 25 | +source comm2.cmd 26 | +cd @builddir@ 27 | +continue 28 | +quit 29 | -------------------------------------------------------------------------------- /test/data/history.right: -------------------------------------------------------------------------------- 1 | +set history size 5 2 | +set history filename 3 | *** Argument required (filename to set it to). 4 | +set history filename history.hst 5 | +show history 6 | filename: The filename in which to record the command history is 7 | "history.hst". 8 | save: Saving of the history record on exit is off 9 | size: The size of the command history is 5 10 | +######################################### 11 | +# Test save on and off. 12 | +# Test also using short abbreviated name 13 | +######################################### 14 | +set his save off 15 | +set hi save on 16 | +list 17 | 1 #!/usr/bin/python 18 | 2 -> """Towers of Hanoi""" 19 | 3 import sys 20 | 4 21 | 5 def hanoi(n,a,b,c): 22 | 6 if n-1 > 0: 23 | 7 hanoi(n-1, a, c, b) 24 | 8 print "Move disk %s to %s" % (a, b) 25 | 9 if n-1 > 0: 26 | 10 hanoi(n-1, c, b, a) 27 | +show hi 28 | filename: The filename in which to record the command history is 29 | "history.hst". 30 | save: Saving of the history record on exit is on 31 | size: The size of the command history is 5 32 | +quit 33 | -------------------------------------------------------------------------------- /test/test-import.py.in: -------------------------------------------------------------------------------- 1 | #!@PYTHON@ -t 2 | # $Id: test-import.py.in,v 1.2 2008/12/10 13:31:26 rockyb Exp $ -*- Python -*- 3 | "Unit test of 'import pydb'" 4 | import os, sys, unittest 5 | 6 | top_builddir = "@top_builddir@" 7 | if top_builddir[-1] != os.path.sep: 8 | top_builddir += os.path.sep 9 | top_srcdir = "@top_srcdir@" 10 | if top_srcdir[-1] != os.path.sep: 11 | top_srcdir += os.path.sep 12 | 13 | builddir = "@builddir@" 14 | if builddir[-1] != os.path.sep: 15 | builddir += os.path.sep 16 | 17 | srcdir = "@srcdir@" 18 | if srcdir[-1] != os.path.sep: 19 | srcdir += os.path.sep 20 | 21 | class PdbTests(unittest.TestCase): 22 | 23 | def test_import(self): 24 | """Test that 'import pydb' works""" 25 | cmd = ("@PYTHON@ -c 'import os, sys; " + 26 | "sys.path.insert(0, \"%s\"); " + 27 | "sys.path.insert(0, \"%s\"); " + 28 | "import pydb'" ) % (top_builddir, top_srcdir) 29 | rc = os.system(cmd) >> 8 30 | self.assertEqual(0, rc, "python import pydb") 31 | return 32 | 33 | if __name__ == "__main__": 34 | unittest.main() 35 | -------------------------------------------------------------------------------- /test/run2.cmd: -------------------------------------------------------------------------------- 1 | # Test of restart and linetracing 2 | # $Id: run2.cmd,v 1.3 2007/01/25 10:19:15 rockyb Exp $ 3 | # 4 | set basename on 5 | set trace-commands on 6 | info program 7 | continue 8 | info program 9 | ###################################### 10 | ### Program munges sys.argv 11 | ### see if we can rerun it okay 12 | ###################################### 13 | set interactive on 14 | run 3 5 15 | ###################################### 16 | ### Break of a fn name and 17 | ### Try a return where there is none 18 | ### either because not in subroutine 19 | ### or no "return" statement 20 | ###################################### 21 | set interactive off 22 | break check_args 23 | return 24 | continue 25 | return 26 | ###################################### 27 | ### rerun wrong number of parameters 28 | ### that causes and exception 29 | ### and use "info program" to check 30 | ### termination 31 | ###################################### 32 | set interactive on 33 | info program 34 | run 5 10 35 | continue 36 | break gcd 37 | continue 38 | info program 39 | set linetrace on 40 | set interactive off 41 | return 42 | where 43 | quit 44 | -------------------------------------------------------------------------------- /test/dbgcall.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | """Towers of Hanoi - testing calling debugger with continue and cmds""" 3 | import sys 4 | 5 | sys.path.insert(0, '..') 6 | import pydb 7 | 8 | pydb.debugger(dbg_cmds=['set basename on', 'set linetrace on', 'step 20']) 9 | 10 | def hanoi(n,a,b,c): 11 | if n-1 > 0: 12 | hanoi(n-1, a, c, b) 13 | print "Move disk %s to %s" % (a, b) 14 | if n-1 > 0: 15 | hanoi(n-1, c, b, a) 16 | 17 | if __name__=='__main__': 18 | i_args=len(sys.argv) 19 | if i_args != 1 and i_args != 2: 20 | print "*** Need number of disks or no parameter" 21 | sys.exit(1) 22 | 23 | n=3 24 | sys.settrace(None) 25 | if i_args > 1: 26 | try: 27 | n = int(sys.argv[1]) 28 | except ValueError, msg: 29 | print "** Expecting an integer, got: %s" % repr(sys.argv[1]) 30 | sys.exit(2) 31 | 32 | pydb.debugger(status='continue', 33 | dbg_cmds=['p "continued"', 'step 2', 'c']) 34 | if n < 1 or n > 100: 35 | print "*** number of disks should be between 1 and 100" 36 | sys.exit(2) 37 | 38 | hanoi(n, "a", "b", "c") 39 | -------------------------------------------------------------------------------- /test/data/brkpt3t.right: -------------------------------------------------------------------------------- 1 | --Call level -1 2 | +############################################################### 3 | +### Test bad command parameters 4 | +############################################################### 5 | +# Non integer argument 6 | +commands a 7 | *** 'commands' command: Expecting a positive integer, got: a 8 | +# No such breakpoint number 9 | +commands 5 10 | *** No breakpoint numbered 5. 11 | +############################################################### 12 | +### Test valid command. Note that in order to do this 13 | +### here we need to use the "source" command so that 14 | +### input doesn't get confused. 15 | +### FIXME: somehow output isn't coming out. 16 | +### but at least we're testing part 17 | +### parsing to the "end" 18 | +############################################################### 19 | +break 28 20 | Breakpoint 1 set in file gcd.py, line 28. 21 | +cd . 22 | +source comm1.cmd 23 | +continue 24 | +break 31 25 | Breakpoint 2 set in file gcd.py, line 31. 26 | +source comm2.cmd 27 | +cd . 28 | +continue 29 | +quit 30 | Requesting exit from MainThread (id -1209792848) 31 | The program exited via sys.exit(). Exit status: 32 | -------------------------------------------------------------------------------- /test/data/brkpt3-2.5t.right: -------------------------------------------------------------------------------- 1 | --Call level -1 2 | +############################################################### 3 | +### Test bad command parameters 4 | +############################################################### 5 | +# Non integer argument 6 | +commands a 7 | *** 'commands' command: Expecting a positive integer, got: a 8 | +# No such breakpoint number 9 | +commands 5 10 | *** No breakpoint numbered 5. 11 | +############################################################### 12 | +### Test valid command. Note that in order to do this 13 | +### here we need to use the "source" command so that 14 | +### input doesn't get confused. 15 | +### FIXME: somehow output isn't coming out. 16 | +### but at least we're testing part 17 | +### parsing to the "end" 18 | +############################################################### 19 | +break 28 20 | Breakpoint 1 set in file gcd.py, line 28. 21 | +cd . 22 | +source comm1.cmd 23 | +continue 24 | +break 31 25 | Breakpoint 2 set in file gcd.py, line 31. 26 | +source comm2.cmd 27 | +cd . 28 | +continue 29 | +quit 30 | Requesting exit from MainThread (id -1210472784) 31 | The program exited via sys.exit(). Exit status: 32 | -------------------------------------------------------------------------------- /test/gcd.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | """Greatest Common Divisor 3 | 4 | Some characterstics of this program used for testing check_args() does 5 | not have a 'return' statement. 6 | 7 | check_args() raises an uncaught exception when given the wrong number 8 | of parameters. 9 | 10 | """ 11 | import sys 12 | 13 | def check_args(): 14 | if len(sys.argv) != 3: 15 | # Rather than use sys.exit let's just raise an error 16 | raise Exception, "Need to give two numbers" 17 | for i in range(2): 18 | try: 19 | sys.argv[i+1] = int(sys.argv[i+1]) 20 | except ValueError: 21 | print "** Expecting an integer, got: %s" % repr(sys.argv[i]) 22 | sys.exit(2) 23 | 24 | def gcd(a,b): 25 | """ GCD. We assume positive numbers""" 26 | 27 | # Make: a <= b 28 | if a > b: 29 | (a, b) = (b, a) 30 | 31 | if a <= 0: 32 | return None 33 | if a == 1 or b-a == 0: 34 | return a 35 | return gcd(b-a, a) 36 | 37 | if __name__=='__main__': 38 | check_args() 39 | 40 | (a, b) = sys.argv[1:3] 41 | print "The GCD of %d and %d is %d" % (a, b, gcd(a, b)) 42 | 43 | -------------------------------------------------------------------------------- /test/brkpt3t.right.in: -------------------------------------------------------------------------------- 1 | --Call level -1 2 | +############################################################### 3 | +### Test bad command parameters 4 | +############################################################### 5 | +# Non integer argument 6 | +commands a 7 | *** 'commands' command: Expecting a positive integer, got: a 8 | +# No such breakpoint number 9 | +commands 5 10 | *** No breakpoint numbered 5. 11 | +############################################################### 12 | +### Test valid command. Note that in order to do this 13 | +### here we need to use the "source" command so that 14 | +### input doesn't get confused. 15 | +### FIXME: somehow output isn't coming out. 16 | +### but at least we're testing part 17 | +### parsing to the "end" 18 | +############################################################### 19 | +break 28 20 | Breakpoint 1 set in file gcd.py, line 28. 21 | +cd @srcdir@ 22 | +source comm1.cmd 23 | +continue 24 | +break 31 25 | Breakpoint 2 set in file gcd.py, line 31. 26 | +source comm2.cmd 27 | +cd @builddir@ 28 | +continue 29 | +quit 30 | Requesting exit from MainThread (id -1209792848) 31 | The program exited via sys.exit(). Exit status: 32 | -------------------------------------------------------------------------------- /test/unit/fns.py.in: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 'Unit test for pydb.fns' 3 | import os, sys, unittest 4 | 5 | top_builddir = "../.." 6 | if top_builddir[-1] != os.path.sep: 7 | top_builddir += os.path.sep 8 | sys.path.insert(0, os.path.join(top_builddir, 'pydb')) 9 | top_srcdir = "../.." 10 | if top_srcdir[-1] != os.path.sep: 11 | top_srcdir += os.path.sep 12 | sys.path.insert(0, os.path.join(top_srcdir, 'pydb')) 13 | 14 | from fns import printf, print_argspec 15 | 16 | class TestFns(unittest.TestCase): 17 | 18 | def test_fns_printf(self): 19 | self.assertEqual('037', printf(31, "/o")) 20 | self.assertEqual('00011111', printf(31, "/t")) 21 | self.assertEqual('!', printf(33, "/c")) 22 | self.assertEqual('0x21', printf(33, "/x")) 23 | return 24 | 25 | def test_fns_argspec(self): 26 | self.assertEqual('test_fns_argspec(self)', 27 | print_argspec(self.test_fns_argspec, 28 | 'test_fns_argspec')) 29 | self.assertFalse(print_argspec(None, 'invalid_fn')) 30 | return 31 | pass 32 | 33 | if __name__ == '__main__': 34 | unittest.main() 35 | -------------------------------------------------------------------------------- /test/thread/q.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | 4 | import thread 5 | import time 6 | from threading import * 7 | import Queue 8 | 9 | class Producer(Thread): 10 | 11 | def __init__(self,itemq): 12 | Thread.__init__(self) 13 | self.itemq=itemq 14 | 15 | def run(self): 16 | 17 | itemq=self.itemq 18 | i=0 19 | for j in range(10): 20 | 21 | print currentThread(),"Produced One Item:",i 22 | itemq.put(i,1) 23 | i+=1 24 | time.sleep(1) 25 | 26 | 27 | class Consumer(Thread): 28 | 29 | def __init__(self,itemq): 30 | Thread.__init__(self) 31 | self.itemq=itemq 32 | 33 | def run(self): 34 | itemq=self.itemq 35 | 36 | for j in range(4): 37 | time.sleep(2) 38 | it=itemq.get(1) 39 | print currentThread(),"Consumed One Item:",it 40 | 41 | if __name__=="__main__": 42 | 43 | q=Queue.Queue(10) 44 | 45 | pro=Producer(q) 46 | cons1=Consumer(q) 47 | cons2=Consumer(q) 48 | 49 | pro.start() 50 | cons1.start() 51 | cons2.start() 52 | pro.join() 53 | cons1.join() 54 | cons2.join() 55 | -------------------------------------------------------------------------------- /test/unit/bytecode.py.in: -------------------------------------------------------------------------------- 1 | #!@PYTHON@ -t 2 | 'Unit test for pydb.bytecode' 3 | import inspect, os, sys, unittest 4 | 5 | top_srcdir = "@top_srcdir@" 6 | if top_srcdir[-1] != os.path.sep: 7 | top_srcdir += os.path.sep 8 | sys.path.insert(0, os.path.join(top_srcdir, 'pydb')) 9 | 10 | from bytecode import op_at_frame, stmt_contains_make_function, is_def_stmt 11 | 12 | class TestByteCode(unittest.TestCase): 13 | 14 | def test_contains_make_function(self): 15 | def sqr(x): 16 | return x * x 17 | frame = inspect.currentframe() 18 | co = frame.f_code 19 | lineno = frame.f_lineno 20 | self.assertTrue(stmt_contains_make_function(co, lineno-4)) 21 | self.assertFalse(stmt_contains_make_function(co, lineno)) 22 | return 23 | 24 | def test_op_at_frame(self): 25 | frame = inspect.currentframe() 26 | self.assertEqual('CALL_FUNCTION', op_at_frame(frame)) 27 | return 28 | 29 | def test_is_def_frame(self): 30 | # Not a "def" statement because frame is wrong spot 31 | frame = inspect.currentframe() 32 | self.assertFalse(is_def_stmt('foo(): pass', frame)) 33 | return 34 | 35 | if __name__ == '__main__': 36 | unittest.main() 37 | -------------------------------------------------------------------------------- /Doc/info/Makefile: -------------------------------------------------------------------------------- 1 | # Generate the Python "info" documentation. 2 | 3 | TOPDIR=.. 4 | TOOLSDIR=$(TOPDIR)/tools 5 | HTMLDIR=$(TOPDIR)/html 6 | 7 | # The emacs binary used to build the info docs. GNU Emacs 21 is required. 8 | EMACS=emacs 9 | 10 | MKINFO=$(TOOLSDIR)/mkinfo 11 | SCRIPTS=$(TOOLSDIR)/checkargs.pm $(TOOLSDIR)/mkinfo $(TOOLSDIR)/py2texi.el 12 | 13 | # set VERSION to code the VERSION number into the info file name 14 | # allowing installation of more than one set of python info docs 15 | # into the same directory 16 | VERSION= 17 | 18 | all: check-emacs-version \ 19 | lib 20 | # doc inst 21 | 22 | lib: python$(VERSION)-lib.info 23 | 24 | whatsnew: $(WHATSNEW) 25 | $(WHATSNEW): python$(VERSION)-$(WHATSNEW).info 26 | 27 | check-emacs-version: 28 | @v="`$(EMACS) --version 2>&1 | egrep '^(GNU |X)Emacs [12]*'`"; \ 29 | if `echo "$$v" | egrep '^GNU Emacs 2[1-3]' >/dev/null 2>&1`; then \ 30 | echo "Using $(EMACS) to build the info docs"; \ 31 | else \ 32 | echo "GNU Emacs 21 or greater is required to build the info docs"; \ 33 | echo "Found $$v"; \ 34 | false; \ 35 | fi 36 | 37 | python$(VERSION)-lib.info: ../lib/lib.tex $(SCRIPTS) 38 | EMACS=$(EMACS) $(MKINFO) $< $*.texi $@ 39 | 40 | clean: 41 | rm -f *.texi~ *.texi 42 | 43 | clobber: clean 44 | rm -f *.texi python*-*.info python*-*.info-[0-9]* 45 | -------------------------------------------------------------------------------- /test/data/Makefile.am: -------------------------------------------------------------------------------- 1 | check_DATA = \ 2 | brkpt1.right \ 3 | brkpt1t.right \ 4 | brkpt2-2.3.right \ 5 | brkpt2.right \ 6 | brkpt3t.right \ 7 | brkpt3-2.5t.right \ 8 | brkpt3.right \ 9 | checkline.py \ 10 | cmdparse.right \ 11 | contbug-2.5.right \ 12 | contbug.right \ 13 | dbgcall.right \ 14 | dbgcall-2.5.right \ 15 | file.right \ 16 | file-2.5.right \ 17 | filebug.right \ 18 | fntrace.right \ 19 | help.right \ 20 | history.right \ 21 | logging.right \ 22 | noscript.right \ 23 | pm.right \ 24 | pydbrc.right \ 25 | run.right \ 26 | run2.right \ 27 | save.right \ 28 | setshow.right \ 29 | setshow-no-rl.right \ 30 | sighandler.right \ 31 | skip.right \ 32 | step.right \ 33 | trace-2.4-final.right \ 34 | trace-2.5.right \ 35 | trace.right \ 36 | tracetest-2.4-final.right \ 37 | tracetest-2.5.right \ 38 | tracetest.right \ 39 | withbug.right \ 40 | withbug-2.6.right 41 | 42 | EXTRA_DIST = $(check_DATA) 43 | -------------------------------------------------------------------------------- /test/settrace.py.in: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | """Towers of Hanoi""" 3 | import sys, os 4 | 5 | top_builddir = "@top_builddir@" 6 | if top_builddir[-1] != os.path.sep: 7 | top_builddir += os.path.sep 8 | sys.path.insert(0, os.path.join(top_builddir, 'pydb')) 9 | top_srcdir = "@top_srcdir@" 10 | if top_srcdir[-1] != os.path.sep: 11 | top_srcdir += os.path.sep 12 | sys.path.insert(0, os.path.join(top_srcdir, 'pydb')) 13 | 14 | def hanoi(n,a,b,c): 15 | if n-1 > 0: 16 | hanoi(n-1, a, c, b) 17 | print "Move disk %s to %s" % (a, b) 18 | if n-1 > 0: 19 | hanoi(n-1, c, b, a) 20 | 21 | i_args=len(sys.argv) 22 | if i_args > 3: 23 | print "usage %s [disks [cmdfile]]" % sys.argv[0] 24 | sys.exit(1) 25 | 26 | n=3 27 | if i_args > 1: 28 | try: 29 | n = int(sys.argv[1]) 30 | except ValueError, msg: 31 | print "** Expecting an integer, got: %s" % repr(sys.argv[1]) 32 | sys.exit(2) 33 | 34 | if n < 1 or n > 100: 35 | print "*** number of disks should be between 1 and 100" 36 | sys.exit(2) 37 | 38 | dbg_cmds=['set basename on', 39 | 'where', 40 | 'list', 41 | 'step', 42 | 'step', 43 | 'where', 44 | 'info locals', 45 | 'set linetrace on', 46 | 'continue'] 47 | 48 | import pydb 49 | pydb.debugger(dbg_cmds) 50 | 51 | hanoi(n, "a", "b", "c") 52 | -------------------------------------------------------------------------------- /Doc/Makefile.deps: -------------------------------------------------------------------------------- 1 | # -*- Makefile -*- 2 | # LaTeX source dependencies. 3 | 4 | COMMONSTYLES= $(PYTHON_DOC)/texinputs/python.sty \ 5 | $(PYTHON_DOC)/texinputs/pypaper.sty 6 | 7 | INDEXSTYLES=$(PYTHON_DOC)/texinputs/python.ist 8 | 9 | COMMONTEX=$(PTYHON_DOC)/commontex/copyright.tex \ 10 | $(PTYHON_DOC)/commontex/license.tex \ 11 | $(PTYHON_DOC)/commontex/patchlevel.tex \ 12 | $(PTYHON_DOC)/commontex/boilerplate.tex 13 | 14 | MANSTYLES= $(PYTHON_DOC)/texinputs/fncychap.sty \ 15 | $(PYTHON_DOC)/texinputs/manual.cls \ 16 | $(COMMONSTYLES) 17 | 18 | HOWTOSTYLES= 19 | APIFILES= 20 | 21 | # These files are generated from those listed above, and are used to 22 | # generate the typeset versions of the manuals. The list is defined 23 | # here to make it easier to ensure parallelism. 24 | ANNOAPIFILES= $(MANSTYLES) $(INDEXSTYLES) $(COMMONTEX) \ 25 | $(PTYHON_DOC)/commontex/reportingbugs.tex 26 | 27 | DOCFILES= $(HOWTOSTYLES) \ 28 | $(PTYHON_DOC)/commontex/boilerplate.tex \ 29 | $(PYTHON_DOC)/texinputs/ltxmarkup.sty \ 30 | doc/doc.tex 31 | 32 | EXTFILES= 33 | 34 | TUTFILES= 35 | 36 | # LaTeX source files for the Python Reference Manual 37 | REFFILES= 38 | 39 | # LaTeX source files for the Python Library Reference 40 | LIBFILES= lib/libpydb.tex 41 | 42 | 43 | # LaTeX source files for Macintosh Library Modules. 44 | MACFILES= 45 | 46 | INSTFILES = 47 | 48 | DISTFILES = 49 | -------------------------------------------------------------------------------- /test/data/run.right: -------------------------------------------------------------------------------- 1 | +info program 2 | Program stopped. 3 | It stopped after stepping, next'ing or initial start. 4 | +continue 5 | The program finished and will be restarted 6 | +###################################### 7 | +### Now restart with a breakpoint 8 | +###################################### 9 | +break hanoi 10 | Breakpoint 1 set in file hanoi.py, line 5. 11 | +show args 12 | Argument list to give program being debugged when it is started is 13 | "". 14 | +run 15 | Restarting hanoi.py with arguments: 16 | 17 | +continue 18 | +info args 19 | n= 3 20 | a= a 21 | b= b 22 | c= c 23 | +info program 24 | Program stopped. 25 | It stopped at breakpoint 1. 26 | +where 2 27 | -> 0 hanoi(n=3, a='a', b='b', c='c') called from file 'hanoi.py' at line 6 28 | ## 1 in file 'hanoi.py' at line 31 29 | +###################################### 30 | +### We should be at that breakpoint 31 | +### delete it and run again 32 | +### this time changing a parameter 33 | +###################################### 34 | +info break 35 | Num Type Disp Enb Where 36 | 1 breakpoint keep y at hanoi.py:5 37 | breakpoint already hit 2 times 38 | +delete 1 39 | Deleted breakpoint 1 40 | +run 1 41 | Restarting hanoi.py with arguments: 42 | 1 43 | +continue 44 | The program finished and will be restarted 45 | +show args 46 | Argument list to give program being debugged when it is started is 47 | "1". 48 | +info args 49 | +#### 50 | +quit 51 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | Note invalid combinations "stop pass", "noprint stack" is buggy. 2 | break line thread-name buggy 3 | investigate quit exception passing through in ipython. 4 | Add to ddd recent features, e.g. assembly, threads, display expressions 5 | 6 | Write Bdb documentation. 7 | 8 | Remote debugging 9 | add for threading: 10 | step [count] Thread-name 11 | next [count] Thread-name 12 | 13 | Mock objects for thread id's/names. Then more tests on thread code. 14 | 15 | reinstate "thread" command? 16 | 17 | Add watchpoints. (Mentioned in pdbimprovements) 18 | 19 | The main pydb.py file size has been reduced but it is still bit 20 | large. If we can break out into more files that might be nice. 21 | 22 | Some more regression tests should to be written. They've been 23 | invaluable so far and maintain quality. Especially for the large 24 | changes. 25 | 26 | Redo post_mortem, pm, set_step to funnel through parse_options rather 27 | than taking the optional cmdfile and opts parameters. 28 | 29 | gdb return command relies on the existence of a return statement in 30 | the code. 31 | 32 | Add online debugger concept help and in LaTeX? 33 | 34 | Add in patches of various Bdb's such as the one in Eric. 35 | 36 | Better history completion. Better history completion interaction inside 37 | ipython and with or without Emacs. 38 | 39 | Eric or Idle integration. 40 | 41 | Use inspect module get_stack rather than bdb's? 42 | 43 | $Id: TODO,v 1.21 2007/01/13 12:14:29 rockyb Exp $ 44 | -------------------------------------------------------------------------------- /Doc/tools/patchlevel.h: -------------------------------------------------------------------------------- 1 | 2 | /* Newfangled version identification scheme. 3 | 4 | This scheme was added in Python 1.5.2b2; before that time, only PATCHLEVEL 5 | was available. To test for presence of the scheme, test for 6 | defined(PY_MAJOR_VERSION). 7 | 8 | When the major or minor version changes, the VERSION variable in 9 | configure.in must also be changed. 10 | 11 | There is also (independent) API version information in modsupport.h. 12 | */ 13 | 14 | /* Values for PY_RELEASE_LEVEL */ 15 | #define PY_RELEASE_LEVEL_ALPHA 0xA 16 | #define PY_RELEASE_LEVEL_BETA 0xB 17 | #define PY_RELEASE_LEVEL_GAMMA 0xC /* For release candidates */ 18 | #define PY_RELEASE_LEVEL_FINAL 0xF /* Serial should be 0 here */ 19 | /* Higher for patch releases */ 20 | 21 | /* Version parsed out into numeric values */ 22 | #define PY_MAJOR_VERSION 2 23 | #define PY_MINOR_VERSION 5 24 | #define PY_MICRO_VERSION 0 25 | #define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_ALPHA 26 | #define PY_RELEASE_SERIAL 0 27 | 28 | /* Version as a string */ 29 | #define PY_VERSION "pydb" 30 | 31 | /* Subversion Revision number of this file (not of the repository) */ 32 | #define PY_PATCHLEVEL_REVISION "$Revision: 1.3 $" 33 | 34 | /* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2. 35 | Use this for numeric comparisons, e.g. #if PY_VERSION_HEX >= ... */ 36 | #define PY_VERSION_HEX ((PY_MAJOR_VERSION << 24) | \ 37 | (PY_MINOR_VERSION << 16) | \ 38 | (PY_MICRO_VERSION << 8) | \ 39 | (PY_RELEASE_LEVEL << 4) | \ 40 | (PY_RELEASE_SERIAL << 0)) 41 | -------------------------------------------------------------------------------- /test/data/help.right: -------------------------------------------------------------------------------- 1 | usage: pydb.py [debugger-options] [python-script [script-options...]] 2 | 3 | Runs the extended python debugger 4 | 5 | options: 6 | --version show program's version number and exit 7 | -h, --help show this help message and exit 8 | -X, --trace Show lines before executing them. This option also 9 | sets --batch 10 | -F, --fntrace Show functions before executing them. This option also 11 | sets --batch 12 | --batch Don't run interactive commands shell on stops. 13 | --basename Filenames strip off basename, (e.g. for regression 14 | tests) 15 | -x FILE, --command=FILE 16 | Execute commands from FILE. 17 | --cd=DIR Change current directory to DIR. 18 | --error=FILE Write debugger's error output (stderr) to FILE 19 | -e EXECUTE, --exec=EXECUTE 20 | list of debugger commands to execute. Separate the 21 | commands with ;; 22 | -n, --nx Don't execute commands found in any initialization 23 | files 24 | -o FILE, --output=FILE 25 | Write debugger's output (stdout) to FILE 26 | --sigcheck Set to watch for signal handler changes 27 | -t TARGET, --target=TARGET 28 | Specify a target to connect to. Arguments should be of 29 | form, 'protocol address'. 30 | -T, --threading Start off with threading debug support 31 | --annotate=ANNOTATE Use annotations (to work inside emacs) 32 | -------------------------------------------------------------------------------- /Doc/lib/lib-ds.tex: -------------------------------------------------------------------------------- 1 | \documentclass{manual} 2 | 3 | % NOTE: this file controls which chapters/sections of the library 4 | % manual are actually printed. It is easy to customize your manual 5 | % by commenting out sections that you're not interested in. 6 | 7 | \title{Python Library Reference for the Extended Python Debugger} 8 | 9 | \input{boilerplate} 10 | 11 | \makeindex % tell \index to actually write the 12 | % .idx file 13 | \makemodindex % ... and the module index as well. 14 | 15 | 16 | \begin{document} 17 | 18 | \maketitle 19 | 20 | \ifhtml 21 | \chapter*{Front Matter\label{front}} 22 | \fi 23 | 24 | \input{copyright} 25 | 26 | \begin{abstract} 27 | 28 | \noindent 29 | Python is an extensible, interpreted, object-oriented programming 30 | language. It supports a wide range of applications, from simple text 31 | processing scripts to interactive Web browsers. 32 | 33 | We describe here only the Extended Python Debugger. The rest of the The 34 | \ulink{\module{Python Reference Manual}} 35 | {http://docs.python.org/lib/lib.html} should be consulted for other 36 | standard Python modules including the original \ulink{\module{Python 37 | Debugger}}{http://docs.python.org/lib/module-pdb.html} (\tt{pdb.py}). 38 | 39 | \end{abstract} 40 | 41 | \tableofcontents 42 | 43 | % Chapter title: 44 | 45 | % ============= 46 | % DEVELOPMENT TOOLS 47 | % ============= 48 | % % Software development support 49 | 50 | \renewcommand{\baselinestretch}{3.0}\normalsize 51 | \input{libpydb} % The Python Debugger 52 | 53 | 54 | \end{document} 55 | -------------------------------------------------------------------------------- /Doc/lib/lib.tex: -------------------------------------------------------------------------------- 1 | \documentclass{manual} 2 | 3 | % NOTE: this file controls which chapters/sections of the library 4 | % manual are actually printed. It is easy to customize your manual 5 | % by commenting out sections that you're not interested in. 6 | 7 | \title{Python Library Reference for the Extended Python Debugger} 8 | 9 | \input{boilerplate} 10 | 11 | \makeindex % tell \index to actually write the 12 | % .idx file 13 | \makemodindex % ... and the module index as well. 14 | 15 | 16 | \begin{document} 17 | 18 | \maketitle 19 | 20 | \ifhtml 21 | \chapter*{Front Matter\label{front}} 22 | \fi 23 | 24 | \input{copyright} 25 | 26 | \begin{abstract} 27 | 28 | \noindent 29 | Python is an extensible, interpreted, object-oriented programming 30 | language. It supports a wide range of applications, from simple text 31 | processing scripts to interactive Web browsers. 32 | 33 | We describe here only the Extended Python Debugger. The rest of the The 34 | \ulink{\module{Python Reference Manual}} 35 | {http://docs.python.org/lib/lib.html} should be consulted for other 36 | standard Python modules including the original \ulink{\module{Python 37 | Debugger}}{http://docs.python.org/lib/module-pdb.html} (\tt{pdb.py}). 38 | 39 | \end{abstract} 40 | 41 | \tableofcontents 42 | 43 | % Chapter title: 44 | 45 | % ============= 46 | % DEVELOPMENT TOOLS 47 | % ============= 48 | % % Software development support 49 | 50 | \input{libpydb} % The Python Debugger 51 | 52 | %begin{latexonly} 53 | \renewcommand{\indexname}{Index} 54 | %end{latexonly} 55 | \input{lib.ind} % Index 56 | 57 | \end{document} 58 | -------------------------------------------------------------------------------- /test/thread/prof2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | #Let us profile code which uses threads 4 | import thread 5 | import time 6 | from threading import Thread 7 | 8 | class MyThread(Thread): 9 | 10 | def __init__(self,bignum): 11 | 12 | Thread.__init__(self) 13 | self.bignum=bignum 14 | 15 | def run(self): 16 | 17 | for l in range(5): 18 | for k in range(self.bignum): 19 | res=0 20 | for i in range(self.bignum): 21 | res+=1 22 | 23 | 24 | def myadd_nothread(bignum): 25 | 26 | for l in range(5): 27 | for k in range(bignum): 28 | res=0 29 | for i in range(bignum): 30 | res+=1 31 | 32 | for l in range(5): 33 | for k in range(bignum): 34 | res=0 35 | for i in range(bignum): 36 | res+=1 37 | 38 | def thread_test(bignum): 39 | #We create 2 Thread objects for the 2 threads. 40 | thr1=MyThread(bignum) 41 | thr2=MyThread(bignum) 42 | 43 | thr1.start() 44 | thr2.start() 45 | 46 | thr1.join() 47 | thr2.join() 48 | 49 | 50 | def test(): 51 | 52 | bignum=20 53 | 54 | #Let us test the threading part 55 | 56 | import sys 57 | sys.setcheckinterval(1000) 58 | 59 | 60 | starttime=time.time() 61 | thread_test(bignum) 62 | stoptime=time.time() 63 | 64 | print "Running 2 threads took %.3f seconds" % (stoptime-starttime) 65 | 66 | #Now run without Threads. 67 | starttime=time.time() 68 | myadd_nothread(bignum) 69 | stoptime=time.time() 70 | 71 | print "Running Without Threads took %.3f seconds" % (stoptime-starttime) 72 | 73 | 74 | if __name__=="__main__": 75 | 76 | test() 77 | -------------------------------------------------------------------------------- /test/brkpt2.cmd: -------------------------------------------------------------------------------- 1 | # 2 | # Test of breakpoint handling 3 | # $Id: brkpt2.cmd,v 1.10 2008/11/24 21:24:28 rockyb Exp $ 4 | # 5 | set basename on 6 | set trace-commands on 7 | ############################################################### 8 | ### Clear nonexist break; 9 | ############################################################### 10 | clear 11 | ############################################################### 12 | ### Multiple breakpoints on a line and clearing all 13 | ############################################################### 14 | break 28 15 | break gcd.py:28 16 | info break 17 | clear 28 18 | ############################################################### 19 | ### Clear by current line number 20 | ############################################################### 21 | break 28 22 | continue 23 | clear 24 | info break 25 | ############################################################### 26 | ### Test Delete: invalid/valid number. 27 | ############################################################### 28 | delete 1 29 | break 11 30 | info break 31 | delete 4 32 | tbreak 31 33 | continue 34 | info break 35 | ############################################################### 36 | ### Test Continue with a line number 37 | ############################################################### 38 | c 35 39 | info break 40 | where 2 41 | ############################################################### 42 | ### Test frame command 43 | ############################################################### 44 | frame 45 | frame abs(-1*2) 46 | frame -3 47 | frame -2 48 | frame 0 49 | ############################################################### 50 | ### Test ignore 51 | ############################################################### 52 | ignore 0 1 53 | ignore 4 -1 54 | ## FIXME: need a real ignore test, not just invalid cases 55 | quit 56 | -------------------------------------------------------------------------------- /test/unit/checkline.py.in: -------------------------------------------------------------------------------- 1 | #!@PYTHON@ -t 2 | # -*- Python -*- 3 | # $Id: checkline.py.in,v 1.2 2008/12/21 10:54:23 rockyb Exp $ 4 | "Unit test for checkline" 5 | import inspect, os, sys, unittest 6 | 7 | top_builddir = "@top_builddir@" 8 | if top_builddir[-1] != os.path.sep: 9 | top_builddir += os.path.sep 10 | sys.path.insert(0, os.path.join(top_builddir, 'pydb')) 11 | top_srcdir = "@top_srcdir@" 12 | if top_srcdir[-1] != os.path.sep: 13 | top_srcdir += os.path.sep 14 | sys.path.insert(0, os.path.join(top_srcdir, 'pydb')) 15 | 16 | import fns 17 | 18 | class CheckLine(unittest.TestCase): 19 | def errmsg(self, msg): 20 | self.errors.append(msg) 21 | return 22 | 23 | def test_basic(self): 24 | global top_srcdir 25 | self.curframe = inspect.currentframe() 26 | check_script = os.path.join(top_srcdir, 'test', 'data', 27 | 'checkline.py') 28 | for t in ( ( 1, True), 29 | ( 2, False), 30 | ( 3, False), # FIXME add 4 31 | ( 5, False), 32 | ( 6, True), 33 | ( 7, False), 34 | ( 8, False), 35 | ( 9, True), 36 | (10, False), 37 | ): 38 | self.errors=[] 39 | result = fns.checkline(self, check_script, t[0]) 40 | if t[1]: 41 | self.assertEqual(t[0], result, "Should have worked") 42 | self.assertEqual(0, len(self.errors), "With no errors") 43 | else: 44 | self.assertNotEqual(t[0], result, "Should not have worked") 45 | self.assertEqual(1, len(self.errors), "and given an error") 46 | return 47 | 48 | if __name__ == '__main__': 49 | unittest.main() 50 | -------------------------------------------------------------------------------- /pydb/server.py: -------------------------------------------------------------------------------- 1 | """$Id: server.py,v 1.2 2008/05/29 02:53:01 rockyb Exp $ 2 | Debugger Server code 3 | """ 4 | from gdb import Gdb 5 | import sys 6 | import connection 7 | 8 | old_handler = None 9 | server_addr = None 10 | 11 | def setup_server(sig=None, protocol=None, addr=None): 12 | """Gather the parameters to set up a debugging server. 13 | This routine should be imported and called near the top of the 14 | program file. 15 | 16 | When signal "sig" is received, which by default is SIGUSR1, 17 | invoke_server() is called and passed the parameters used to setup 18 | this server. 19 | 20 | Protocol "protocol" is used for communication. 21 | 22 | If "addr" is specified clients can connect to this server 23 | at that address. 24 | """ 25 | import signal 26 | if not sig: 27 | sig = signal.SIGUSR1 28 | 29 | global old_handler 30 | old_handler = signal.signal(sig, invoke_server) 31 | 32 | if protocol != None: 33 | proto = protocol 34 | else: 35 | proto = 'connection.ConnectionFIFO' 36 | 37 | global server_addr 38 | if addr != None: 39 | server_addr = proto + " " + addr 40 | else: 41 | tmp = gettmpdir() + os.path.pathsep + str(os.getpid()) + "pydb" 42 | server_addr = proto + " " + tmp 43 | 44 | def invoke_server(signum, frame): 45 | """This function sets up a signal handler, which when it 46 | traps a signal, starts a debugging server suitable for other 47 | debugging clients to connect to. 48 | """ 49 | p = Gdb() 50 | p._sys_argv = list(sys.argv) 51 | 52 | from remote import RemoteWrapperServer 53 | p = RemoteWrapperServer(p) 54 | p.do_pydbserver(server_addr) 55 | 56 | p.set_trace(frame) 57 | 58 | import signal 59 | signal.signal(signum, old_handler) 60 | -------------------------------------------------------------------------------- /Doc/tools/mkinfo: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # -*- Ksh -*- 3 | 4 | # Script to drive the HTML-info conversion process. 5 | # Pass in upto three parameters: 6 | # - the name of the main tex file 7 | # - the name of the output file in texi format (optional) 8 | # - the name of the output file in info format (optional) 9 | # 10 | # Written by Fred L. Drake, Jr.
This document was generated using the 4 | LaTeX2HTML translator. 5 |
6 | 7 |9 | LaTeX2HTML is Copyright © 10 | 1993, 1994, 1995, 1996, 1997, Nikos 12 | Drakos, Computer Based Learning Unit, University of 13 | Leeds, and Copyright © 1997, 1998, Ross 15 | Moore, Mathematics Department, Macquarie University, 16 | Sydney. 17 |
18 | 19 |The application of 21 | LaTeX2HTML to the Python 22 | documentation has been heavily tailored by Fred L. Drake, 23 | Jr. Original navigation icons were contributed by Christopher 24 | Petrilli. 25 |
26 | 27 |General comments and questions regarding this document should 32 | be sent by email to bashdb-pydb@lists.sourceforge.net. 34 | 35 |
If you find specific errors or have patches, requests, please 36 | report this (using the appropriate tab "Patches" or "Bugs" on Python 38 | Extended Debugger Bug Tracker at SourceForge. 40 |
41 | 42 |43 | If you are able to provide suggested text, either to replace 44 | existing incorrect or unclear material, or additional text to 45 | supplement what's already available, we'd appreciate the 46 | contribution. There's no need to worry about text markup; our 47 | documentation team will gladly take care of that. 48 |
49 | 50 |For any of these channels, please be sure not to send HTML email. 51 | Thanks. 52 |
53 | -------------------------------------------------------------------------------- /htdocs/download.html: -------------------------------------------------------------------------------- 1 | 2 |9 |
Although we don't provide pre-compiled binary packages (just source 15 | code), others do; and we are most grateful for that. 16 | 17 |
59 | 60 |
61 | $Id: download.html,v 1.4 2006/10/06 09:17:24 rockyb Exp $
62 |
63 |
--------------------------------------------------------------------------------
/htdocs/jc.css:
--------------------------------------------------------------------------------
1 | /* Style settings courtesy of John Chidiac. */
2 | body
3 | {
4 | margin: 0;
5 | color: #676767;
6 | background: white;
7 | font-family: Arial, Helvetica, sans-serif;
8 | background-color: #e2e2e2;
9 | }
10 |
11 | a:link
12 | {
13 | color: #1F00FF;
14 | }
15 |
16 | a:visited
17 | {
18 | color: #9900DD;
19 | }
20 |
21 | #container
22 | {
23 | width: 65em;
24 | padding: 4em;
25 | margin: 0 auto;
26 | background-color: #fff;
27 | }
28 |
29 | #other_projects
30 | {
31 | float: right;
32 | padding: 1em;
33 | background-color: #e2edbe;
34 | width: 14em;
35 | border-left: 2em solid #fff;
36 | }
37 |
38 | h1
39 | {
40 | padding: 48px;
41 | margin: -48px -48px 0 -48px;
42 | background-color: #c2d87e;
43 | }
44 |
45 | h1, h2, h3
46 | {
47 | color: #000;
48 | }
49 |
50 | h2
51 | {
52 | margin: 32px 0 .6em 0;
53 | padding-bottom: .2em;
54 | border-bottom: 1px solid #ddd;
55 | }
56 |
57 | ul
58 | {
59 | list-style: none;
60 | margin: 0;
61 | padding: 0;
62 | }
63 |
64 | ul a
65 | {
66 | font-size: 1.2em;
67 | width: 30em;
68 | }
69 |
70 | li
71 | {
72 | font-size: .9em;
73 | margin-bottom: 6px;
74 | }
75 |
76 | #other_projects p
77 | {
78 | margin-top: 0;
79 | }
80 |
81 | .thumb
82 | {
83 | margin-right: 10px;
84 | text-align: center;
85 | float: left;
86 | width: 150px;
87 | overflow: hidden;
88 | height: 170px;
89 | }
90 |
91 | .thumb a
92 | {
93 | text-decoration: none;
94 | }
95 |
96 | tt
97 | {
98 | font-size: 1.2em;
99 | font-weight: bold;
100 | }
101 |
102 | dt
103 | {
104 | font-weight: bold;
105 | margin-top: 1.2em;
106 | }
107 |
108 | dd
109 | {
110 | margin-top: -18px;
111 | margin-left: 9em;
112 | }
113 |
114 | h4
115 | {
116 | margin-top: -45px;
117 | margin-bottom: 64px;
118 | color: #fff;
119 | }
120 |
121 | p
122 | {
123 | line-height: 1.3;
124 | }
125 |
126 | .credit
127 | {
128 | border-top: 1px solid #e2e2e2;
129 | padding-top: 1em;
130 | margin-top: 3em;
131 | font-style: italic;
132 | font-size: .89em;
133 | }
134 |
--------------------------------------------------------------------------------
/test/test-fifo-connect.py.in:
--------------------------------------------------------------------------------
1 | #!@PYTHON@ -t
2 | # $Id: test-fifo-connect.py.in,v 1.1 2007/11/01 09:20:31 rockyb Exp $ -*- Python -*-
3 |
4 | # This unit test doesn't use any of the debugger code. It is meant solely
5 | # to test the connection classes.
6 |
7 | import os, sys, thread, time, unittest
8 |
9 | top_builddir = "@top_builddir@"
10 | if top_builddir[-1] != os.path.sep:
11 | top_builddir += os.path.sep
12 | sys.path.insert(0, os.path.join(top_builddir, 'pydb'))
13 | top_srcdir = "@top_srcdir@"
14 | if top_srcdir[-1] != os.path.sep:
15 | top_srcdir += os.path.sep
16 | sys.path.insert(0, os.path.join(top_srcdir, 'pydb'))
17 |
18 | import connection
19 |
20 | class TestFIFOConnections(unittest.TestCase):
21 |
22 | def test_client_server(self):
23 | """Test that the we can read and write between a FIFO client and
24 | server"""
25 | fname='fifotest'
26 | server = connection.ConnectionFIFO(is_server=True)
27 | client = connection.ConnectionFIFO(is_server=False)
28 | thread.start_new_thread(server.connect, (fname,))
29 | for i in range(10):
30 | if not hasattr(server, 'outp') or server.outp is None:
31 | time.sleep(0.05)
32 | client.connect(fname)
33 | line = 'this is a test\n'
34 | client.write(line)
35 |
36 | for i in range(10):
37 | if not os.path.exists('fifotest.out'):
38 | time.sleep(0.05)
39 | else:
40 | break
41 |
42 | self.assertEqual(True, os.path.exists('fifotest.out'))
43 | for i in range(10):
44 | if not hasattr(server, 'inp') or server.inp is None:
45 | time.sleep(0.05)
46 | l2 = server.readline()
47 | self.assertEqual(l2, line, "client to server")
48 | line = 'Another test\n'
49 | server.write(line)
50 | l2 = client.readline()
51 | self.assertEqual(l2, line, "server to client")
52 | client.disconnect()
53 | server.disconnect()
54 | # And again just to see what will happen
55 | server.disconnect()
56 |
57 | if __name__ == '__main__':
58 | unittest.main()
59 |
--------------------------------------------------------------------------------
/Doc/tools/node2label.pl:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env perl
2 |
3 | # On Cygwin, we actually have to generate a temporary file when doing
4 | # the inplace edit, or we'll get permission errors. Not sure who's
5 | # bug this is, except that it isn't ours. To deal with this, we
6 | # generate backups during the edit phase and remove them at the end.
7 | #
8 | use English;
9 | $INPLACE_EDIT = '.bak';
10 |
11 | # read the labels, then reverse the mappings
12 | require "labels.pl";
13 |
14 | %nodes = ();
15 | my $key;
16 | # sort so that we get a consistent assignment for nodes with multiple labels
17 | foreach $label (sort keys %external_labels) {
18 | #
19 | # If the label can't be used as a filename on non-Unix platforms,
20 | # skip it. Such labels may be used internally within the documentation,
21 | # but will never be used for filename generation.
22 | #
23 | if ($label =~ /^([-.a-zA-Z0-9]+)$/) {
24 | $key = $external_labels{$label};
25 | $key =~ s|^/||;
26 | $nodes{$key} = $label;
27 | }
28 | }
29 |
30 | # This adds the "internal" labels added for indexing. These labels will not
31 | # be used for file names.
32 | require "intlabels.pl";
33 | foreach $label (keys %internal_labels) {
34 | $key = $internal_labels{$label};
35 | $key =~ s|^/||;
36 | if (defined($nodes{$key})) {
37 | $nodes{$label} = $nodes{$key};
38 | }
39 | }
40 |
41 | # collect labels that have been used
42 | %newnames = ();
43 |
44 | while (<>) {
45 | # don't want to do one s/// per line per node
46 | # so look for lines with hrefs, then do s/// on nodes present
47 | if (/(HREF|href)=[\"\']node\d+\.html[\#\"\']/) {
48 | @parts = split(/(HREF|href)\=[\"\']/);
49 | shift @parts;
50 | for $node (@parts) {
51 | $node =~ s/[\#\"\'].*$//g;
52 | chomp($node);
53 | if (defined($nodes{$node})) {
54 | $label = $nodes{$node};
55 | if (s/(HREF|href)=([\"\'])$node([\#\"\'])/href=$2$label.html$3/g) {
56 | s/(HREF|href)=([\"\'])$label.html/href=$2$label.html/g;
57 | $newnames{$node} = "$label.html";
58 | }
59 | }
60 | }
61 | }
62 | print;
63 | }
64 |
65 | foreach $oldname (keys %newnames) {
66 | rename($oldname, $newnames{$oldname});
67 | }
68 |
69 | foreach $filename (glob('*.bak')) {
70 | unlink($filename);
71 | }
72 |
--------------------------------------------------------------------------------
/test/test-complete.py.in:
--------------------------------------------------------------------------------
1 | #!@PYTHON@ -t
2 | # $Id: test-complete.py.in,v 1.4 2009/02/09 09:28:39 rockyb Exp $ -*- Python -*-
3 |
4 | import os, sys, unittest
5 |
6 | try:
7 | import readline
8 | except ImportError:
9 | print "Completion test skipped - no readline"
10 | sys.exit(0)
11 |
12 | top_builddir = "@top_builddir@"
13 | if top_builddir[-1] != os.path.sep:
14 | top_builddir += os.path.sep
15 | sys.path.insert(0, os.path.join(top_builddir, 'pydb'))
16 | top_srcdir = "@top_srcdir@"
17 | if top_srcdir[-1] != os.path.sep:
18 | top_srcdir += os.path.sep
19 | sys.path.insert(0, os.path.join(top_srcdir, 'pydb'))
20 |
21 | from complete import list_completions, all_completions
22 |
23 | class TestComplete(unittest.TestCase):
24 |
25 | def test_list_completions(self):
26 | c=[]; seen={}
27 | l=["a", "an", "another", "also", "boy"]
28 | self.assertEqual(list_completions(l, "a", seen, c),
29 | ['a', 'an', 'another', 'also'])
30 | self.assertEqual(list_completions(l, "b", seen, c),
31 | ['a', 'an', 'another', 'also', 'boy'])
32 | c=[]; seen={}
33 | self.assertEqual(list_completions(l, "a", seen, c, "foo "),
34 | ['foo a', 'foo an', 'foo another', 'foo also'])
35 | c=[]; seen={}
36 | self.assertEqual(list_completions(l, "an", seen, c), ['an', 'another'])
37 | c=[]; seen={}
38 | self.assertEqual(list_completions(l, "b", seen, c), ['boy'])
39 | c=[]; seen={}
40 | self.assertEqual(list_completions(l, "be", seen, c), [])
41 | return
42 |
43 | def test_all_completions(self):
44 | import pydb
45 | dbg = pydb.Pdb()
46 | dbg.curframe = None
47 | self.assertEqual( all_completions(dbg, "s"),
48 | ['s', 'save', 'set', 'shell', 'show', 'signal', 'skip',
49 | 'source', 'step'])
50 | self.assertEqual( all_completions(dbg, "set l"),
51 | ['set linetrace', 'set listsize', 'set logging'])
52 | self.assertEqual( all_completions(dbg, "set l", False),
53 | ['linetrace', 'listsize', 'logging'])
54 | return
55 |
56 | if __name__ == '__main__':
57 | unittest.main()
58 |
--------------------------------------------------------------------------------
/test/unit/sighandler.py.in:
--------------------------------------------------------------------------------
1 | #!@PYTHON@ -t
2 | 'Unit test for pydb.sighandler'
3 | import inspect, os, signal, sys, unittest
4 |
5 | top_builddir = "@top_builddir@"
6 | if top_builddir[-1] != os.path.sep:
7 | top_builddir += os.path.sep
8 | sys.path.insert(0, os.path.join(top_builddir, 'pydb'))
9 | top_srcdir = "@top_srcdir@"
10 | if top_srcdir[-1] != os.path.sep:
11 | top_srcdir += os.path.sep
12 | sys.path.insert(0, os.path.join(top_srcdir, 'pydb'))
13 |
14 | from sighandler import canonic_signame, lookup_signame, lookup_signum, YN
15 |
16 | class TestSigHandler(unittest.TestCase):
17 |
18 | def test_YN(self):
19 | for expect, b in (('Yes', True), ('No', False)):
20 | self.assertEqual(expect, YN(b))
21 | pass
22 | return
23 |
24 | def test_canonic_signame(self):
25 | for expect, name_num in (('SIGTERM', '15'),
26 | ('SIGTERM', '-15'),
27 | ('SIGTERM', 'term'),
28 | ('SIGTERM', 'sigterm'),
29 | ('SIGTERM', 'TERM'),
30 | (None, '300'),
31 | (False, 'bogus')):
32 | self.assertEqual(expect, canonic_signame(name_num),
33 | 'name_num: %s' % name_num)
34 | pass
35 | pass
36 |
37 | def test_lookup_signame(self):
38 | for expect, num in (('SIGTERM', 15), ('SIGTERM', -15),
39 | (None, 300)):
40 | self.assertEqual(expect, lookup_signame(num))
41 | pass
42 | return
43 |
44 | def test_lookup_signum(self):
45 | for expect, name in ((15, 'SIGTERM'), (15, 'TERM'),
46 | (15, 'term'), (None, 'nothere')):
47 | self.assertEqual(expect, lookup_signum(name))
48 | pass
49 | return
50 |
51 | def test_lookup_signame_signum(self):
52 | for signum in range(signal.NSIG):
53 | signame = lookup_signame(signum)
54 | if signame is not None:
55 | self.assertEqual(signum, lookup_signum(signame))
56 | # Try without the SIG prefix
57 | self.assertEqual(signum, lookup_signum(signame[3:]))
58 | pass
59 | pass
60 | return
61 |
62 | pass
63 |
64 | if __name__ == '__main__':
65 | unittest.main()
66 |
--------------------------------------------------------------------------------
/test/test-disassem.py.in:
--------------------------------------------------------------------------------
1 | #!@PYTHON@ -t
2 | # -*- Python -*-
3 | # $Id: test-disassem.py.in,v 1.2 2009/03/31 19:52:59 rockyb Exp $
4 | "Unit test for Extended Python debugger's signal handling commands "
5 | import inspect, os, time, sys, unittest
6 |
7 | top_builddir = "@top_builddir@"
8 | if top_builddir[-1] != os.path.sep:
9 | top_builddir += os.path.sep
10 | sys.path.insert(0, os.path.join(top_builddir, 'pydb'))
11 | top_srcdir = "@top_srcdir@"
12 | if top_srcdir[-1] != os.path.sep:
13 | top_srcdir += os.path.sep
14 | sys.path.insert(0, os.path.join(top_srcdir, 'pydb'))
15 |
16 | import pydb
17 |
18 | class PdbTest(pydb.Pdb):
19 | def __init__(self):
20 | pydb.Pdb.__init__(self)
21 | self.errLines = []
22 | self.msgLines = []
23 | self.msg_last_nocr = False
24 | self.stack = self.curframe = self.botframe = None
25 | return
26 |
27 | def errmsg(self, msg):
28 | self.errLines.append(msg)
29 | return
30 |
31 | def msg(self, msg):
32 | if self.msg_last_nocr:
33 | self.msgLines[-1] += msg
34 | else:
35 | self.msgLines.append(msg)
36 | self.msg_last_nocr = False
37 | return
38 |
39 | def msg_nocr(self, msg):
40 | if self.msg_last_nocr:
41 | self.msgLines[-1] += msg
42 | else:
43 | self.msgLines.append(msg)
44 | self.msg_last_nocr = True
45 | return
46 |
47 | def msgReset(self):
48 | self.msgLines = []
49 | return
50 |
51 | class PdbTests(unittest.TestCase):
52 |
53 | def test_disassemble(self):
54 | """Unit test dissassemble command"""
55 | import atexit
56 | deb = PdbTest()
57 | deb.curframe = inspect.currentframe()
58 | # deb.do_disassemble('atexit.register')
59 | # all_lines = len(deb.msgLines)
60 | # self.assertEqual(True, all_lines > 0)
61 | # deb.msgReset()
62 | deb.do_disassemble('+')
63 | all_lines = len(deb.msgLines)
64 | self.assertEqual(True, all_lines > 0)
65 | deb.msgReset()
66 | deb.do_disassemble('10')
67 | all_lines = len(deb.msgLines)
68 | self.assertEqual(True, all_lines > 0)
69 | deb.msgReset()
70 | deb.do_disassemble('1 100')
71 | all_lines = len(deb.msgLines)
72 | self.assertEqual(True, all_lines > 0)
73 | deb.msgReset()
74 | return
75 |
76 | if __name__ == "__main__":
77 | unittest.main()
78 |
79 |
--------------------------------------------------------------------------------
/test/test-save.py.in:
--------------------------------------------------------------------------------
1 | #!@PYTHON@ -t
2 | # $Id: test-save.py.in,v 1.3 2008/12/10 13:31:26 rockyb Exp $ -*- Python -*-
3 | """Unit test of the save command."""
4 | import difflib, os, time, sys, unittest
5 |
6 | top_builddir = "@top_builddir@"
7 | if top_builddir[-1] != os.path.sep:
8 | top_builddir += os.path.sep
9 | sys.path.insert(0, os.path.join(top_builddir, 'pydb'))
10 | top_srcdir = "@top_srcdir@"
11 | if top_srcdir[-1] != os.path.sep:
12 | top_srcdir += os.path.sep
13 | sys.path.insert(0, os.path.join(top_srcdir, 'pydb'))
14 |
15 | builddir = "@builddir@"
16 | if builddir[-1] != os.path.sep:
17 | builddir += os.path.sep
18 |
19 | srcdir = "@srcdir@"
20 | if srcdir[-1] != os.path.sep:
21 | srcdir += os.path.sep
22 |
23 | pydir = os.path.join(top_builddir, "pydb")
24 | pydb_short = "pydb.py"
25 | pydb_path = os.path.join(pydir, pydb_short)
26 |
27 | def run_debugger(testname, pydb_opts='', args=''):
28 | global srcdir, builddir, pydir
29 |
30 | rightfile = os.path.join(srcdir, 'data', "%s.right" % testname)
31 |
32 | os.environ['PYTHONPATH']=os.pathsep.join(sys.path)
33 | cmdfile = os.path.join(srcdir, "%s.cmd" % testname)
34 | outfile = "%s.out" % testname
35 | outfile_opt = '--output=%s ' % outfile
36 |
37 | # print "builddir: %s, cmdfile: %s, outfile: %s, rightfile: %s" % \
38 | # (builddir, cmdfile, outfile, rightfile)
39 |
40 | if os.path.exists(outfile): os.unlink(outfile)
41 |
42 | cmd = "%s --command %s %s %s %s %s.py" % \
43 | (pydb_path, cmdfile, outfile_opt, pydb_opts, args,
44 | '%sgcd' % srcdir)
45 |
46 | os.system(cmd)
47 | fromfile = rightfile
48 | fromdate = time.ctime(os.stat(fromfile).st_mtime)
49 | fromlines = open(fromfile, 'U').readlines()
50 | tofile = outfile
51 | todate = time.ctime(os.stat(tofile).st_mtime)
52 | tolines = open(tofile, 'U').readlines()
53 | diff = list(difflib.unified_diff(fromlines, tolines, fromfile,
54 | tofile, fromdate, todate))
55 | if len(diff) == 0:
56 | os.unlink(outfile)
57 | for line in diff:
58 | print line,
59 | return len(diff) == 0
60 |
61 | class PdbTests(unittest.TestCase):
62 |
63 | def test_save(self):
64 | """Test running bug running "save" command"""
65 | result=run_debugger(testname='save', pydb_opts='--basename')
66 | self.assertEqual(True, result, "pydb 'save' command comparision")
67 | return
68 |
69 | if __name__ == "__main__":
70 | unittest.main()
71 |
--------------------------------------------------------------------------------
/test/test-contbug.py.in:
--------------------------------------------------------------------------------
1 | #!@PYTHON@ -t
2 | # -*- Python -*-
3 | # $Id: test-contbug.py.in,v 1.3 2008/12/08 00:40:57 rockyb Exp $
4 | "Unit test for Extended Python debugger's runl and runv commands "
5 | import difflib, os, sys, unittest, signal, time
6 |
7 | top_builddir = "@top_builddir@"
8 | if top_builddir[-1] != os.path.sep:
9 | top_builddir += os.path.sep
10 | sys.path.insert(0, os.path.join(top_builddir, 'pydb'))
11 | top_srcdir = "@top_srcdir@"
12 | if top_srcdir[-1] != os.path.sep:
13 | top_srcdir += os.path.sep
14 | sys.path.insert(0, os.path.join(top_srcdir, 'pydb'))
15 |
16 | import pydb
17 |
18 | builddir = "@builddir@"
19 | if builddir[-1] != os.path.sep:
20 | builddir += os.path.sep
21 |
22 | srcdir = "@srcdir@"
23 | if srcdir[-1] != os.path.sep:
24 | srcdir += os.path.sep
25 |
26 | pydir = os.path.join(top_builddir, "pydb")
27 | pydb_short = "pydb.py"
28 | pydb_path = os.path.join(pydir, pydb_short)
29 |
30 | def diff_files(outfile, rightfile):
31 | fromfile = rightfile
32 | fromdate = time.ctime(os.stat(fromfile).st_mtime)
33 | fromlines = open(fromfile, 'U').readlines()
34 | tofile = outfile
35 | todate = time.ctime(os.stat(tofile).st_mtime)
36 | tolines = open(tofile, 'U').readlines()
37 |
38 | diff = list(difflib.unified_diff(fromlines, tolines, fromfile,
39 | tofile, fromdate, todate))
40 | if len(diff) == 0:
41 | os.unlink(outfile)
42 | for line in diff:
43 | print line,
44 | return len(diff) == 0
45 |
46 | class RunTests(unittest.TestCase):
47 |
48 | def test_continue_bug(self):
49 | """Test --exec and a bug whith 'c lineno' when given initially."""
50 | python_script = '%shanoi.py' % srcdir
51 |
52 | if sys.hexversion >= 0x02050000:
53 | rightfile = os.path.join(srcdir, 'data',
54 | "contbug-2.5.right")
55 | else:
56 | rightfile = os.path.join(srcdir, 'data',
57 | "contbug.right")
58 |
59 | outfile = 'contbug.out'
60 | if os.path.exists(outfile): os.unlink(outfile)
61 | args = ('--basename', '--nx', '--output', outfile,
62 | '--exec',
63 | "set linetrace off;; set trace-commands on;; c 12;; quit",
64 | python_script)
65 | pydb.runv(args)
66 | result = diff_files(outfile, rightfile)
67 | self.assertEqual(True, result, "continue bug (via runv)")
68 |
69 | if __name__ == '__main__':
70 | unittest.main()
71 |
--------------------------------------------------------------------------------
/test/test-skip.py.in:
--------------------------------------------------------------------------------
1 | #!@PYTHON@ -t
2 | # $Id: test-skip.py.in,v 1.1 2009/02/09 09:28:39 rockyb Exp $ -*- Python -*-
3 | "Unit test of the file command for Extended Python debugger "
4 | import difflib, os, time, sys, unittest
5 |
6 | top_builddir = "@top_builddir@"
7 | if top_builddir[-1] != os.path.sep:
8 | top_builddir += os.path.sep
9 | sys.path.insert(0, os.path.join(top_builddir, 'pydb'))
10 | top_srcdir = "@top_srcdir@"
11 | if top_srcdir[-1] != os.path.sep:
12 | top_srcdir += os.path.sep
13 | sys.path.insert(0, os.path.join(top_srcdir, 'pydb'))
14 |
15 | builddir = "@builddir@"
16 | if builddir[-1] != os.path.sep:
17 | builddir += os.path.sep
18 |
19 | srcdir = "@srcdir@"
20 | if srcdir[-1] != os.path.sep:
21 | srcdir += os.path.sep
22 |
23 | pydir = os.path.join(top_builddir, "pydb")
24 | pydb_short = "pydb.py"
25 | pydb_path = os.path.join(pydir, pydb_short)
26 |
27 | def run_debugger(testname, pythonfile, pydb_opts='', args='',
28 | outfile=None):
29 | global srcdir, builddir, pydir
30 |
31 | rightfile = os.path.join(srcdir, 'data', "%s.right" % testname)
32 |
33 | os.environ['PYTHONPATH']=os.pathsep.join(sys.path)
34 | cmdfile = os.path.join(srcdir, "%s.cmd" % testname)
35 | outfile = "%s.out" % testname
36 | outfile_opt = '--output=%s ' % outfile
37 |
38 | # print "builddir: %s, cmdfile: %s, outfile: %s, rightfile: %s" % \
39 | # (builddir, cmdfile, outfile, rightfile)
40 |
41 | if os.path.exists(outfile): os.unlink(outfile)
42 |
43 | cmd = "%s --command %s %s %s %s %s" % \
44 | (pydb_path, cmdfile, outfile_opt, pydb_opts, pythonfile, args)
45 |
46 | os.system(cmd)
47 | fromfile = rightfile
48 | fromdate = time.ctime(os.stat(fromfile).st_mtime)
49 | fromlines = open(fromfile, 'U').readlines()
50 | tofile = outfile
51 | todate = time.ctime(os.stat(tofile).st_mtime)
52 | tolines = open(tofile, 'U').readlines()
53 | diff = list(difflib.unified_diff(fromlines, tolines, fromfile,
54 | tofile, fromdate, todate))
55 | if len(diff) == 0:
56 | os.unlink(outfile)
57 | for line in diff:
58 | print line,
59 | return len(diff) == 0
60 |
61 | class PdbTests(unittest.TestCase):
62 |
63 | def test_trace(self):
64 | """Test stepping"""
65 | result=run_debugger(testname='skip', pydb_opts='--basename',
66 | pythonfile='%sgcd.py' % srcdir)
67 | self.assertEqual(True, result, "pydb 'skip' command comparision")
68 | return
69 |
70 | if __name__ == "__main__":
71 | unittest.main()
72 |
--------------------------------------------------------------------------------
/test/test-step.py.in:
--------------------------------------------------------------------------------
1 | #!@PYTHON@ -t
2 | # $Id: test-step.py.in,v 1.3 2008/12/10 13:31:26 rockyb Exp $ -*- Python -*-
3 | "Unit test of the file command for Extended Python debugger "
4 | import difflib, os, time, sys, unittest
5 |
6 | top_builddir = "@top_builddir@"
7 | if top_builddir[-1] != os.path.sep:
8 | top_builddir += os.path.sep
9 | sys.path.insert(0, os.path.join(top_builddir, 'pydb'))
10 | top_srcdir = "@top_srcdir@"
11 | if top_srcdir[-1] != os.path.sep:
12 | top_srcdir += os.path.sep
13 | sys.path.insert(0, os.path.join(top_srcdir, 'pydb'))
14 |
15 | builddir = "@builddir@"
16 | if builddir[-1] != os.path.sep:
17 | builddir += os.path.sep
18 |
19 | srcdir = "@srcdir@"
20 | if srcdir[-1] != os.path.sep:
21 | srcdir += os.path.sep
22 |
23 | pydir = os.path.join(top_builddir, "pydb")
24 | pydb_short = "pydb.py"
25 | pydb_path = os.path.join(pydir, pydb_short)
26 |
27 | def run_debugger(testname, pythonfile, pydb_opts='', args='',
28 | outfile=None):
29 | global srcdir, builddir, pydir
30 |
31 | rightfile = os.path.join(srcdir, 'data', "%s.right" % testname)
32 |
33 | os.environ['PYTHONPATH']=os.pathsep.join(sys.path)
34 | cmdfile = os.path.join(srcdir, "%s.cmd" % testname)
35 | outfile = "%s.out" % testname
36 | outfile_opt = '--output=%s ' % outfile
37 |
38 | # print "builddir: %s, cmdfile: %s, outfile: %s, rightfile: %s" % \
39 | # (builddir, cmdfile, outfile, rightfile)
40 |
41 | if os.path.exists(outfile): os.unlink(outfile)
42 |
43 | cmd = "%s --command %s %s %s %s %s" % \
44 | (pydb_path, cmdfile, outfile_opt, pydb_opts, pythonfile, args)
45 |
46 | os.system(cmd)
47 | fromfile = rightfile
48 | fromdate = time.ctime(os.stat(fromfile).st_mtime)
49 | fromlines = open(fromfile, 'U').readlines()
50 | tofile = outfile
51 | todate = time.ctime(os.stat(tofile).st_mtime)
52 | tolines = open(tofile, 'U').readlines()
53 | diff = list(difflib.unified_diff(fromlines, tolines, fromfile,
54 | tofile, fromdate, todate))
55 | if len(diff) == 0:
56 | os.unlink(outfile)
57 | for line in diff:
58 | print line,
59 | return len(diff) == 0
60 |
61 | class PdbTests(unittest.TestCase):
62 |
63 | def test_trace(self):
64 | """Test stepping"""
65 | result=run_debugger(testname='step', pydb_opts='--basename',
66 | pythonfile='%sgcd.py' % srcdir)
67 | self.assertEqual(True, result, "pydb 'step' command comparision")
68 | return
69 |
70 | if __name__ == "__main__":
71 | unittest.main()
72 |
--------------------------------------------------------------------------------
/test/test-linetrace.py.in:
--------------------------------------------------------------------------------
1 | #!@PYTHON@ -t
2 | # -*- Python -*-
3 | # $Id: test-linetrace.py.in,v 1.5 2008/12/08 00:40:57 rockyb Exp $
4 | "Unit test for Extended Python debugger's set linetrace "
5 | import difflib, os, sys, time, unittest
6 |
7 | top_builddir = "@top_builddir@"
8 | if top_builddir[-1] != os.path.sep:
9 | top_builddir += os.path.sep
10 | sys.path.insert(0, os.path.join(top_builddir, 'pydb'))
11 | top_srcdir = "@top_srcdir@"
12 | if top_srcdir[-1] != os.path.sep:
13 | top_srcdir += os.path.sep
14 | sys.path.insert(0, os.path.join(top_srcdir, 'pydb'))
15 |
16 | def run_python(testname, pythonfile, args='', outfile=None):
17 | srcdir = os.path.join(top_srcdir, 'test')
18 | pythonfile = os.path.join(".", pythonfile)
19 | outfile_opt = ''
20 | if outfile is None:
21 | outfile = "%s.out" % testname
22 |
23 | if sys.hexversion >= 0x02050000:
24 | rightfile = os.path.join(srcdir, 'data',
25 | "%s-2.5.right" % testname)
26 | elif sys.version_info[0:2] == (2, 4) and sys.version_info[3] == 'final':
27 | rightfile = os.path.join(srcdir, 'data',
28 | "%s-2.4-final.right" % testname)
29 | else:
30 | rightfile = os.path.join(srcdir, 'data',
31 | "%s.right" % testname)
32 |
33 | if os.path.exists(outfile): os.unlink(outfile)
34 |
35 | cmd = "(@PYTHON@ %s %s) >%s 2>&1" % (pythonfile, args, outfile)
36 | os.system(cmd)
37 |
38 | # Do diff on output
39 | fromfile = rightfile
40 | fromdate = time.ctime(os.stat(fromfile).st_mtime)
41 | fromlines = open(fromfile, 'U').readlines()[1:-1]
42 | tofile = outfile
43 | todate = time.ctime(os.stat(tofile).st_mtime)
44 | tolines = open(tofile, 'U').readlines()[1:-1]
45 |
46 | # 3rd line has a path in it. Pick out just the non-path tail of that
47 | fromlines[2] = fromlines[2][-24:]
48 | tolines[2] = tolines[2][-24:]
49 | diff = list(difflib.unified_diff(fromlines, tolines,
50 | fromfile, tofile, fromdate, todate))
51 | if len(diff) == 0:
52 | os.unlink(outfile)
53 | for line in diff:
54 | print line,
55 | return len(diff) == 0
56 |
57 | class PdbTests(unittest.TestCase):
58 |
59 | def test_settrace(self):
60 | """Test that 'tracing and set_trace (debugger) work"""
61 | global builddir
62 | result = run_python("tracetest", "settrace.py")
63 | self.assertEqual(True, result, "hanoi trace output comparision")
64 | return
65 |
66 | if __name__ == "__main__":
67 | unittest.main()
68 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | This is an expanded version of the Python debugger, pdb.py
2 |
3 | Largely we're trying to follow gdb's command set unless there's good
4 | reason. So new or modified command names generally refer to the
5 | function they have in gdb.
6 |
7 | Changes from pdb.py:
8 |
9 | - non-interactive POSIX-shell like line tracing.
10 |
11 | - Restart program saving settings (gdb's "run") or a pure "exec"
12 | restart (reloads the entire debugger)
13 |
14 | - Add "display" expressions
15 |
16 | - Some gdb "set"/"show" commands:
17 | args, listsize, version (no set here), and some new ones
18 | basename, cmdtrace, interactive, linetrace,
19 |
20 | - Some gdb "info" commands:
21 | args break, display, globals, line, locals, program, and source
22 |
23 | - Other gdb commands: cd, display, disassemble, frame, pwd, return
24 | (immediate return, not finish), run, shell, source, undisplay
25 |
26 | - debugger is installed in binary directory; i.e. one runs "pydb script..."
27 | rather than "python pdb script..."
28 |
29 | - debugger accepts debugger options; e.g. redirecting output or setting
30 | line tracing
31 |
32 | - Add Perl's "examine" to show info about a symbol. For functions,
33 | methods, classes and modules the documentation string if any is printed.
34 | For functions, we also show the argument list. More work is needed here
35 | to recurse fields of an arbitrary object and show that.
36 |
37 | - add gdb's "frame" command and stack order. Cleaner display of
38 | call stack; for example "exec" calls are marked as such.
39 |
40 | - gdb-like help with subcomamnd-specific help available on
41 | info, set, or show subcommands; e.g. "help info line" works
42 |
43 | - More extensive and complete documentation. See
44 | http://bashdb.sourceforge.net/pydb/pydb/lib/index.html
45 |
46 | - up/down can take a number of frames to move.
47 |
48 | - Stepping skips over "def" statements.
49 |
50 | - Comes with regression tests. Can also be subclassed to capture
51 | debugger output.
52 |
53 | - Works with GUI frontend ddd. (For now a testing version of ddd is
54 | required. See
55 | http://sourceforge.net/project/showfiles.php?group_id=61395&package_id=65341
56 | version 3.3.12-test3 or greater.
57 |
58 | - Miscellaneous pdb bugs fixed. (See ChangeLog for details)
59 |
60 | Coexistence:
61 | For now, we try not to conflict with pdb.py. After all, Python
62 | developers made provision of multiple debuggers so we'll make use of
63 | that!
64 |
65 | So whereever there was a pdb, use pydb. The class name is still
66 | Pdb. So the debugger initialization script is .pydbrc for this
67 | debugger rather than .pdbrc for the one that comes with Python.
68 |
69 | $Id: README,v 1.6 2006/02/21 21:12:57 rockyb Exp $
--------------------------------------------------------------------------------
/test/test-dbgcall.py.in:
--------------------------------------------------------------------------------
1 | #!@PYTHON@ -t
2 | # $Id: test-dbgcall.py.in,v 1.3 2008/12/26 02:40:45 rockyb Exp $ -*- Python -*-
3 | "Unit test for Extended Python debugger's debugger() call"
4 | import difflib, os, sys, time, unittest
5 | from subprocess import *
6 |
7 | top_builddir = "@top_builddir@"
8 | if top_builddir[-1] != os.path.sep:
9 | top_builddir += os.path.sep
10 | sys.path.insert(0, os.path.join(top_builddir, 'pydb'))
11 | top_srcdir = "@top_srcdir@"
12 | if top_srcdir[-1] != os.path.sep:
13 | top_srcdir += os.path.sep
14 | sys.path.insert(0, os.path.join(top_srcdir, 'pydb'))
15 |
16 | import pydb
17 |
18 | srcdir = "@srcdir@"
19 | if srcdir[-1] != os.path.sep:
20 | srcdir += os.path.sep
21 |
22 | class DbgCallTests(unittest.TestCase):
23 |
24 | def run_python(self, testname, pythonfile):
25 | global srcdir, builddir, pydir
26 |
27 | if sys.hexversion >= 0x02050000:
28 | rightfile = os.path.join(srcdir, 'data',
29 | "%s-2.5.right" % testname)
30 | else:
31 | rightfile = os.path.join(srcdir, 'data',
32 | "%s.right" % testname)
33 | pass
34 |
35 | outfile = 'dbgcall.out'
36 | cmd = '%s %s >%s' % ('@PYTHON@', pythonfile, outfile)
37 | os.system(cmd)
38 | # p = Popen(['@PYTHON@', pythonfile], stdout=PIPE)
39 | # output = p.communicate()[0]
40 | # if p.returncode != 0:
41 | # print output
42 | # print p.returncode
43 | # self.assertTrue(False, 'Could not run %s' % pythonfile)
44 | # return
45 |
46 | fromfile = rightfile
47 | fromdate = time.ctime(os.stat(fromfile).st_mtime)
48 | fromlines = open(fromfile, 'U').readlines()
49 | tofile = outfile
50 | todate = time.ctime(os.stat(tofile).st_mtime)
51 | tolines = open(tofile, 'U').readlines()
52 | diff = list(difflib.unified_diff(fromlines[1:], tolines[1:], fromfile,
53 | tofile, fromdate, todate))
54 | if len(diff) == 0:
55 | os.unlink(outfile)
56 | else:
57 | for line in diff:
58 | print line,
59 | self.assertEqual(len(diff), 0)
60 | return
61 |
62 | ## Don't use assertTrue to be compatible with older version of
63 | ## unittest
64 |
65 | def test_debugger_call(self):
66 | """Test debugger with 'dbg_cmds', and 'continue'"""
67 | global srcdir
68 | testname = 'dbgcall'
69 | pythonfile = '%s%s.py' % (srcdir, testname,)
70 | self.run_python(testname, pythonfile)
71 | return
72 |
73 | if __name__ == "__main__":
74 | unittest.main()
75 |
--------------------------------------------------------------------------------
/test/Makefile.am:
--------------------------------------------------------------------------------
1 | #$Id: Makefile.am,v 1.55 2009/04/10 23:42:02 rockyb Exp $
2 | # Copyright (C) 2006, 2007, 2008 Rocky Bernstein \n";
57 | my $name;
58 | foreach $name (split /,/, $self->{names}) {
59 | my($key,$type,$synopsis) = $self->get($name);
60 | my $link = "";
61 | $synopsis =~ s/
\n";
71 | $data;
72 | }
73 |
74 |
75 | package testSynopsisTable;
76 |
77 | sub test{
78 | # this little test is mostly to debug the stuff above, since this is
79 | # my first Perl "object".
80 | my $st = SynopsisTable->new();
81 | $st->declare("sample", "sample", "standard");
82 | $st->set_synopsis("sample", "This is a little synopsis....");
83 | $st->declare("copy_reg", "copyreg", "standard");
84 | $st->set_synopsis("copy_reg", "pickle support stuff");
85 | $st->show();
86 |
87 | print "\n\n";
88 |
89 | my $st2 = SynopsisTable->new();
90 | $st2->declare("st2module", "st2module", "built-in");
91 | $st2->set_synopsis("st2module", "silly little synopsis");
92 | $st2->show();
93 | }
94 |
95 | 1; # This must be the last line -- Perl is bogus!
96 |
--------------------------------------------------------------------------------
/test/test-help.py.in:
--------------------------------------------------------------------------------
1 | #!@PYTHON@ -t
2 | # $Id: test-help.py.in,v 1.3 2008/12/08 00:40:57 rockyb Exp $
3 | "Unit test of getting help options "
4 | import difflib, os, time, sys, unittest
5 |
6 | top_builddir = "@top_builddir@"
7 | if top_builddir[-1] != os.path.sep:
8 | top_builddir += os.path.sep
9 | sys.path.insert(0, os.path.join(top_builddir, 'pydb'))
10 | top_srcdir = "@top_srcdir@"
11 | if top_srcdir[-1] != os.path.sep:
12 | top_srcdir += os.path.sep
13 | sys.path.insert(0, os.path.join(top_srcdir, 'pydb'))
14 |
15 | builddir = "@builddir@"
16 | if builddir[-1] != os.path.sep:
17 | builddir += os.path.sep
18 |
19 | srcdir = "@srcdir@"
20 | if srcdir[-1] != os.path.sep:
21 | srcdir += os.path.sep
22 |
23 | pydir = os.path.join(top_builddir, "pydb")
24 | pydb_short = "pydb.py"
25 | pydb_path = os.path.join(pydir, pydb_short)
26 |
27 | def run_debugger(testname, pythonfile, pydb_opts='', args='',
28 | outfile=None, need_25=True):
29 | global srcdir, builddir, pydir
30 |
31 | if sys.hexversion >= 0x02050000 and need_25:
32 | rightfile = os.path.join(srcdir, 'data',
33 | "%s-2.5.right" % testname)
34 | else:
35 | rightfile = os.path.join(srcdir, 'data',
36 | "%s.right" % testname)
37 |
38 | outfile_opt = ''
39 | if outfile is None:
40 | outfile = os.path.join(builddir, "%s.out" % testname)
41 |
42 | if os.path.exists(outfile): os.unlink(outfile)
43 |
44 | os.environ['PYTHONPATH']=os.pathsep.join(sys.path)
45 | os.environ['COLUMNS']='80'
46 | cmd = "%s %s %s %s >%s" % \
47 | (pydb_path, pydb_opts, pythonfile, args, outfile)
48 |
49 | os.system(cmd)
50 | fromfile = rightfile
51 | fromdate = time.ctime(os.stat(fromfile).st_mtime)
52 | fromlines = open(fromfile, 'U').readlines()[0:-2]
53 | tofile = outfile
54 | todate = time.ctime(os.stat(tofile).st_mtime)
55 | tolines = open(tofile, 'U').readlines()[0:-2]
56 | # Curse you getopts! I'm so ashamed.
57 | tolines[0] = fromlines[0].lower() # Usage -> usage
58 | tolines[4] = fromlines[4].lower() # Options -> options
59 | diff = list(difflib.unified_diff(fromlines, tolines, fromfile,
60 | tofile, fromdate, todate))
61 | if len(diff) == 0:
62 | os.unlink(outfile)
63 | for line in diff:
64 | print line,
65 | return len(diff) == 0
66 |
67 | class PdbTests(unittest.TestCase):
68 |
69 | def test_help(self):
70 | """Test getting help: --help and -h options"""
71 | for trace_opt in ['--help', '-h']:
72 | result=run_debugger(testname='help',
73 | pydb_opts='%s --help' % trace_opt,
74 | pythonfile='', need_25 = False)
75 | self.assertEqual(True, result,
76 | "help listing output comparision" )
77 |
78 |
79 | if __name__ == "__main__":
80 | unittest.main()
81 |
--------------------------------------------------------------------------------
/test/test-pm.py.in:
--------------------------------------------------------------------------------
1 | #!@PYTHON@ -t
2 | # $Id: test-pm.py.in,v 1.2 2008/11/17 19:06:39 rockyb Exp $ -*- Python -*-
3 | "Unit test for Extended Python debugger's Post-Mortem (pm) commands "
4 | import difflib, os, time, sys, unittest
5 |
6 | top_builddir = "@top_builddir@"
7 | if top_builddir[-1] != os.path.sep:
8 | top_builddir += os.path.sep
9 | sys.path.insert(0, os.path.join(top_builddir, 'pydb'))
10 | top_srcdir = "@top_srcdir@"
11 | if top_srcdir[-1] != os.path.sep:
12 | top_srcdir += os.path.sep
13 | sys.path.insert(0, os.path.join(top_srcdir, 'pydb'))
14 |
15 | import pydb
16 |
17 | builddir = "@builddir@"
18 | if builddir[-1] != os.path.sep:
19 | builddir += os.path.sep
20 |
21 | top_builddir = "@top_builddir@"
22 | if top_builddir[-1] != os.path.sep:
23 | top_builddir += os.path.sep
24 |
25 | srcdir = "@srcdir@"
26 | if srcdir[-1] != os.path.sep:
27 | srcdir += os.path.sep
28 |
29 | pydir = os.path.join(top_builddir, "pydb")
30 | pydb_short = "pydb.py"
31 | pydb_path = os.path.join(pydir, pydb_short)
32 |
33 | def raise_error():
34 | raise FloatingPointError
35 |
36 | class PdbTests(unittest.TestCase):
37 |
38 | ## Don't use assertTrue to be compatible with older version of
39 | ## unittest
40 |
41 | def test_postmortem2(self):
42 | """Test post-mortem processing without a traceback"""
43 | pydb.post_mortem()
44 | self.assertEqual(True, True, "post-mortem test with no traceback")
45 |
46 | def test_postmortem(self):
47 | """Test post-mortem processing"""
48 | try:
49 | raise_error()
50 | except FloatingPointError:
51 | t = sys.exc_info()[2]
52 | outfile = 'pm.out'
53 | rightfile = os.path.join(srcdir, 'data', 'pm.right')
54 | errfile = 'pm.err'
55 | old_stdout = sys.stdout
56 | old_stderr = sys.stderr
57 | sys.stdout = open(outfile, 'w')
58 | sys.stderr = open(errfile, 'w')
59 | pydb.post_mortem(t=t, dbg_cmds=None,
60 | cmdfile=os.path.join(srcdir, 'pm.cmd'))
61 | sys.stdout.close()
62 | sys.stderr.close()
63 | sys.stdout = old_stdout
64 | sys.stderr = old_stderr
65 | fromfile = rightfile
66 | fromdate = time.ctime(os.stat(fromfile).st_mtime)
67 | fromlines = open(fromfile, 'U').readlines()
68 | tofile = outfile
69 | todate = time.ctime(os.stat(tofile).st_mtime)
70 | tolines = open(tofile, 'U').readlines()
71 |
72 | diff = list(difflib.unified_diff(fromlines, tolines, fromfile,
73 | tofile, fromdate, todate))
74 |
75 | if len(diff) == 0:
76 | os.unlink(outfile)
77 | os.unlink(errfile)
78 | for line in diff:
79 | print line,
80 | self.assertEqual(0, len(diff), "post-mortem test")
81 | return
82 |
83 |
84 | if __name__ == "__main__":
85 | unittest.main()
86 |
--------------------------------------------------------------------------------
/pydb/bytecode.py:
--------------------------------------------------------------------------------
1 | from opcode import *
2 | import dis
3 | import re
4 |
5 | def op_at_code_loc(code, loc):
6 | try:
7 | op = ord(code[loc])
8 | except IndexError:
9 | return 'got IndexError'
10 | return opname[op]
11 |
12 | def op_at_frame(frame, loc=None):
13 | code = frame.f_code.co_code
14 | if loc is None: loc = frame.f_lasti
15 | return op_at_code_loc(code, loc)
16 |
17 | def next_opcode(code, offset):
18 | '''Return the next opcode and offset as a tuple. Tuple (-100,
19 | -1000) is returned when reaching the end.'''
20 | n = len(code)
21 | while offset < n:
22 | c = code[offset]
23 | op = ord(c)
24 | offset += 1
25 | if op >= HAVE_ARGUMENT:
26 | offset += 2
27 | pass
28 | yield op, offset
29 | pass
30 | yield -100, -1000
31 | pass
32 |
33 | def next_linestart(co, offset, count=1):
34 | linestarts = dict(dis.findlinestarts(co))
35 | code = co.co_code
36 | n = len(code)
37 | contains_cond_jump = False
38 | for op, offset in next_opcode(code, offset):
39 | if offset in linestarts:
40 | count -= 1
41 | if 0 == count:
42 | return linestarts[offset]
43 | pass
44 | pass
45 | return -1000
46 |
47 | # FIXME: break out into a code iterator.
48 | def stmt_contains_make_function(co, lineno):
49 | linestarts = dict(dis.findlinestarts(co))
50 | code = co.co_code
51 | found_start = False
52 | for offset, start_line in linestarts.items():
53 | if start_line == lineno:
54 | found_start = True
55 | break
56 | pass
57 | if not found_start:
58 | return False
59 | for op, offset in next_opcode(code, offset):
60 | if -1000 == offset or linestarts.get(offset): return False
61 | opcode = opname[op]
62 | # print opcode
63 | if 'MAKE_FUNCTION' == opcode:
64 | return True
65 | pass
66 | return False
67 |
68 | # A pattern for a def header seems to be used a couple of times.
69 | _re_def_str = r'^\s*def\s'
70 | _re_def = re.compile(_re_def_str)
71 | def is_def_stmt(line, frame):
72 | """Return True if we are looking at a def statement"""
73 | # Should really also check that operand is a code object
74 | return _re_def.match(line) and op_at_frame(frame)=='LOAD_CONST' \
75 | and stmt_contains_make_function(frame.f_code, frame.f_lineno)
76 |
77 | # Demo stuff above
78 | if __name__=='__main__':
79 | import inspect
80 | def sqr(x):
81 | return x * x
82 | frame = inspect.currentframe()
83 | co = frame.f_code
84 | lineno = frame.f_lineno
85 | print 'contains MAKE_FUNCTION', stmt_contains_make_function(co, lineno-4)
86 | print 'contains MAKE_FUNCTION', stmt_contains_make_function(co, lineno)
87 |
88 | print "op at frame: ", op_at_frame(frame)
89 | print "op at frame, position 2", op_at_frame(frame, 2)
90 | print "def statement: x=5?: ", is_def_stmt('x=5', frame)
91 | # Not a "def" statement because frame is wrong spot
92 | print is_def_stmt('def foo():', frame)
93 |
94 | pass
95 |
--------------------------------------------------------------------------------
/test/test-setshow.py.in:
--------------------------------------------------------------------------------
1 | #!@PYTHON@ -t
2 | # $Id: test-setshow.py.in,v 1.5 2008/12/10 13:31:26 rockyb Exp $ -*- Python -*-
3 | "Unit test of the file command for Extended Python debugger "
4 | import difflib, os, time, sys, unittest
5 |
6 | top_builddir = "@top_builddir@"
7 | if top_builddir[-1] != os.path.sep:
8 | top_builddir += os.path.sep
9 | sys.path.insert(0, os.path.join(top_builddir, 'pydb'))
10 | top_srcdir = "@top_srcdir@"
11 | if top_srcdir[-1] != os.path.sep:
12 | top_srcdir += os.path.sep
13 | sys.path.insert(0, os.path.join(top_srcdir, 'pydb'))
14 |
15 | builddir = "@builddir@"
16 | if builddir[-1] != os.path.sep:
17 | builddir += os.path.sep
18 |
19 | srcdir = "@srcdir@"
20 | if srcdir[-1] != os.path.sep:
21 | srcdir += os.path.sep
22 |
23 | pydir = os.path.join(top_builddir, "pydb")
24 | pydb_short = "pydb.py"
25 | pydb_path = os.path.join(pydir, pydb_short)
26 |
27 | def run_debugger(testname, pythonfile, pydb_opts='', args='',
28 | rightfile=None):
29 | global srcdir, builddir, pydir
30 |
31 | if rightfile is None:
32 | rightfile = os.path.join(srcdir, 'data',
33 | "%s.right" % testname)
34 |
35 | os.environ['PYTHONPATH']=os.pathsep.join(sys.path)
36 | cmdfile = os.path.join(srcdir, "%s.cmd" % testname)
37 | outfile = "%s.out" % testname
38 | outfile_opt = '--output=%s ' % outfile
39 |
40 | # print "builddir: %s, cmdfile: %s, outfile: %s, rightfile: %s" % \
41 | # (builddir, cmdfile, outfile, rightfile)
42 |
43 | if os.path.exists(outfile): os.unlink(outfile)
44 |
45 | cmd = "%s --command %s %s %s %s %s" % \
46 | (pydb_path, cmdfile, outfile_opt, pydb_opts, args, pythonfile)
47 |
48 | os.system(cmd)
49 | fromfile = rightfile
50 | fromdate = time.ctime(os.stat(fromfile).st_mtime)
51 | # fromlines = open(fromfile, 'U').readlines()[0:-1]
52 | fromlines = open(fromfile, 'U').readlines()
53 | tofile = outfile
54 | todate = time.ctime(os.stat(tofile).st_mtime)
55 | # tolines = open(tofile, 'U').readlines()[0:-1]
56 | tolines = open(tofile, 'U').readlines()
57 | diff = list(difflib.unified_diff(fromlines, tolines, fromfile,
58 | tofile, fromdate, todate))
59 | if len(diff) == 0:
60 | os.unlink(outfile)
61 | for line in diff:
62 | print line,
63 | return len(diff) == 0
64 |
65 | class PdbTests(unittest.TestCase):
66 |
67 | def test_setshow(self):
68 | """Test running program via the 'file' command"""
69 |
70 | try:
71 | import readline
72 | rightfile = os.path.join(srcdir, 'data',
73 | "setshow.right")
74 | except ImportError:
75 | rightfile = os.path.join(srcdir, 'data',
76 | "setshow-no-rl.right")
77 |
78 | result=run_debugger(testname='setshow', pythonfile='',
79 | pydb_opts='--basename', rightfile=rightfile)
80 | self.assertEqual(True, result, "pydb 'set/show' command comparision")
81 | return
82 |
83 | if __name__ == "__main__":
84 | unittest.main()
85 |
--------------------------------------------------------------------------------
/test/test-sighandle.py.in:
--------------------------------------------------------------------------------
1 | #!@PYTHON@ -t
2 | # -*- Python -*-
3 | # $Id: test-sighandle.py.in,v 1.2 2009/03/06 08:51:46 rockyb Exp $
4 | "Unit test for Extended Python debugger's signal handling commands "
5 | import os, time, sys, unittest, signal
6 |
7 | top_builddir = "@top_builddir@"
8 | if top_builddir[-1] != os.path.sep:
9 | top_builddir += os.path.sep
10 | sys.path.insert(0, os.path.join(top_builddir, 'pydb'))
11 | top_srcdir = "@top_srcdir@"
12 | if top_srcdir[-1] != os.path.sep:
13 | top_srcdir += os.path.sep
14 | sys.path.insert(0, os.path.join(top_srcdir, 'pydb'))
15 |
16 | import pydb, sighandler
17 |
18 | builddir = "@builddir@"
19 | if builddir[-1] != os.path.sep:
20 | builddir += os.path.sep
21 |
22 | top_builddir = "@top_builddir@"
23 | if top_builddir[-1] != os.path.sep:
24 | top_builddir += os.path.sep
25 |
26 | srcdir = "@srcdir@"
27 | if srcdir[-1] != os.path.sep:
28 | srcdir += os.path.sep
29 |
30 | pydir = os.path.join(top_builddir, "pydb")
31 | pydb_short = "pydb.py"
32 | pydb_path = os.path.join(pydir, pydb_short)
33 | outfile = 'sighandler.out'
34 | program = 'sigtestexample.py'
35 |
36 | class PdbTest(pydb.Pdb):
37 | def __init__(self):
38 | pydb.Pdb.__init__(self)
39 | self.errLines = []
40 | self.msgLines = []
41 | self.msg_last_nocr = False
42 | self.stack = self.curframe = self.botframe = None
43 |
44 | def resetmsg(self):
45 | self.msgLines=[]
46 |
47 | def errmsg(self, msg):
48 | self.errLines.append(msg)
49 |
50 | def msg(self, msg):
51 | if self.msg_last_nocr:
52 | self.msgLines[-1] += msg
53 | else:
54 | self.msgLines.append(msg)
55 | self.msg_last_nocr = False
56 |
57 | def msg_nocr(self, msg):
58 | if self.msg_last_nocr:
59 | self.msgLines[-1] += msg
60 | else:
61 | self.msgLines.append(msg)
62 | self.msg_last_nocr = True
63 |
64 | class SigTests(unittest.TestCase):
65 |
66 | def test_settings(self):
67 | """Test setting signals"""
68 | p = PdbTest()
69 | h = sighandler.SignalManager(p)
70 | # Set to known value
71 | h.action('SIGUSR1 print pass')
72 | h.info_signal(['USR1'])
73 | correct = ["Signal Stop Print Stack Pass Description",
74 | "SIGUSR1 No Yes Yes No User-defined signal 1"]
75 | self.assertEqual(p.msgLines, correct)
76 | p.resetmsg()
77 | # noprint implies no stop
78 | h.action('SIGUSR1 noprint stack pass')
79 | h.info_signal(['USR1'])
80 | correct = ["Signal Stop Print Stack Pass Description",
81 | "SIGUSR1 No No Yes Yes User-defined signal 1"]
82 | self.assertEqual(p.msgLines, correct)
83 | # stop keyword implies print and nopass
84 | p.resetmsg()
85 | h.action('SIGUSR1 stop')
86 | h.info_signal(['USR1'])
87 | correct = ["Signal Stop Print Stack Pass Description",
88 | "SIGUSR1 Yes Yes No Yes User-defined signal 1"]
89 | self.assertEqual(p.msgLines, correct)
90 |
91 | if __name__ == '__main__':
92 | unittest.main()
93 |
--------------------------------------------------------------------------------
/test/cmdparse.cmd:
--------------------------------------------------------------------------------
1 | # $Id: cmdparse.cmd,v 1.21 2009/03/18 10:15:23 rockyb Exp $
2 | # This tests the functioning of some debugger command a
3 | # parsing and set/show processing
4 | set basename on
5 | set trace-commands on
6 | ### *******************************
7 | ### *** Set/show commands ***
8 | ### *******************************
9 | ########################################
10 | ### test args and baseneme...
11 | ########################################
12 | set args this is a test
13 | show args
14 | show basename
15 | set basename foo
16 | show base
17 | set basename off
18 | show basename
19 | set basename 0
20 | show basename
21 | set basename 1
22 | show basename
23 | ########################################
24 | ### test listsize tests...
25 | ########################################
26 | show listsize
27 | set listsize 10+10
28 | show listsi
29 | set listsize abc
30 | set listsize -20
31 | set listsize 20 forever
32 | ########################################
33 | ### test linetrace...
34 | ########################################
35 | set linetrace delay
36 | set linetrace delay 2
37 | show linetrace delay
38 | set linetrace delay 0.5
39 | show linetrace delay
40 | set linetrace delay foo
41 | show linetrace delay
42 | set linetrace on
43 | show linetrace
44 | set linetrace off
45 | show linetrace
46 | show maxargsize
47 | ########################################
48 | ### bad enable disable
49 | ########################################
50 | enable 10
51 | disable 10
52 | enable foo
53 | disable foo
54 | ########################################
55 | ### test list
56 | ########################################
57 | list
58 | list
59 | list -
60 | list 10 15
61 | list 10 3
62 | list hanoi.py:12
63 | list hanoi
64 | list hanoi 10
65 | list gcd.py:24
66 | list .
67 | # first and last file names are different
68 | list gcd.py:24 hanoi.py:10
69 | # File doesn't have 50 lines
70 | list 50
71 | set listsi 6
72 | list 5
73 | # Invalid list command - need lineno or fn name
74 | list hanoi.py
75 | ########################################
76 | ### test prompt, misc...
77 | ########################################
78 | show prompt
79 | show foo
80 | cd
81 | ########################################
82 | ### test numeric argument syntax
83 | ########################################
84 | up fdsafdsa
85 | u='foo'
86 | down 1 b c
87 | frame foo
88 | step -1
89 | next -1
90 | ########################################
91 | ### test info
92 | ########################################
93 | info line
94 | info source
95 | ########################################
96 | ### help/info stuff
97 | ########################################
98 | help nogood
99 | help restart
100 | help run
101 | help set
102 | help set linesize
103 | help set listsize
104 | help show
105 | help show listsize
106 | help info
107 | #######################################
108 | # The below "help info" lines should
109 | # have '.' append to the end whereas
110 | # in the above listing they were
111 | # omitted.
112 | #######################################
113 | help info program
114 | help info source
115 | #######################################
116 | # The below "help show" commands have
117 | # more than one line of output also
118 | # ommited in a simple "show"
119 | #######################################
120 | help show args
121 | help show commands
122 | quit
123 |
--------------------------------------------------------------------------------
/test/data/dbgcall.right:
--------------------------------------------------------------------------------
1 | (/tmp/pydb-1.25/test/dbgcall.py:17):
2 | 17 if __name__=='__main__':
3 | (dbgcall.py:18):
4 | + 18 i_args=len(sys.argv)
5 | (dbgcall.py:19):
6 | + 19 if i_args != 1 and i_args != 2:
7 | (dbgcall.py:23):
8 | + 23 n=3
9 | (dbgcall.py:24):
10 | + 24 sys.settrace(None)
11 | (dbgcall.py:34):
12 | + 34 if n < 1 or n > 100:
13 | (dbgcall.py:38):
14 | + 38 hanoi(n, "a", "b", "c")
15 | --Call level -5
16 | (dbgcall.py:10): hanoi
17 | + 10 def hanoi(n,a,b,c):
18 | (dbgcall.py:11): hanoi
19 | + 11 if n-1 > 0:
20 | (dbgcall.py:12): hanoi
21 | + 12 hanoi(n-1, a, c, b)
22 | --Call level -4
23 | (dbgcall.py:10): hanoi
24 | + 10 def hanoi(n,a,b,c):
25 | (dbgcall.py:11): hanoi
26 | + 11 if n-1 > 0:
27 | (dbgcall.py:12): hanoi
28 | + 12 hanoi(n-1, a, c, b)
29 | --Call level -3
30 | (dbgcall.py:10): hanoi
31 | + 10 def hanoi(n,a,b,c):
32 | (dbgcall.py:11): hanoi
33 | + 11 if n-1 > 0:
34 | (dbgcall.py:13): hanoi
35 | + 13 print "Move disk %s to %s" % (a, b)
36 | Move disk a to b
37 | (dbgcall.py:14): hanoi
38 | + 14 if n-1 > 0:
39 | (dbgcall.py:14): hanoi
40 | + 14 if n-1 > 0:
41 | (dbgcall.py:13): hanoi
42 | + 13 print "Move disk %s to %s" % (a, b)
43 | Move disk a to c
44 | (dbgcall.py:14): hanoi
45 | + 14 if n-1 > 0:
46 | (dbgcall.py:15): hanoi
47 | + 15 hanoi(n-1, c, b, a)
48 | --Call level -3
49 | (dbgcall.py:10): hanoi
50 | + 10 def hanoi(n,a,b,c):
51 | (dbgcall.py:11): hanoi
52 | + 11 if n-1 > 0:
53 | (dbgcall.py:13): hanoi
54 | + 13 print "Move disk %s to %s" % (a, b)
55 | Move disk b to c
56 | (dbgcall.py:14): hanoi
57 | + 14 if n-1 > 0:
58 | (dbgcall.py:14): hanoi
59 | + 14 if n-1 > 0:
60 | (dbgcall.py:15): hanoi
61 | + 15 hanoi(n-1, c, b, a)
62 | (dbgcall.py:13): hanoi
63 | + 13 print "Move disk %s to %s" % (a, b)
64 | 'continued'
65 | Move disk a to b
66 | (dbgcall.py:14): hanoi
67 | + 14 if n-1 > 0:
68 | (dbgcall.py:15): hanoi
69 | + 15 hanoi(n-1, c, b, a)
70 | --Call level -4
71 | (dbgcall.py:10): hanoi
72 | + 10 def hanoi(n,a,b,c):
73 | (dbgcall.py:11): hanoi
74 | + 11 if n-1 > 0:
75 | (dbgcall.py:12): hanoi
76 | + 12 hanoi(n-1, a, c, b)
77 | --Call level -3
78 | (dbgcall.py:10): hanoi
79 | + 10 def hanoi(n,a,b,c):
80 | (dbgcall.py:11): hanoi
81 | + 11 if n-1 > 0:
82 | (dbgcall.py:13): hanoi
83 | + 13 print "Move disk %s to %s" % (a, b)
84 | Move disk c to a
85 | (dbgcall.py:14): hanoi
86 | + 14 if n-1 > 0:
87 | (dbgcall.py:14): hanoi
88 | + 14 if n-1 > 0:
89 | (dbgcall.py:13): hanoi
90 | + 13 print "Move disk %s to %s" % (a, b)
91 | Move disk c to b
92 | (dbgcall.py:14): hanoi
93 | + 14 if n-1 > 0:
94 | (dbgcall.py:15): hanoi
95 | + 15 hanoi(n-1, c, b, a)
96 | --Call level -3
97 | (dbgcall.py:10): hanoi
98 | + 10 def hanoi(n,a,b,c):
99 | (dbgcall.py:11): hanoi
100 | + 11 if n-1 > 0:
101 | (dbgcall.py:13): hanoi
102 | + 13 print "Move disk %s to %s" % (a, b)
103 | Move disk a to b
104 | (dbgcall.py:14): hanoi
105 | + 14 if n-1 > 0:
106 | (dbgcall.py:14): hanoi
107 | + 14 if n-1 > 0:
108 | (dbgcall.py:15): hanoi
109 | + 15 hanoi(n-1, c, b, a)
110 | (dbgcall.py:15): hanoi
111 | + 15 hanoi(n-1, c, b, a)
112 | (dbgcall.py:38):
113 | + 38 hanoi(n, "a", "b", "c")
114 |
--------------------------------------------------------------------------------
/test/data/brkpt1-2.7.right:
--------------------------------------------------------------------------------
1 | +###############################################################
2 | +# Test the breakpoint by line number
3 | +###############################################################
4 | +info break
5 | No breakpoints.
6 | +break 30
7 | *** Blank, doc string, or comment
8 | +info break
9 | No breakpoints.
10 | +###############################################################
11 | +### Test enable/disable...
12 | +###############################################################
13 | +enable
14 | *** No breakpoint number given
15 | +enable 1
16 | *** No breakpoint numbered 1.
17 | +info break
18 | No breakpoints.
19 | +enable foo
20 | *** Breakpoint index 'foo' is not a number
21 | +disable 1
22 | No breakpoint numbered 1.
23 | +disable
24 | *** No breakpoint number given.
25 | +info break
26 | No breakpoints.
27 | +################################################################
28 | +### Try setting breakpoints outside of the file range...
29 | +###############################################################
30 | +break 0
31 | *** End of file
32 | +break 1
33 | *** Blank, doc string, or comment
34 | +break 99
35 | *** End of file
36 | +#
37 | +# list breakpoints
38 | +L
39 | No breakpoints.
40 | +###############################################################
41 | +### *** Test using file:line format on break...
42 | +###############################################################
43 | +break hanoi.py:22
44 | Breakpoint 1 set in file hanoi.py, line 22.
45 | +break ./hanoi.py:22
46 | Breakpoint 2 set in file hanoi.py, line 22.
47 | +break ./hanoi.py:0
48 | *** End of file
49 | +break ./dbg-test1.sh:1955
50 | *** './dbg-test1.sh' not found using sys.path
51 | +info break
52 | Num Type Disp Enb Where
53 | 1 breakpoint keep y at hanoi.py:22
54 | 2 breakpoint keep y at hanoi.py:22
55 | +#### Try deleting breakpoints...
56 | +delete 10
57 | *** No breakpoint numbered 10.
58 | +delete 1
59 | Deleted breakpoint 1
60 | +clear 22
61 | Deleted breakpoint 2
62 | +info break
63 | No breakpoints.
64 | +break 22
65 | Breakpoint 3 set in file hanoi.py, line 22.
66 | +###############################################################
67 | +### *** Test breakpoints with conditions...
68 | +###############################################################
69 | +condition 1 x==0
70 | +### FIXME: there is no condition 2!
71 | +### condition 2 y > 25
72 | +condition 2+2 y > 25
73 | *** No breakpoint numbered 4.
74 | +info break
75 | Num Type Disp Enb Where
76 | 3 breakpoint keep y at hanoi.py:22
77 | +### FIXME: there still is no condition 2
78 | +### condition 2
79 | +condition 4
80 | *** No breakpoint numbered 4.
81 | +info break
82 | Num Type Disp Enb Where
83 | 3 breakpoint keep y at hanoi.py:22
84 | +condition x==1
85 | *** condition command: Expecting a positive integer, got: x==1
86 | +condition bad
87 | *** condition command: Expecting a positive integer, got: bad
88 | +condition 30 y==1
89 | *** No breakpoint numbered 30.
90 | +condition 0 y==1
91 | *** condition command: Expecting a positive integer at least 1, got: 0.
92 | +###############################################################
93 | +### *** Test breakpoints by function name
94 | +###############################################################
95 | +break hanoi
96 | Breakpoint 4 set in file hanoi.py, line 5.
97 | +clear hanoi
98 | Deleted breakpoint 4
99 | +q
100 |
--------------------------------------------------------------------------------
/test/data/brkpt1.right:
--------------------------------------------------------------------------------
1 | +###############################################################
2 | +# Test the breakpoint by line number
3 | +###############################################################
4 | +info break
5 | No breakpoints.
6 | +break 30
7 | *** Blank, doc string, or comment
8 | +info break
9 | No breakpoints.
10 | +###############################################################
11 | +### Test enable/disable...
12 | +###############################################################
13 | +enable
14 | *** No breakpoint number given
15 | +enable 1
16 | *** No breakpoint numbered 1.
17 | +info break
18 | No breakpoints.
19 | +enable foo
20 | *** Breakpoint index 'foo' is not a number
21 | +disable 1
22 | No breakpoint numbered 1.
23 | +disable
24 | *** No breakpoint number given.
25 | +info break
26 | No breakpoints.
27 | +################################################################
28 | +### Try setting breakpoints outside of the file range...
29 | +###############################################################
30 | +break 0
31 | *** End of file
32 | +break 1
33 | *** Blank, doc string, or comment
34 | +break 99
35 | *** End of file
36 | +#
37 | +# list breakpoints
38 | +L
39 | No breakpoints.
40 | +###############################################################
41 | +### *** Test using file:line format on break...
42 | +###############################################################
43 | +break hanoi.py:22
44 | Breakpoint 1 set in file hanoi.py, line 22.
45 | +break ./hanoi.py:22
46 | Breakpoint 2 set in file hanoi.py, line 22.
47 | +break ./hanoi.py:0
48 | *** End of file
49 | +break ./dbg-test1.sh:1955
50 | *** './dbg-test1.sh' not found using sys.path
51 | +info break
52 | Num Type Disp Enb Where
53 | 1 breakpoint keep y at hanoi.py:22
54 | 2 breakpoint keep y at hanoi.py:22
55 | +#### Try deleting breakpoints...
56 | +delete 10
57 | *** No breakpoint numbered 10.
58 | +delete 1
59 | Deleted breakpoint 1
60 | +clear 22
61 | *** No breakpoint at hanoi.py:22.
62 | +info break
63 | No breakpoints.
64 | +break 22
65 | Breakpoint 3 set in file hanoi.py, line 22.
66 | +###############################################################
67 | +### *** Test breakpoints with conditions...
68 | +###############################################################
69 | +condition 1 x==0
70 | +### FIXME: there is no condition 2!
71 | +### condition 2 y > 25
72 | +condition 2+2 y > 25
73 | *** No breakpoint numbered 4.
74 | +info break
75 | Num Type Disp Enb Where
76 | 3 breakpoint keep y at hanoi.py:22
77 | +### FIXME: there still is no condition 2
78 | +### condition 2
79 | +condition 4
80 | *** No breakpoint numbered 4.
81 | +info break
82 | Num Type Disp Enb Where
83 | 3 breakpoint keep y at hanoi.py:22
84 | +condition x==1
85 | *** condition command: Expecting a positive integer, got: x==1
86 | +condition bad
87 | *** condition command: Expecting a positive integer, got: bad
88 | +condition 30 y==1
89 | *** No breakpoint numbered 30.
90 | +condition 0 y==1
91 | *** condition command: Expecting a positive integer at least 1, got: 0.
92 | +###############################################################
93 | +### *** Test breakpoints by function name
94 | +###############################################################
95 | +break hanoi
96 | Breakpoint 4 set in file hanoi.py, line 5.
97 | +clear hanoi
98 | Deleted breakpoint 4
99 | +q
100 |
--------------------------------------------------------------------------------
/test/test-with.py.in:
--------------------------------------------------------------------------------
1 | #!@PYTHON@ -t
2 | # $Id: test-with.py.in,v 1.7 2008/12/10 13:31:26 rockyb Exp $ -*- Python -*-
3 | """Unit test of the bug in using 'info local' when inside a "with" command."""
4 | import difflib, os, time, sys, unittest
5 |
6 | top_builddir = "@top_builddir@"
7 | if top_builddir[-1] != os.path.sep:
8 | top_builddir += os.path.sep
9 | sys.path.insert(0, os.path.join(top_builddir, 'pydb'))
10 | top_srcdir = "@top_srcdir@"
11 | if top_srcdir[-1] != os.path.sep:
12 | top_srcdir += os.path.sep
13 | sys.path.insert(0, os.path.join(top_srcdir, 'pydb'))
14 |
15 | builddir = "@builddir@"
16 | if builddir[-1] != os.path.sep:
17 | builddir += os.path.sep
18 |
19 | srcdir = "@srcdir@"
20 | if srcdir[-1] != os.path.sep:
21 | srcdir += os.path.sep
22 |
23 | pydir = os.path.join(top_builddir, "pydb")
24 | pydb_short = "pydb.py"
25 | pydb_path = os.path.join(pydir, pydb_short)
26 |
27 | def run_debugger(testname, pythonfile, pydb_opts='', args='', rightfile=None,
28 | need_26=False):
29 | global srcdir, builddir, pydir
30 |
31 | if rightfile is None:
32 | rightfile = os.path.join(builddir, 'data', "%s.right" % testname)
33 |
34 | os.environ['PYTHONPATH']=os.pathsep.join(sys.path)
35 | cmdfile = os.path.join(srcdir, "%s.cmd" % testname)
36 | outfile = "%s.out" % testname
37 | outfile_opt = '--output=%s ' % outfile
38 |
39 | # print "builddir: %s, cmdfile: %s, outfile: %s, rightfile: %s" % \
40 | # (builddir, cmdfile, outfile, rightfile)
41 |
42 | if os.path.exists(outfile): os.unlink(outfile)
43 |
44 | cmd = "%s --command %s %s %s %s %s" % \
45 | (pydb_path, cmdfile, outfile_opt, pydb_opts, args, pythonfile)
46 |
47 | os.system(cmd)
48 | fromfile = rightfile
49 | fromdate = time.ctime(os.stat(fromfile).st_mtime)
50 | fromlines = open(fromfile, 'U').readlines()[0:-1]
51 | tofile = outfile
52 | todate = time.ctime(os.stat(tofile).st_mtime)
53 | tolines = open(tofile, 'U').readlines()[0:-1]
54 | if not need_26:
55 | tolines[4]= tolines[4][0:74] + "\n"
56 | diff = list(difflib.unified_diff(fromlines, tolines, fromfile,
57 | tofile, fromdate, todate))
58 | if len(diff) == 0:
59 | os.unlink(outfile)
60 | for line in diff:
61 | print line,
62 | return len(diff) == 0
63 |
64 | class PdbTests(unittest.TestCase):
65 |
66 | def test_with(self):
67 | """Test running bug running "info local" inside a "with" command"""
68 | if sys.hexversion >= 0x02050000:
69 | if sys.hexversion >= 0x02060000:
70 | need_26 = True
71 | rightfile = os.path.join(srcdir, 'data',
72 | "withbug-2.6.right")
73 | else:
74 | need_26 = False
75 | rightfile = os.path.join(srcdir, 'data',
76 | "withbug.right")
77 | result=run_debugger(testname='withbug',
78 | pythonfile='%swithbug.py' % srcdir,
79 | pydb_opts='--basename',
80 | rightfile=rightfile, need_26=need_26)
81 | self.assertEqual(True, result, "pydb 'withbug' command comparision")
82 | self.assertTrue(True, 'With test skipped - not 2.5')
83 | return
84 |
85 | if __name__ == "__main__":
86 | unittest.main()
87 |
--------------------------------------------------------------------------------
/test/data/tracetest-2.4-final.right:
--------------------------------------------------------------------------------
1 | (/tmp/pydb-1.23cvs/test/settrace.py:51):
2 | 51 hanoi(n, "a", "b", "c")
3 | -> 0 in file 'settrace.py' at line 51
4 | 46 'continue']
5 | 47
6 | 48 import pydb
7 | 49 pydb.debugger(dbg_cmds)
8 | 50
9 | 51 -> hanoi(n, "a", "b", "c")
10 | [EOF]
11 | --Call level -5
12 | (settrace.py:14): hanoi
13 | 14 def hanoi(n,a,b,c):
14 | (settrace.py:15): hanoi
15 | 15 if n-1 > 0:
16 | -> 0 hanoi(n=3, a='a', b='b', c='c') called from file 'settrace.py' at line 15
17 | ## 1 in file 'settrace.py' at line 51
18 | a = 'a'
19 | c = 'c'
20 | b = 'b'
21 | n = 3
22 | (settrace.py:16): hanoi
23 | + 16 hanoi(n-1, a, c, b)
24 | --Call level -4
25 | (settrace.py:14): hanoi
26 | + 14 def hanoi(n,a,b,c):
27 | (settrace.py:15): hanoi
28 | + 15 if n-1 > 0:
29 | (settrace.py:16): hanoi
30 | + 16 hanoi(n-1, a, c, b)
31 | --Call level -3
32 | (settrace.py:14): hanoi
33 | + 14 def hanoi(n,a,b,c):
34 | (settrace.py:15): hanoi
35 | + 15 if n-1 > 0:
36 | (settrace.py:17): hanoi
37 | + 17 print "Move disk %s to %s" % (a, b)
38 | Move disk a to b
39 | (settrace.py:18): hanoi
40 | + 18 if n-1 > 0:
41 | (settrace.py:18): hanoi
42 | + 18 if n-1 > 0:
43 | (settrace.py:17): hanoi
44 | + 17 print "Move disk %s to %s" % (a, b)
45 | Move disk a to c
46 | (settrace.py:18): hanoi
47 | + 18 if n-1 > 0:
48 | (settrace.py:19): hanoi
49 | + 19 hanoi(n-1, c, b, a)
50 | --Call level -3
51 | (settrace.py:14): hanoi
52 | + 14 def hanoi(n,a,b,c):
53 | (settrace.py:15): hanoi
54 | + 15 if n-1 > 0:
55 | (settrace.py:17): hanoi
56 | + 17 print "Move disk %s to %s" % (a, b)
57 | Move disk b to c
58 | (settrace.py:18): hanoi
59 | + 18 if n-1 > 0:
60 | (settrace.py:18): hanoi
61 | + 18 if n-1 > 0:
62 | (settrace.py:19): hanoi
63 | + 19 hanoi(n-1, c, b, a)
64 | (settrace.py:17): hanoi
65 | + 17 print "Move disk %s to %s" % (a, b)
66 | Move disk a to b
67 | (settrace.py:18): hanoi
68 | + 18 if n-1 > 0:
69 | (settrace.py:19): hanoi
70 | + 19 hanoi(n-1, c, b, a)
71 | --Call level -4
72 | (settrace.py:14): hanoi
73 | + 14 def hanoi(n,a,b,c):
74 | (settrace.py:15): hanoi
75 | + 15 if n-1 > 0:
76 | (settrace.py:16): hanoi
77 | + 16 hanoi(n-1, a, c, b)
78 | --Call level -3
79 | (settrace.py:14): hanoi
80 | + 14 def hanoi(n,a,b,c):
81 | (settrace.py:15): hanoi
82 | + 15 if n-1 > 0:
83 | (settrace.py:17): hanoi
84 | + 17 print "Move disk %s to %s" % (a, b)
85 | Move disk c to a
86 | (settrace.py:18): hanoi
87 | + 18 if n-1 > 0:
88 | (settrace.py:18): hanoi
89 | + 18 if n-1 > 0:
90 | (settrace.py:17): hanoi
91 | + 17 print "Move disk %s to %s" % (a, b)
92 | Move disk c to b
93 | (settrace.py:18): hanoi
94 | + 18 if n-1 > 0:
95 | (settrace.py:19): hanoi
96 | + 19 hanoi(n-1, c, b, a)
97 | --Call level -3
98 | (settrace.py:14): hanoi
99 | + 14 def hanoi(n,a,b,c):
100 | (settrace.py:15): hanoi
101 | + 15 if n-1 > 0:
102 | (settrace.py:17): hanoi
103 | + 17 print "Move disk %s to %s" % (a, b)
104 | Move disk a to b
105 | (settrace.py:18): hanoi
106 | + 18 if n-1 > 0:
107 | (settrace.py:18): hanoi
108 | + 18 if n-1 > 0:
109 | (settrace.py:19): hanoi
110 | + 19 hanoi(n-1, c, b, a)
111 | (settrace.py:19): hanoi
112 | + 19 hanoi(n-1, c, b, a)
113 | (settrace.py:51):
114 | + 51 hanoi(n, "a", "b", "c")
115 |
--------------------------------------------------------------------------------
/test/data/dbgcall-2.5.right:
--------------------------------------------------------------------------------
1 | (/src/external-vcs/pydb/test/dbgcall.py:17): \n " : '>')
65 | . " \n");
68 | $oddrow = !$oddrow;
69 | }
70 | $data .= "$link$name \n"
66 | . " \ \n"
67 | . " $synopsis