PDB - stepping out of a function

PythonPython 2.7PdbIpdb

Python Problem Overview


Can I step out of a function after stepping into it with step while using pdb / ipdb debugger?

And if there's no such option - what is the fastest way to get out of the stepped-in function?

Python Solutions


Solution 1 - Python

As mentioned by Arthur in a comment, you can use r(eturn) to run execution to the end of the current function and then stop, which almost steps out of the current function. Then enter n(ext) once to complete the step out, returning to the caller.

Documentation is here.

(Pdb) ?r
r(eturn)
        Continue execution until the current function returns.

Solution 2 - Python

step will continue the execution. To move up and down the callstack, you can use up (move up to the calling function), and then down to go back the other way.

Have a look at the doc: https://docs.python.org/3.6/library/pdb.html#pdbcommand-step

Solution 3 - Python

You can just add a breakpoint outside the function and continue until you reach it. For example, if the call to your function is at line 14, you can:

(Pdb) b 15
(Pdb) c

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKludgeView Question on Stackoverflow
Solution 1 - PythondavidAView Answer on Stackoverflow
Solution 2 - PythonArthurView Answer on Stackoverflow
Solution 3 - PythonMarounView Answer on Stackoverflow