PDB
Refer to: https://docs.python.org/3/library/pdb.html
a python module
- so can be executed by
python -m pdb <source_file>
Usage
- python -m pdb <source_file>
- actually call
Pdb()._runscript(source_file)
- actually call
- insert by code:
import pdb pdb.set_trace()
- debug a module/function
[willchen@fdev060101 decorator]$ ipython Python 2.7.12 |Anaconda 4.1.1 (64-bit)| (default, Jul 2 2016, 17:42:40) Type "copyright", "credits" or "license" for more information. IPython 4.2.0 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]: import test In [2]: import pdb In [4]: pdb.run('test.my_print("abc")') > <string>(1)<module>()->None (Pdb) s --Call-- > /n/home/dev/willchen/study/py/decorator/test.py(4)my_print() -> def my_print(msg): (Pdb) p msg 'abc' (Pdb) n > /n/home/dev/willchen/study/py/decorator/test.py(5)my_print() -> for i in range(3): (Pdb) n > /n/home/dev/willchen/study/py/decorator/test.py(6)my_print() -> print(msg)
some commands
-
n(ext)
-
s(tep)
-
c(ont(inue)): continue
-
b(reak) [([filename:]lineno | function) [, condition]]
With a lineno argument, set a break there in the current file. With a function argument, set a break at the first executable statement within that function. The line number may be prefixed with a filename and a colon, to specify a