ipdb: tracing via additional code on demand | python

386 views Asked by At

I use import ipdb;ipdb.set_trace()

Sometimes, while debugging with set_trace I want verify some method out of frame/source (invoke it with my parameters, and see how it works inside). Method is not used yet in code, so jump is impossible.

sth like:

def do_a(): ...
def do_b(): ...
def do_c(): ...

def do_d():
  do_a()
  import ipdb;ipdb.set_trace()

# here: wanna check do_c before do_b, but not just get result from do_c (it's easy), rather trace throught entire do_c and keep position in current frame.

  do_b()

there is debug command, but do not work with functions, I expect interactive shell.

Workaround is time-consuming: stop debugger, modify code (add do_c() in example) and restart debugger)

1

There are 1 answers

1
Mikko Ohtamaa On

Not sure this works as this is quite rare use case.

Set breakpoint with breakpoint settings command like tbreak:

http://georgejhunt.com/olpc/pydebug/pydebug/ipdb.html

  tbreak do_b   # Might or might not work

Then just execute do_b and it should hit the breakpoint

  do_b()