5

I have a Python program with a function foo() in it.

I run the program with PDB, and stop at an arbitrary breakpoint somewhere within the program.

Now, it's easy for me to call foo() from within PDB, I just type:

!foo()

And foo runs. As soon as it finishes, it drops back to PDB, and I'm still waiting at the original line my program was at before.

But now let's say I want PDB to stop at a breakpoint within foo. I set a breakpoint in my source file on the first line of foo(), and then execute !foo().

But PDB doesn't stop at the breakpoint. It only seems to stop there if foo() is called from within the program, not from PDB's command-line while the program is running.

Does anybody know any way around this? I've searched the PDB documentation and Google to no avail.

(The reason I need to do this is because my program takes an hour to read all necessary data to boot up, and I need to be able to debug as much as possible within a single debugging session, as opposed to simply adding breakpoints and re-running the program. So the flexibility of calling functions interactively, and debugging them within, would be tremendously helpful.)

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
crazygringo
  • 1,324
  • 1
  • 9
  • 4
  • You can set breakpoints while in a session if you know the linenumbers. I'm not knowledgeable enough to know what to do if you're going between multiple files though... Also, I don't know if PDB is smart enough to respect those breakpoints if you're running that function in the middle of a session like you are – Conrad.Dean Dec 02 '11 at 15:47
  • I'm not sure if PDB can do that. Anyway, if you think that at some point your program is ready to call foo() for debugging, you just need to modify the source code to call it at that point, debug the problem and remove that extra call after you've fixed the problem. – jcollado Dec 02 '11 at 16:00

1 Answers1

3

Python debugger: Stepping into a function that you have called interactively has the answer: PDB has a 'debug' command that allows you to start a recursive debug session on a function call from within the debugger.

Community
  • 1
  • 1
Paul Holbrook
  • 563
  • 1
  • 4
  • 8