Reputation: 60691
i am using the python shell to try to do debugging
i set a breakpoint
i did:
>>> import pdb
>>> import mymodule
>>> pdb.run('mymodule.test()')
but it is just running my program without stopping at the breakpoint!
what am i donig wrong?
Upvotes: 0
Views: 278
Reputation: 7285
The typical usage to break into the debugger from a running program is to insert
import pdb; pdb.set_trace()
at the location you want to break into the debugger. You can then step through the code following this statement, and continue running without the debugger using the c command.
The typical usage to inspect a crashed program is:
>>> import pdb
>>> import mymodule
>>> mymodule.test()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "./mymodule.py", line 4, in test
test2()
File "./mymodule.py", line 3, in test2
print spam
NameError: spam
>>> pdb.pm()
> ./mymodule.py(3)test2()
-> print spam
(Pdb)
The Python site offers a very elaborate tutorial for pdb
. Go to http://docs.python.org/library/pdb.html.
Upvotes: 2
Reputation: 123468
How did you set a breakpoint? Try adding the line in your code:
import pdb
pdb.set_trace()
and then run it. If you're in the pdb shell, then "break foo.py:45" will break on line 45 of file foo.py.
Here are some useful commands:
h help, list commands
s step through current line
n step to next line
u go up the stack
c continue execution
Check the full list by typing 'h'. And "help X" will give you help on command X. Also, see this tutorial:
Upvotes: 4