PDB - stepping out of a function
Asked Answered
H

3

71

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?

Heresy answered 1/2, 2018 at 15:0 Comment(0)
T
92

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.
Teuton answered 19/4, 2018 at 2:23 Comment(2)
r then n, got it!Oxidase
And you can use retval debugger command to examine the return value.Corbitt
E
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

Edibles answered 1/2, 2018 at 15:11 Comment(4)
I would like to continue the execution until the current running function (the one I stepped into) is finished, something like until does for loopsHeresy
well, the doc quite clearly list r(eturn) which does exactly what you are asking forEdibles
That's the solution I was looking for. Thought r(eturn) is just a synonym to a regular return!Heresy
You might want to edit or delete this answer, because it currently doesn't answer the (since edited) question as askedNumberless
S
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
Soundproof answered 1/2, 2018 at 15:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.