views:

218

answers:

1

From what I can tell, pdb does not recognize when the source code has changed between "runs". That is, if I'm debugging, notice a bug, fix that bug, and rerun the program in pdb (i.e. without exiting pdb), pdb will not recompile the code. I'll still be debugging the old version of the code, even if pdb lists the new source code.

So, does pdb not update the compiled code as the source changes? If not, is there a way to make it do so? I'd like to be able to stay in a single pdb session in order to keep my breakpoints and such.

FWIW, gdb will notice when the program it's debugging changes underneath it, though only on a restart of that program. This is the behavior I'm trying to replicate in pdb.

A: 

What do you mean by "rerun the program in pdb?" If you've imported a module, Python won't reread it unless you explicitly ask to do so, i.e. with reload(module). However, reload is far from bulletproof (see xreload for another strategy).

There are plenty of pitfalls in Python code reloading. To more robustly solve your problem, you could wrap pdb with a class that records your breakpoint info to a file on disk, for example, and plays them back on command.

(Sorry, ignore the first version of this answer; it's early and I didn't read your question carefully enough.)

Nicholas Riley
What I mean by "rerun" is, conceptually, what I mean by rerunning a python program from the command line. pdb clearly understands the notion of my program exiting, so I'm wondering, when it runs my program a second time, if I can get it to also recompile the source as necessary.
You can try using `reload` from inside pdb before rerunning it, but again, depending on structure of your program, it may not be reliable. (FWIW, I consider this the single biggest failure of Python as a language. Coming from environments like Smalltalk and Lisp, it's just depressing.)
Nicholas Riley