# encoding: utf-8 # # Copyright (c) 2010 Doug Hellmann. All rights reserved. # class MyObj( object ): def __init__(self, num_loops): self.count = num_loops def go(self): for i in range(self.count): print i return if __name__ == '__main__' : MyObj(5).go() * This source code was highlighted with Source Code Highlighter .
# encoding: utf-8 # # Copyright (c) 2010 Doug Hellmann. All rights reserved. # class MyObj( object ): def __init__(self, num_loops): self.count = num_loops def go(self): for i in range(self.count): print i return if __name__ == '__main__' : MyObj(5).go() * This source code was highlighted with Source Code Highlighter .
# encoding: utf-8 # # Copyright (c) 2010 Doug Hellmann. All rights reserved. # class MyObj( object ): def __init__(self, num_loops): self.count = num_loops def go(self): for i in range(self.count): print i return if __name__ == '__main__' : MyObj(5).go() * This source code was highlighted with Source Code Highlighter .
# encoding: utf-8 # # Copyright (c) 2010 Doug Hellmann. All rights reserved. # class MyObj( object ): def __init__(self, num_loops): self.count = num_loops def go(self): for i in range(self.count): print i return if __name__ == '__main__' : MyObj(5).go() * This source code was highlighted with Source Code Highlighter .
# encoding: utf-8 # # Copyright (c) 2010 Doug Hellmann. All rights reserved. # class MyObj( object ): def __init__(self, num_loops): self.count = num_loops def go(self): for i in range(self.count): print i return if __name__ == '__main__' : MyObj(5).go() * This source code was highlighted with Source Code Highlighter .
# encoding: utf-8 # # Copyright (c) 2010 Doug Hellmann. All rights reserved. # class MyObj( object ): def __init__(self, num_loops): self.count = num_loops def go(self): for i in range(self.count): print i return if __name__ == '__main__' : MyObj(5).go() * This source code was highlighted with Source Code Highlighter .
# encoding: utf-8 # # Copyright (c) 2010 Doug Hellmann. All rights reserved. # class MyObj( object ): def __init__(self, num_loops): self.count = num_loops def go(self): for i in range(self.count): print i return if __name__ == '__main__' : MyObj(5).go() * This source code was highlighted with Source Code Highlighter .
# encoding: utf-8 # # Copyright (c) 2010 Doug Hellmann. All rights reserved. # class MyObj( object ): def __init__(self, num_loops): self.count = num_loops def go(self): for i in range(self.count): print i return if __name__ == '__main__' : MyObj(5).go() * This source code was highlighted with Source Code Highlighter .
# encoding: utf-8 # # Copyright (c) 2010 Doug Hellmann. All rights reserved. # class MyObj( object ): def __init__(self, num_loops): self.count = num_loops def go(self): for i in range(self.count): print i return if __name__ == '__main__' : MyObj(5).go() * This source code was highlighted with Source Code Highlighter .
# encoding: utf-8 # # Copyright (c) 2010 Doug Hellmann. All rights reserved. # class MyObj( object ): def __init__(self, num_loops): self.count = num_loops def go(self): for i in range(self.count): print i return if __name__ == '__main__' : MyObj(5).go() * This source code was highlighted with Source Code Highlighter .
# encoding: utf-8 # # Copyright (c) 2010 Doug Hellmann. All rights reserved. # class MyObj( object ): def __init__(self, num_loops): self.count = num_loops def go(self): for i in range(self.count): print i return if __name__ == '__main__' : MyObj(5).go() * This source code was highlighted with Source Code Highlighter .
# encoding: utf-8 # # Copyright (c) 2010 Doug Hellmann. All rights reserved. # class MyObj( object ): def __init__(self, num_loops): self.count = num_loops def go(self): for i in range(self.count): print i return if __name__ == '__main__' : MyObj(5).go() * This source code was highlighted with Source Code Highlighter .
# encoding: utf-8 # # Copyright (c) 2010 Doug Hellmann. All rights reserved. # class MyObj( object ): def __init__(self, num_loops): self.count = num_loops def go(self): for i in range(self.count): print i return if __name__ == '__main__' : MyObj(5).go() * This source code was highlighted with Source Code Highlighter .
# encoding: utf-8 # # Copyright (c) 2010 Doug Hellmann. All rights reserved. # class MyObj( object ): def __init__(self, num_loops): self.count = num_loops def go(self): for i in range(self.count): print i return if __name__ == '__main__' : MyObj(5).go() * This source code was highlighted with Source Code Highlighter .
# encoding: utf-8 # # Copyright (c) 2010 Doug Hellmann. All rights reserved. # class MyObj( object ): def __init__(self, num_loops): self.count = num_loops def go(self): for i in range(self.count): print i return if __name__ == '__main__' : MyObj(5).go() * This source code was highlighted with Source Code Highlighter .
$ python -m pdb pdb_script.py
> .../pdb_script.py(7)<module>()
-> class MyObj(object):
(Pdb)
注:
通常、 pdbには、ファイルパスの出力時に各モジュールへのフルパスが含まれます。 例を簡潔にするために、デバッガーの出力では、これらのパスは...
$ python
Python 2.7 (r27:82508, Jul 3 2010, 21:12:11)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pdb_script
>>> import pdb
>>> pdb.run('pdb_script.MyObj(5).go()')
> <string>(1)<module>()
(Pdb)
- #!/ usr / bin / env python
- #エンコード:utf-8
- #
- #Copyright(c)2010 Doug Hellmann。 無断複写・転載を禁じます。
- #
- インポートpdb
- クラス MyObj( オブジェクト ):
- def __init __(self、num_loops):
- self.count = num_loops
- def go(self):
- 範囲内のi(self.count):
- pdb.set_trace()
- 印刷する
- 帰る
- __name__ == '__main__'の場合 :
- MyObj(5).go()
$ python ./pdb_set_trace.py
> .../pdb_set_trace.py(17)go()
-> print i
(Pdb)
- #!/ usr / bin / env python
- #エンコード:utf-8
- #
- #Copyright(c)2010 Doug Hellmann。 すべての権利を留保します。
- #
- クラス MyObj( オブジェクト ):
- def __init __(self、num_loops):
- self.count = num_loops
- def go(self):
- 範囲内のi(self.num_loops):
- 印刷する
- 帰る
$ python
Python 2.7 (r27:82508, Jul 3 2010, 21:12:11)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from pdb_post_mortem import MyObj
>>> MyObj(5).go()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pdb_post_mortem.py", line 13, in go
for i in range(self.num_loops):
AttributeError: 'MyObj' object has no attribute 'num_loops'
>>> import pdb
>>> pdb.pm()
> .../pdb_post_mortem.py(13)go()
-> for i in range(self.num_loops):
(Pdb)
$ python pdb_set_trace.py
> .../pdb_set_trace.py(17)go()
-> print i
(Pdb) where
.../pdb_set_trace.py(21)<module>()
-> MyObj(5).go()
> .../pdb_set_trace.py(17)go()
-> print i
(Pdb) list
12 self.count = num_loops
13
14 def go(self):
15 for i in range(self.count):
16 pdb.set_trace()
17 -> print i
18 return
19
20 if __name__ == '__main__':
21 MyObj(5).go()
[EOF]
(Pdb)
(Pdb) list 14
9 class MyObj(object):
10
11 def __init__(self, num_loops):
12 self.count = num_loops
13
14 def go(self):
15 for i in range(self.count):
16 pdb.set_trace()
17 -> print i
18 return
19
(Pdb) list 5, 19
5 #
6
7 import pdb
8
9 class MyObj(object):
10
11 def __init__(self, num_loops):
12 self.count = num_loops
13
14 def go(self):
15 for i in range(self.count):
16 pdb.set_trace()
17 -> print i
18 return
19
(Pdb) up
> .../pdb_set_trace.py(21)<module>()
-> MyObj(5).go()
(Pdb) down
> .../pdb_set_trace.py(17)go()
-> print i
- #!/ usr / bin / env python
- #エンコード:utf-8
- #
- #Copyright(c)2010 Doug Hellmann。 無断複写・転載を禁じます。
- #
- インポートpdb
- def recursive_function(n = 5、出力= '印刷される' ):
- n> 0の場合 :
- 再帰関数(n-1)
- その他 :
- pdb.set_trace()
- 印刷出力
- 帰る
- __name__ == '__main__'の場合 :
- recursive_function()
$ python pdb_function_arguments.py
> .../pdb_function_arguments.py(14)recursive_function()
-> return
(Pdb) where
.../pdb_function_arguments.py(17)<module>()
-> recursive_function()
.../pdb_function_arguments.py(11)recursive_function()
-> recursive_function(n-1)
.../pdb_function_arguments.py(11)recursive_function()
-> recursive_function(n-1)
.../pdb_function_arguments.py(11)recursive_function()
-> recursive_function(n-1)
.../pdb_function_arguments.py(11)recursive_function()
-> recursive_function(n-1)
.../pdb_function_arguments.py(11)recursive_function()
-> recursive_function(n-1)
> .../pdb_function_arguments.py(14)recursive_function()
-> return
(Pdb) args
n = 0
output = to be printed
(Pdb) up
> .../pdb_function_arguments.py(11)recursive_function()
-> recursive_function(n-1)
(Pdb) args
n = 1
output = to be printed
(Pdb)
(Pdb) pn
1
(Pdb) print n
1
$ python pdb_function_arguments.py
> .../pdb_function_arguments.py(14)recursive_function()
-> print output
(Pdb) !output
'to be printed'
(Pdb) !output='changed value'
(Pdb) continue
changed value
- #!/ usr / bin / env python
- #エンコード:utf-8
- #
- #Copyright(c)2010 Doug Hellmann。 無断複写・転載を禁じます。
- #
- インポートpdb
- f として open( 'lorem.txt' 、 'rt' ) を使用
- lines = f.readlines()
- pdb.set_trace()
$ python pdb_pp.py
--Return--
> .../pdb_pp.py(12)<module>()->None
-> pdb.set_trace()
(Pdb) p lines
['Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec\n', 'egestas, enim
et consectetuer ullamcorper, lectus ligula rutrum leo, a\n', 'elementum elit tortor
eu quam.\n']
(Pdb) pp lines
['Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec\n',
'egestas, enim et consectetuer ullamcorper, lectus ligula rutrum leo, a\n',
'elementum elit tortor eu quam.\n']
(Pdb)
- #!/ usr / bin / env python
- #エンコード:utf-8
- #
- #Copyright(c)2010 Doug Hellmann。 すべての権利を留保します。
- #
- インポートpdb
- def f(n):
- 範囲(n)のiの場合:
- j = i * n
- 印刷i、j
- 帰る
- __name__ == '__main__'の場合 :
- pdb.set_trace()
- f(5)
$ python pdb_step.py
> /Users/dhellmann/Documents/PyMOTW/src.pdb/PyMOTW/pdb/pdb_step.py(17)<module>()
-> f(5)
(Pdb) step
--Call--
> .../pdb_step.py(9)f()
-> def f(n):
(Pdb) step
> .../pdb_step.py(10)f()
-> for i in range(n):
(Pdb) step
> /Users/dhellmann/Documents/PyMOTW/src.pdb/PyMOTW/pdb/pdb_step.py(11)f()
-> j = i * n
(Pdb) pi
0
(Pdb) step
> /Users/dhellmann/Documents/PyMOTW/src.pdb/PyMOTW/pdb/pdb_step.py(12)f()
-> print i, j
(Pdb) pj
0
(Pdb)
- #!/ usr / bin / env python
- #エンコード:utf-8
- #
- #Copyright(c)2010 Doug Hellmann。 無断複写・転載を禁じます。
- #
- インポートpdb
- def calc(i、n):
- j = i * n
- リターン j
- def f(n):
- 範囲(n)のiの場合:
- j =計算(i、n)
- 印刷i、j
- 帰る
- __name__ == '__main__'の場合 :
- pdb.set_trace()
- f(5)
$ python pdb_next.py
> .../pdb_next.py(21)<module>()
-> f(5)
(Pdb) step
--Call--
> .../pdb_next.py(13)f()
-> def f(n):
(Pdb) step
> .../pdb_next.py(14)f()
-> for i in range(n):
(Pdb) step
> .../pdb_next.py(15)f()
-> j = calc(i, n)
(Pdb) step
--Call--
> .../pdb_next.py(9)calc()
-> def calc(i, n):
(Pdb) step
> .../pdb_next.py(10)calc()
-> j = i * n
(Pdb) step
> .../pdb_next.py(11)calc()
-> return j
(Pdb) step
--Return--
> .../pdb_next.py(11)calc()->0
-> return j
(Pdb) step
> .../pdb_next.py(16)f()
-> print i, j
(Pdb) step
0 0
> .../pdb_next.py(14)f()
-> for i in range(n):
(Pdb) step
> .../pdb_next.py(15)f()
-> j = calc(i, n)
(Pdb) next
> .../pdb_next.py(16)f()
-> print i, j
(Pdb)
$ python pdb_next.py
> .../pdb_next.py(21)<module>()
-> f(5)
(Pdb) step
--Call--
> .../pdb_next.py(13)f()
-> def f(n):
(Pdb) step
> .../pdb_next.py(14)f()
-> for i in range(n):
(Pdb) step
> .../pdb_next.py(15)f()
-> j = calc(i, n)
(Pdb) next
> .../pdb_next.py(16)f()
-> print i, j
(Pdb) until
0 0
1 5
2 10
3 15
4 20
> .../pdb_next.py(17)f()
-> return
(Pdb)
$ python pdb_next.py
> .../pdb_next.py(21)<module>()
-> f(5)
(Pdb) step
--Call--
> .../pdb_next.py(13)f()
-> def f(n):
(Pdb) step
> .../pdb_next.py(14)f()
-> for i in range(n):
(Pdb) return
0 0
1 5
2 10
3 15
4 20
--Return--
> .../pdb_next.py(17)f()->None
-> return
(Pdb)
- #!/ usr / bin / env python
- #エンコード:utf-8
- #
- #Copyright(c)2010 Doug Hellmann。 無断複写・転載を禁じます。
- #
- def calc(i、n):
- j = i * n
- 印刷'j =' 、j
- j> 0の場合 :
- 「ポジティブ!」
- リターン j
- def f(n):
- 範囲(n)のiの場合:
- print 'i =' 、i
- j =計算(i、n)
- 帰る
- __name__ == '__main__'の場合 :
- f(5)
$ python -m pdb pdb_break.py
> .../pdb_break.py(7)<module>()
-> def calc(i, n):
(Pdb) break 11
Breakpoint 1 at .../pdb_break.py:11
(Pdb) continue
i = 0
j = 0
i = 1
j = 5
> .../pdb_break.py(11)calc()
-> print 'Positive!'
(Pdb)
$ python -m pdb pdb_break.py
> .../pdb_break.py(7)<module>()
-> def calc(i, n):
(Pdb) break calc
Breakpoint 1 at .../pdb_break.py:7
(Pdb) continue
i = 0
> .../pdb_break.py(8)calc()
-> j = i * n
(Pdb) where
.../pdb_break.py(21)<module>()
-> f(5)
.../pdb_break.py(17)f()
-> j = calc(i, n)
> .../pdb_break.py(8)calc()
-> j = i * n
(Pdb)
- #!/ usr / bin / env python
- #エンコード:utf-8
- #
- #Copyright(c)2010 Doug Hellmann。 無断複写・転載を禁じます。
- #
- pdb_break import f から
- f(5)
$ python -m pdb pdb_break_remote.py
> .../pdb_break_remote.py(7)<module>()
-> from pdb_break import f
(Pdb) break pdb_break.py:11
Breakpoint 1 at .../pdb_break.py:11
(Pdb) continue
i = 0
j = 0
i = 1
j = 5
> .../pdb_break.py(11)calc()
-> print 'Positive!'
(Pdb)
$ python -m pdb pdb_break.py
> .../pdb_break.py(7)<module>()
-> def calc(i, n):
(Pdb) break 11
Breakpoint 1 at .../pdb_break.py:11
(Pdb) break
Num Type Disp Enb Where
1 breakpoint keep yes at .../pdb_break.py:11
(Pdb) continue
i = 0
j = 0
i = 1
j = 5
> .../pdb/pdb_break.py(11)calc()
-> print 'Positive!'
(Pdb) continue
Positive!
i = 2
j = 10
> .../pdb_break.py(11)calc()
-> print 'Positive!'
(Pdb) break
Num Type Disp Enb Where
1 breakpoint keep yes at .../pdb_break.py:11
breakpoint already hit 2 times
(Pdb)
$ python -m pdb pdb_break.py
> .../pdb_break.py(7)<module>()
-> def calc(i, n):
(Pdb) break calc
Breakpoint 1 at .../pdb_break.py:7
(Pdb) break 11
Breakpoint 2 at .../pdb_break.py:11
(Pdb) break
Num Type Disp Enb Where
1 breakpoint keep yes at .../pdb_break.py:7
2 breakpoint keep yes at .../pdb_break.py:11
(Pdb) disable 1
(Pdb) break
Num Type Disp Enb Where
1 breakpoint keep no at .../pdb_break.py:7
2 breakpoint keep yes at .../pdb_break.py:11
(Pdb) continue
i = 0
j = 0
i = 1
j = 5
> .../pdb_break.py(11)calc()
-> print 'Positive!'
(Pdb)
$ python -m pdb pdb_break.py
> .../pdb_break.py(7)<module>()
-> def calc(i, n):
(Pdb) break calc
Breakpoint 1 at .../pdb_break.py:7
(Pdb) break 16
Breakpoint 2 at .../pdb_break.py:16
(Pdb) disable 1
(Pdb) continue
> .../pdb_break.py(16)f()
-> print 'i =', i
(Pdb) list
11 print 'Positive!'
12 return j
13
14 def f(n):
15 for i in range(n):
16 B-> print 'i =', i
17 j = calc(i, n)
18 return
19
20 if __name__ == '__main__':
21 f(5)
(Pdb) continue
i = 0
j = 0
> .../pdb_break.py(16)f()
-> print 'i =', i
(Pdb) list
11 print 'Positive!'
12 return j
13
14 def f(n):
15 for i in range(n):
16 B-> print 'i =', i
17 j = calc(i, n)
18 return
19
20 if __name__ == '__main__':
21 f(5)
(Pdb) pi
1
(Pdb) enable 1
(Pdb) continue
i = 1
> .../pdb_break.py(8)calc()
-> j = i * n
(Pdb) list
3 #
4 # Copyright (c) 2010 Doug Hellmann. All rights reserved.
5 #
6
7 B def calc(i, n):
8 -> j = i * n
9 print 'j =', j
10 if j > 0:
11 print 'Positive!'
12 return j
13
(Pdb)
$ python -m pdb pdb_break.py
> .../pdb_break.py(7)<module>()
-> def calc(i, n):
(Pdb) break calc
Breakpoint 1 at .../pdb_break.py:7
(Pdb) break 11
Breakpoint 2 at .../pdb_break.py:11
(Pdb) break 16
Breakpoint 3 at .../pdb_break.py:16
(Pdb) break
Num Type Disp Enb Where
1 breakpoint keep yes at .../pdb_break.py:7
2 breakpoint keep yes at .../pdb_break.py:11
3 breakpoint keep yes at .../pdb_break.py:16
(Pdb) clear 2
Deleted breakpoint 2
(Pdb) break
Num Type Disp Enb Where
1 breakpoint keep yes at .../pdb_break.py:7
3 breakpoint keep yes at .../pdb_break.py:16
(Pdb)
$ python -m pdb pdb_break.py
> .../pdb_break.py(7)<module>()
-> def calc(i, n):
(Pdb) tbreak 11
Breakpoint 1 at .../pdb_break.py:11
(Pdb) continue
i = 0
j = 0
i = 1
j = 5
Deleted breakpoint 1
> .../pdb_break.py(11)calc()
-> print 'Positive!'
(Pdb) break
(Pdb) continue
Positive!
i = 2
j = 10
Positive!
i = 3
j = 15
Positive!
i = 4
j = 20
Positive!
The program finished and will be restarted
> .../pdb_break.py(7)<module>()
-> def calc(i, n):
(Pdb)
$ python -m pdb pdb_break.py
> .../pdb_break.py(7)<module>()
-> def calc(i, n):
(Pdb) break 9, j>0
Breakpoint 1 at .../pdb_break.py:9
(Pdb) break
Num Type Disp Enb Where
1 breakpoint keep yes at .../pdb_break.py:9
stop only if j>0
(Pdb) continue
i = 0
j = 0
i = 1
> .../pdb_break.py(9)calc()
-> print 'j =', j
(Pdb)
$ python -m pdb pdb_break.py
> .../pdb_break.py(7)<module>()
-> def calc(i, n):
(Pdb) break 9
Breakpoint 1 at .../pdb_break.py:9
(Pdb) break
Num Type Disp Enb Where
1 breakpoint keep yes at .../pdb_break.py:9
(Pdb) condition 1 j>0
(Pdb) break
Num Type Disp Enb Where
1 breakpoint keep yes at .../pdb_break.py:9
stop only if j>0
(Pdb)
$ python -m pdb pdb_break.py
> .../pdb_break.py(7)<module>()
-> def calc(i, n):
(Pdb) break 17
Breakpoint 1 at .../pdb_break.py:17
(Pdb) continue
i = 0
> .../pdb_break.py(17)f()
-> j = calc(i, n)
(Pdb) next
j = 0
> .../pdb_break.py(15)f()
-> for i in range(n):
(Pdb) ignore 1 2
Will ignore next 2 crossings of breakpoint 1.
(Pdb) break
Num Type Disp Enb Where
1 breakpoint keep yes at .../pdb_break.py:17
ignore next 2 hits
breakpoint already hit 1 time
(Pdb) continue
i = 1
j = 5
Positive!
i = 2
j = 10
Positive!
i = 3
> .../pdb_break.py(17)f()
-> j = calc(i, n)
(Pdb) break
Num Type Disp Enb Where
1 breakpoint keep yes at .../pdb_break.py:17
breakpoint already hit 4 times
$ python -m pdb pdb_break.py
> .../pdb_break.py(7)<module>()
-> def calc(i, n):
(Pdb) break 17
Breakpoint 1 at .../pdb_break.py:17
(Pdb) ignore 1 2
Will ignore next 2 crossings of breakpoint 1.
(Pdb) break
Num Type Disp Enb Where
1 breakpoint keep yes at .../pdb_break.py:17
ignore next 2 hits
(Pdb) ignore 1 0
Will stop next time breakpoint 1 is reached.
(Pdb) break
Num Type Disp Enb Where
1 breakpoint keep yes at .../pdb_break.py:17
$ python -m pdb pdb_break.py
> .../pdb_break.py(7)<module>()
-> def calc(i, n):
(Pdb) break 9
Breakpoint 1 at .../pdb_break.py:9
(Pdb) commands 1
(com) print 'debug i =', i
(com) print 'debug j =', j
(com) print 'debug n =', n
(com) end
(Pdb) continue
i = 0
debug i = 0
debug j = 0
debug n = 5
> .../pdb_break.py(9)calc()
-> print 'j =', j
(Pdb) continue
j = 0
i = 1
debug i = 1
debug j = 5
debug n = 5
> .../pdb_break.py(9)calc()
-> print 'j =', j
(Pdb)
- #!/ usr / bin / env python
- #エンコード:utf-8
- #
- #Copyright(c)2010 Doug Hellmann。 無断複写・転載を禁じます。
- #
- def f(n):
- 結果= []
- j = 0
- 範囲(n)のiの場合:
- j = i * n + j
- j + = n
- result.append(j)
- 結果を返す
- __name__ == '__main__'の場合 :
- プリントf(5)
$ python pdb_jump.py
[5, 15, 30, 50, 75]
$ python -m pdb pdb_jump.py
> .../pdb_jump.py(7)<module>()
-> def f(n):
(Pdb) break 12
Breakpoint 1 at .../pdb_jump.py:12
(Pdb) continue
> .../pdb_jump.py(12)f()
-> j += n
(Pdb) pj
0
(Pdb) step
> .../pdb_jump.py(13)f()
-> result.append(j)
(Pdb) pj
5
(Pdb) continue
> .../pdb_jump.py(12)f()
-> j += n
(Pdb) jump 13
> .../pdb_jump.py(13)f()
-> result.append(j)
(Pdb) pj
10
(Pdb) disable 1
(Pdb) continue
[5, 10, 25, 45, 70]
The program finished and will be restarted
> .../pdb_jump.py(7)<module>()
-> def f(n):
(Pdb)
$ python -m pdb pdb_jump.py
> .../pdb_jump.py(7)<module>()
-> def f(n):
(Pdb) break 13
Breakpoint 1 at .../pdb_jump.py:13
(Pdb) continue
> .../pdb_jump.py(13)f()
-> result.append(j)
(Pdb) pj
5
(Pdb) jump 12
> .../pdb_jump.py(12)f()
-> j += n
(Pdb) continue
> .../pdb_jump.py(13)f()
-> result.append(j)
(Pdb) pj
10
(Pdb) disable 1
(Pdb) continue
[10, 20, 35, 55, 80]
The program finished and will be restarted
> .../pdb_jump.py(7)<module>()
-> def f(n):
(Pdb)
- #!/ usr / bin / env python
- #エンコード:utf-8
- #
- #Copyright(c)2010 Doug Hellmann。 無断複写・転載を禁じます。
- #
- def f(n):
- n <0の場合 :
- ValueErrorを発生させます( 'Invalid n:%s' %n)
- 結果= []
- j = 0
- 範囲(n)のiの場合:
- j = i * n + j
- j + = n
- result.append(j)
- 結果を返す
- __name__ == '__main__'の場合 :
- 試してください :
- プリントf(5)
- 最後に :
- 印刷「常に印刷」
- 試してください :
- プリントf(-5)
- を除く:
- 「エラーが発生しました」を印刷
- その他 :
- 「エラーなし」を印刷
- 「最後のステートメント」を印刷
$ python -m pdb pdb_no_jump.py
> .../pdb_no_jump.py(7)<module>()
-> def f(n):
(Pdb) break 21
Breakpoint 1 at .../pdb_no_jump.py:21
(Pdb) jump 8
> .../pdb_no_jump.py(8)<module>()
-> if n < 0:
(Pdb) pn
*** NameError: NameError("name 'n' is not defined",)
(Pdb) args
(Pdb)
$ python -m pdb pdb_no_jump.py
> .../pdb_no_jump.py(7)<module>()
-> def f(n):
(Pdb) break 21
Breakpoint 1 at .../pdb_no_jump.py:21
(Pdb) continue
> .../pdb_no_jump.py(21)<module>()
-> print f(5)
(Pdb) jump 26
*** Jump failed: can't jump into the middle of a block
(Pdb)
$ python -m pdb pdb_no_jump.py
> .../pdb_no_jump.py(7)<module>()
-> def f(n):
(Pdb) break 23
Breakpoint 1 at .../pdb_no_jump.py:23
(Pdb) continue
[5, 15, 30, 50, 75]
> .../pdb_no_jump.py(23)<module>()
-> print 'Always printed'
(Pdb) jump 25
*** Jump failed: can't jump into or out of a 'finally' block
(Pdb)
$ python -m pdb pdb_no_jump.py
> .../pdb_no_jump.py(7)<module>()
-> def f(n):
(Pdb) break 11
Breakpoint 1 at .../pdb_no_jump.py:11
(Pdb) continue
> .../pdb_no_jump.py(11)f()
-> j = 0
(Pdb) where
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/bdb.py(379)run()
-> exec cmd in globals, locals
<string>(1)<module>()
.../pdb_no_jump.py(21)<module>()
-> print f(5)
> .../pdb_no_jump.py(11)f()
-> j = 0
(Pdb) up
> .../pdb_no_jump.py(21)<module>()
-> print f(5)
(Pdb) jump 25
*** You can only jump within the bottom frame
(Pdb)
- #!/ usr / bin / env python
- #エンコード:utf-8
- #
- #Copyright(c)2010 Doug Hellmann。 無断複写・転載を禁じます。
- #
- インポートシステム
- def f():
- print 'コマンドライン引数:' 、sys.argv
- 帰る
- __name__ == '__main__'の場合 :
- f()
$ python -m pdb pdb_run.py
> .../pdb_run.py(7)<module>()
-> import sys
(Pdb) continue
Command line args: ['pdb_run.py']
The program finished and will be restarted
> .../pdb_run.py(7)<module>()
-> import sys
(Pdb)
(Pdb) run abc "this is a long value"
Restarting pdb_run.py with arguments:
abc this is a long value
> .../pdb_run.py(7)<module>()
-> import sys
(Pdb) continue
Command line args: ['pdb_run.py', 'a', 'b', 'c', 'this is a long value']
The program finished and will be restarted
> .../pdb_run.py(7)<module>()
-> import sys
(Pdb)
$ python -m pdb pdb_run.py
> .../pdb_run.py(7)<module>()
-> import sys
(Pdb) break 10
Breakpoint 1 at .../pdb_run.py:10
(Pdb) continue
> .../pdb_run.py(10)f()
-> print 'Command line args:', sys.argv
(Pdb) run one two three
Restarting pdb_run.py with arguments:
one two three
> .../pdb_run.py(7)<module>()
-> import sys
(Pdb)
$ python -m pdb pdb_function_arguments.py
> .../pdb_function_arguments.py(7)<module>()
-> import pdb
(Pdb) break 10
Breakpoint 1 at .../pdb_function_arguments.py:10
(Pdb) continue
> .../pdb_function_arguments.py(10)recursive_function()
-> if n > 0:
(Pdb) pp locals().keys()
['output', 'n']
(Pdb) alias pl pp locals().keys()
(Pdb) pl
['output', 'n']
(Pdb) alias
pl = pp locals().keys()
(Pdb) alias pl
pl = pp locals().keys()
(Pdb)
$ python -m pdb pdb_function_arguments.py
> .../pdb_function_arguments.py(7)<module>()
-> import pdb
(Pdb) alias ph !help(%1)
(Pdb) ph locals
Help on built-in function locals in module __builtin__:
locals(...)
locals() -> dictionary
Update and return a dictionary containing the current scope's local variables.
(Pdb) unalias ph
(Pdb) ph locals
*** SyntaxError: invalid syntax (<stdin>, line 1)
(Pdb)
$ cat ~/.pdbrc
# Show python help
alias ph !help(%1)
# Overridden alias
alias redefined p 'home definition'
$ cat .pdbrc
# Breakpoints
break 10
# Overridden alias
alias redefined p 'local definition'
$ python -m pdb pdb_function_arguments.py
Breakpoint 1 at .../pdb_function_arguments.py:10
> .../pdb_function_arguments.py(7)<module>()
-> import pdb
(Pdb) alias
ph = !help(%1)
redefined = p 'local definition'
(Pdb) break
Num Type Disp Enb Where
1 breakpoint keep yes at .../pdb_function_arguments.py:10
(Pdb)