62

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?

Kludge
  • 2,653
  • 4
  • 20
  • 42

3 Answers3

82

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.
davidA
  • 12,528
  • 9
  • 64
  • 96
12

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

Arthur
  • 4,093
  • 3
  • 17
  • 28
  • I would like to continue the execution until the current running function (the one I stepped into) is finished, something like `until` does for loops – Kludge Feb 01 '18 at 15:35
  • 4
    well, the doc quite clearly list `r(eturn)` which does exactly what you are asking for – Arthur Feb 01 '18 at 17:44
  • 1
    That's the solution I was looking for. Thought `r(eturn)` is just a synonym to a regular `return`! – Kludge Feb 01 '18 at 19:58
  • You might want to edit or delete this answer, because it currently doesn't answer the (since edited) question as asked – loopbackbee Apr 23 '20 at 18:10
6

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
Maroun
  • 94,125
  • 30
  • 188
  • 241