Copy Code code as follows:
Import PDB
def pdb_test (ARG):
For I in range (ARG):
Print (i)
return arg
Pdb.run ("Pdb_test (3)")
b function name, line number:
Break point, B can query all breakpoints.
Copy Code code as follows:
(Pdb) B pdb_test
Breakpoint 1 at C:\users\plpcc\desktop\pdbtest.py:3
(PDB) b
Num Type Disp Enb Where
Breakpoint Keep Yes at C:\users\plpcc\desktop\pdbtest.py:3
C:
Run the program until a breakpoint is encountered.
Copy Code code as follows:
(PDB) C
> c:\users\plpcc\desktop\pdbtest.py (4) pdb_test ()
-> for I in Range (ARG):
L
To view the code around a breakpoint
Copy Code code as follows:
(PDB) L
Import PDB
B def pdb_test (ARG):
-> for I in Range (ARG):
Print (i)
return arg
Pdb.run ("Pdb_test (3)")
A:
View parameters
Copy Code code as follows:
Single step run, the difference s will go into the path of the function, n will not enter
P:
To view the value of an expression
Copy Code code as follows:
Conditional breakpoint, only if the condition is true a breakpoint hits
Copy Code code as follows:
> c:\users\plpcc\desktop\pdbtest.py (5) pdb_test ()
-> Print (i)
(PDB) L
Import PDB
def pdb_test (ARG):
For I in range (ARG):
b-> Print (i)
return arg
Pdb.run ("Pdb_test (3)")
[EOF]
(PDB) b
Num Type Disp Enb Where
Breakpoint Keep Yes at C:\users\plpcc\desktop\pdbtest.py:5
(Pdb) Condition 2 i==1//i==1 trigger Breakpoint 2
New condition set for breakpoint 2.
(PDB) b
Num Type Disp Enb Where
Breakpoint Keep Yes at C:\users\plpcc\desktop\pdbtest.py:5
Stop only if i==1
(PDB) C
I==0 Direct print is not broken
> c:\users\plpcc\desktop\pdbtest.py (5) pdb_test ()
-> print (i)//trigger breakpoint, I==1
(PDB) P I
Bt:
Viewing call stacks
Copy Code code as follows:
(PDB) bt
c:\python33\lib\bdb.py (405) Run ()
-> exec (cmd, globals, locals)
<string> (1) <module> ()
> c:\users\plpcc\desktop\pdbtest.py (5) pdb_test ()
-> Print (i)
R:
Perform to function return
Copy Code code as follows:
(PDB) R
--return--
> c:\users\plpcc\desktop\pdbtest.py (6) pdb_test ()->3//Code position, function return value->3
-> return arg//Code position statement
(PDB) L
Import PDB
def pdb_test (ARG):
For I in range (ARG):
Print (i)
-> return arg
Pdb.run ("Pdb_test (3)")
Embed a breakpoint by Pdb.set_trace () at the specified location in your code, usually by debugging a switch to control
Copy Code code as follows:
Import PDB
__debug__ = True
def pdb_test (ARG):
if True = = __debug__:
Pdb.set_trace ()
For I in range (ARG):
Print (i)
return arg
Pdb_test (3)
After running in Pdb.set_trace () position is broken, when __debug__ = False, the code runs normally
Copy Code code as follows:
> c:\users\plpcc\desktop\pdbtest.py (8) pdb_test ()
-> for I in Range (ARG):
(PDB) L
__debug__ = True
def pdb_test (ARG):
if True = = __debug__:
Pdb.set_trace ()
-> for I in Range (ARG):
Print (i)
return arg
Pdb_test (3)
[EOF]
After debugging via PDB.PM (), you can track the final heap information of the exception program:
Copy Code code as follows:
Traceback (most recent call last):
File "C:\Users\plpcc\Desktop\pdbTest.py", line, in <module>
Pdb_test (3)
File "C:\Users\plpcc\Desktop\pdbTest.py", line ten, in Pdb_test
1/0
Zerodivisionerror:division by Zero
>>> Import PDB
>>> pdb.pm ()
> c:\users\plpcc\desktop\pdbtest.py (pdb_test) ()
-> 1/0
(PDB) L
def pdb_test (ARG):
if True = = __debug__:
Pdb.set_trace ()
For I in range (ARG):
Print (i)
-> 1/0
return arg
Pdb_test (3)