Prior has been written in the window Python script, accustomed to eclipse commissioning editor, sudden change to the linux environment, little suited. . .
There are built-in python pdb library, you can achieve a simple debugging functions, the basic commands and gdb similar, but the function does not have gdb so powerful, pdb primarily supports multi-breakpoint setting (can set conditions), code-level single-step debugging, viewing stack information, the code view, post-mortem debugging,
For more information see: http://docs.python.org/2/library/pdb.html
Debugging with pdb There are many ways Optional:
1. command line to start the target program, coupled with the -m parameter, then this call myscript.py breakpoint is executed before the first line of the program
python -m pdb myscript.py
2. In the Python interactive environment to enable debugging
>>> Import pdb
>>> Import mymodule
>>> pdb.run ( 'mymodule.test ()')
3. The more common, a program is inserted in the middle of the program, with respect to the breakpoint in general marked inside the IDE Debug then start,
- if __name__ == "__main__":
- a = 1
- import pdb
- pdb.set_trace()
- b = 2
- c = a + b
- print (c)
After running the script, to the pdb.set_trace () that would settle down, you can see the Debug prompt (Pdb) a
Some common commands:
h (elp) [comman] # print instructions and help information available
r (eturn) # Run the code until the next breakpoint or current function returns
b (reak) [[filename:] lineno | function [, condition]] # line or a specified file to set a breakpoint function body
l (ist) [first [, last]] # Specifies an snippet
n (ext) # the next line
s (tep) # the next line, when the process proceeds as a function of the function body
p # print a variable
a (rgs) # parameters of the current print function
w (here) # print stack information
d (own) # moved lower layer stack
u (p) # move to an upper layer stack
j (ump) # jump to the specified line
continue / c # proceed
disable [bpnumber [bpnumber]] # fail breakpoint
enable [bpnumber [bpnumber]] # Enable Breakpoint
cl (ear) [filename: lineno | bpnumber [bpnumber]] # delete breakpoint
q (uit) / exit # abort debugging and exit
Breakpoint Related command:
set a breakpoint: (Pdb) b 8 # Set breakpoint on line 8 (b ie initials break of) the file
shows all breakpoints: (Pdb) b #b command, no arguments, show all breakpoints
deleting breakpoints: (Pdb) cl 2 # delete the first two breakpoints (initials clear of)
Step Over: (Pdb) n # single step, next to the first letter of
Step Into: (Pdb) s #step initials
Setp Return: (Pdb) r #return initials
Resume: (Pdb) c #continue first letters
run to line: (Pdb) j 10 # to 10 lines to run, jump initials
(Pdb) p param # param view the current value of the variable
(Pdb) l # view to run the code somewhere
(Pdb) a # All the stack variables
(Pdb) h # help, help first letter
(Pdb) q # quit, quit the first letter of