Skip to content
Advertisement

Step into the non-innermost call in an expression with PDB

Consider a piece of code like this:

breakpoint()
x = foo(bar(baz()))

In PDB (or PDB++), the step command normally would step into the baz() function.

How can I step into the call to bar() or baz() instead of baz()? I don’t see anything about this in the PDB or PDB++ documentation.

Advertisement

Answer

Look at the list of debugger commands here.

You can either put a breakpoint using break or temporary breakpoint using tbreak in foo or bar:

$ python3 x.py 
> /tmp/0/x.py(14)<module>()
-> x=foo(bar(baz(42)))
(Pdb) break foo
Breakpoint 1 at /tmp/0/x.py:1
(Pdb) continue
> /tmp/0/x.py(2)foo()
-> ret=x+1

or run until the baz end using return and then step again:

$ python3 x.py 
> /tmp/0/x.py(14)<module>()
-> x=foo(bar(baz(42)))
(Pdb) step
--Call--
> /tmp/0/x.py(9)baz()
-> def baz(x):
(Pdb) return
--Return--
> /tmp/0/x.py(11)baz()->45
-> return ret
(Pdb) step
--Call--
> /tmp/0/x.py(5)bar()
-> def bar(x):
(Pdb) return
--Return--
> /tmp/0/x.py(7)bar()->47
-> return ret
(Pdb) step
--Call--
> /tmp/0/x.py(1)foo()
-> def foo(x):
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement