I would like to have the output of the python pdb 'l' command printed to the screen after every command I enter in an interactive debugging session.
Is there a way to setup python pdb to do this?
pdb is a fully featured python shell, so you can execute arbitrary commands. locals() and globals() will display all the variables in scope with their values. You can use dir() if you're not interested in the values.
Once you get you pdb prompt . Just hit n (next) 10 times to exit the loop.
To start execution, you use the continue or c command. If the program executes successfully, you will be taken back to the (Pdb) prompt where you can restart the execution again. At this point, you can use quit / q or Ctrl+D to exit the debugger.
There are many different ways to use pdb, but the simplest is by using its pdb. set_trace() function. Wherever you put this line in your code, the Python interpreter will stop and present an interactive debugger command prompt.
One way to do this is to alias your favourite commands to run the command and then l.
e.g.
(Pdb) alias s step ;; l
(Pdb) s
> /usr/lib/python2.5/distutils/core.py(14)<module>()
-> from types import *
9 # This module should be kept compatible with Python 2.1.
10
11 __revision__ = "$Id: core.py 38672 2005-03-20 22:19:47Z fdrake $"
12
13 import sys, os
14 -> from types import *
15
16 from distutils.debug import DEBUG
17 from distutils.errors import *
18 from distutils.util import grok_environment_error
19
In your ~/.pdbrc you can add the aliases so you have them every time:
alias s step ;; l
';;' allow to separate commands
[crchemist@test tmp]$ python t.py
> /home/crchemist/tmp/t.py(7)()
-> a()
(Pdb) p a ;; l
function a at 0xb7e96df4
2 b = 49 + 45
3 v = 'fff'
4 return v
5
6 import pdb; pdb.set_trace()
7 -> a() [EOF]
(Pdb) s ;; l
--Call--
> /home/crchemist/tmp/t.py(1)a()
-> def a():
1 -> def a():
2 b = 49 + 45
3 v = 'fff'
4 return v
5
6 import pdb; pdb.set_trace()
7 a() [EOF]
(Pdb) s ;; l
> /home/crchemist/tmp/t.py(2)a()
-> b = 49 + 45
1 def a():
2 -> b = 49 + 45
3 v = 'fff'
4 return v
5
6 import pdb; pdb.set_trace()
7 a() [EOF]
(Pdb)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With