代碼如下:
import pdb
def pdb_test(arg):
for i in range(arg):
print(i)
return arg
pdb.run("pdb_test(3)")
b 函數(shù)名、行號:
打斷點(diǎn),b可以查詢所有的斷點(diǎn)。
代碼如下:
(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:
運(yùn)行程序,直到遇到斷點(diǎn)。
代碼如下:
(Pdb) c
> c:/users/plpcc/desktop/pdbtest.py(4)pdb_test()
-> for i in range(arg):
l:
查看斷點(diǎn)周圍的代碼
代碼如下:
(Pdb) l
import pdb
B def pdb_test(arg):
-> for i in range(arg):
print(i)
return arg
pdb.run("pdb_test(3)")
a:
查看參數(shù)
代碼如下:
(Pdb) a
arg = 3
s, n:
單步運(yùn)行,區(qū)別s會進(jìn)入路徑中的函數(shù),n不會進(jìn)入
p:
查看表達(dá)式的值
代碼如下:
(Pdb) p i
condition:
條件斷點(diǎn),只有條件為true斷點(diǎn)才命中
代碼如下:
> 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時才觸發(fā)斷點(diǎn)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直接打印未斷住
> c:/users/plpcc/desktop/pdbtest.py(5)pdb_test()
-> print(i) //觸發(fā)斷點(diǎn),i==1
(Pdb) p i
bt:
查看調(diào)用堆棧
代碼如下:
(Pdb) bt
c:/python33/lib/bdb.py(405)run()
-> exec(cmd, globals, locals)
<string>(1)<module>()
新聞熱點(diǎn)
疑難解答
圖片精選