John W <jwde...@gmail.com> writes: > I'm trying to understand pdb.post_mortem(), and why the backtrace > available in the debugger session seems limited. > > I posted a similar question on stackoverflow[1], but figured I'd try > here as well. > > Here's a simple program > > import pdb > > def inner(): > raise Exception("bad stuff") > > def outer(): > try: > inner() > except Exception as ex: > pdb.post_mortem() > # using breakpoint() gives the full stack trace, of course > > def main(): > outer() > > main() > > When I run that, I get put in the debugger. > Then, if I run the `bt` command to get a backtrace, I see: > > (Pdb) bt > /path/to/script(10)outer() > -> inner() > > /path/to/script(6)inner() > -> raise Exception("bad stuff") > > As you can see, the backtrace only has `outer()` and `inner()`. > What happened to `main()`?
"post_mortem" shows you the traceback from the frame where the exception occured until the current frame. Because you called "post_mortem" in "outer", the display will stop there (and do not include "main"). >I want the full stack available, so I can > investigate variables, etc. at any point along the chain. > (in a real example, there might be quite a lot of additional call > frames of interest) Then use "pdb.set_trace" instead of "pdb.post_mortem". -- https://mail.python.org/mailman/listinfo/python-list