There are several ways to debug with PDB:
1. Command line to start the target program, plus the-m parameter, so that the call myscript.py Word breakpoint is the execution of the first line of the program
PYTHON-M PDB myscript.py
2 Insert a program in the middle of the program, relative to the general IDE inside the breakpoint and then start Debug, but this way is hardcode
Import PDB
Pdb.set_trace ()
b = 2
c = A + b
Print (c)
Then run the script normally, to Pdb.set_trace () then it will be fixed and you will see the debug prompt (Pdb).
Common Debug Commands
H (ELP), the commands available for the current version of the PDB are printed, and if you want to query a command, you can enter H [command], for example: "H L"-View the List command
L (IST) to list the blocks of code that are currently going to be run
B (reak), set breakpoints, such as "B 77″, that is, in the current script 77 lines of the breakpoint, you can also enter the function name as a parameter, the breakpoint will hit the specific function entrance, if only knock B, will show all the existing breakpoints
(PDB) B 504
Breakpoint 4 at/home/jchen/regression/regressionlogcmp.py:504
condition Bpnumber [condition], set a conditional breakpoint, the following statement is the 4th breakpoint plus the condition "a==3"
(PDB) condition 4 a==3
(Pdb) b
Num Type Disp Enb Where
4 Breakpoint Keep Yes at/home/jchen/regression/regressionlogcmp.py:504
stop only if a==3
cl (EAR), if followed by a parameter, clears the specified breakpoint (I never succeeded on Python2.4!!!). ), or clear all breakpoints without a parameter
(PDB) CL
Clear all breaks? y
disable/enable, disabling/activating breakpoints
(Pdb) Disable 3
(Pdb) b
Num Type Disp Enb Where
3 Breakpoint Keep No at/home/jchen/regression/regressionlogcmp.py:505
N (EXT), let the program run the next line, if the current statement has a function call, n is not entered in the called function body
s (TEP), similar to n, but if there is currently a function call, then s will enter the body of the called function
C (ont (inue)) to allow the program to function until a breakpoint is encountered
J (UMP), let the program jump to the specified number of rows
(Pdb) J 497
>/home/jchen/regression/regressionlogcmp.py (497) comparelog ()
pdb.set_trace ()
A (RGS), prints the parameters of the current function
(Pdb) a
_logger =
_base =./base/mrm-8137.log
_new =./new/mrm-8137.log
_caseid = 5550001
_tostepnum = Ten
_cmpmap = {' _bcmpbinarylog ': ' true ', ' _bcmplog ': ' true ', ' _bcmpresp ': ' True '}
p, one of the most useful commands to print a variable
(PDB) p _new
u './new/mrm-8137.log '
! , the exclamation mark followed by the statement, you can directly change a variable
Q (uit), exit Debug
find it interesting to debug a program at the command line, record it and share it.
W, Print a stack trace, with the most recent frame at the bottom. An arrow indicates the ' Current frame ', which determines the context of the most commands. ' BT ' is a alias for this command.
D, Move the current frame one level down in the stack trace
(to a newer frame).
u, Move the current frame one level up in the stack trace
(to an older frame).
using the U and D commands, we can switch between stack frames to get information about their contextual variables. W can display some of the most recent stack frame information.
Debugging a Python program with the PDB library