4

Apparently I've unlearned how to debug with python.

I run bpython3 -i myfile.py, but when an exception occurs I still don't have access to the program variables, nor I can find any command like gdb's up and down.

I've tried to import pdb and play around with it, but I didn't manage to obtain much. And it definitely isn't integrated into bpython in any way.

As far as I remember, it was pretty straightforward, like gdb, but apparently I remember uncorrectly and now I'm clueless. Information online about python debuggers is confused, vague, and I couldn't find anything similar to what I was using before, so I came to ask here: am I missing something obvious?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
o0'.
  • 11,739
  • 19
  • 60
  • 87

1 Answers1

2

bpython3 is just an interface for an interactive Python shell. For gdb-like debugging, use pdb, which supports gdb-like commands:

$ python3 -m pdb t.py 
> /tmp/t.py(2)<module>()
-> def a():
(Pdb) c
Traceback (most recent call last):
  File "/usr/lib/python3.2/pdb.py", line 1556, in main
    pdb._runscript(mainpyfile)
  File "/usr/lib/python3.2/pdb.py", line 1437, in _runscript
    self.run(statement)
  File "/usr/lib/python3.2/bdb.py", line 405, in run
    exec(cmd, globals, locals)
  File "<string>", line 1, in <module>
  File "/tmp/t.py", line 2, in <module>
    def a():
  File "/tmp/t.py", line 4, in a
    b()
  File "/tmp/t.py", line 7, in b
    1/0
ZeroDivisionError: division by zero
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> /tmp/t.py(7)b()
-> 1/0
(Pdb) up
> /tmp/t.py(4)a()
-> b()
(Pdb) print x
1

If you want to use bpython(3) as your debugger, you'll have to include some glue code.

Community
  • 1
  • 1
phihag
  • 278,196
  • 72
  • 453
  • 469
  • Didn't have the time to check this yet, but since bounty is expiring I'll award it anyway, hoping it will be deserved. – o0'. Jul 07 '12 at 09:05