Paul D. Eden
Paul D. Eden

Reputation: 20559

How to show the output of 'l' in python pdb after every command entered

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?

Upvotes: 5

Views: 1806

Answers (2)

Michael Twomey
Michael Twomey

Reputation: 1762

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

Upvotes: 6

Mykola Kharechko
Mykola Kharechko

Reputation: 3211

';;' 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)

Upvotes: 2

Related Questions