Python debugging in Linux
Python has its own pdb library for simple debugging. The basic commands are similar to gdb, but the functions are not as powerful as gdb. pdb mainly supports multi-breakpoint settings (conditional settings ), code-level single-step debugging, viewing stack information, code viewing, post-mortem debugging,
For more information, see: http://docs.python.org/2/library/pdb.html
There are multiple ways to debug with pdb:
1. Run the command line to start the target program and add the-m parameter. In this way, if myscript. py is called, the breakpoint is before the execution of the program.
Python-m pdb myscript. py
2. Enable debugging in the Python interaction environment
>>> Import pdb
>>> Import mymodule
>>> Pdb. run ('mymodule. test ()')
3. It is commonly used to insert a program in the middle of the program, as opposed to hitting a breakpoint in the general IDE and then start debug,
[Python] view plaincopy print?
- If _ name __= = "_ main __":
- A = 1
- Importpdb
- Pdb. set_trace ()
- B = 2
- C = a + B
- Print (c)
After the script runs properly, it will be fixed at pdb. set_trace (), and the debugging prompt (Pdb) will be displayed.
Some Common commands:
H (elp) [comman] # print available commands and help information
R (eturn) # Run the code until the next breakpoint or the current function returns
B (reak) [[filename:] lineno | function [, condition] # specify a row or function body of the file to set breakpoints
L (ist) [first [, last] # view a specified code segment
N (ext) # execute the next line
S (tep) # execute the next line. If it is a function, it enters the function body.
P # print a variable
A (rgs) # print the parameters of the current function
W (here) # print stack information
D (own) # Move to the lower stack
U (p) # Move to the upper stack
J (ump) # Jump to the specified row
Continue/c # continue execution
Disable [bpnumber [bpnumber] # failure breakpoint
Enable [bpnumber [bpnumber] # enable breakpoint
Cl (ear) [filename: lineno | bpnumber [bpnumber] # delete a breakpoint
Q (uit)/exit # Stop debugging and exit