In the perl debugger, if you repeatedly list segments of code taking you away from the current line, you can return to the current line by entering the command .
(dot).
I have not been able to find anything comparable using the python PDB module. If I list myself away from the current line and want to view it again, it seems I have to either remember the line number that was currently executing (unlikely for me) or execute a statement (often undesirable).
Am I missing something?
The difference between n (next) and s (step) is where pdb stops. Use n (next) to continue execution until the next line and stay within the current function, i.e. not stop in a foreign function if one is called.
Starting Python Debugger To start debugging within the program just insert import pdb, pdb. set_trace() commands. Run your script normally and execution will stop where we have introduced a breakpoint. So basically we are hard coding a breakpoint on a line below where we call set_trace().
pdb. set_trace (*, header=None) Enter the debugger at the calling stack frame. This is useful to hard-code a breakpoint at a given point in a program, even if the code is not otherwise being debugged (e.g. when an assertion fails). If given, header is printed to the console just before debugging begins.
Late but hopefully still helpful. Make the following alias:
alias ll u;;d;;l
Then whenever you type ll
, pdb will list from the current position. It works by going up the stack and then down the stack, which resets 'l' to show from the current position. (This won't work if you are at the top of the stack trace.)
Tip: Permanent alias
To make the alias permanent, add the line into your .pdbrc
-file in the user home directory (~/.pdbrc
). This works with both pdb and ipdb.
In Python 3.2 and higher, you can use list .
to reset the list location.
Source: Python Bug tracker #4179
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