[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Full stack trace in pdb.post_mortem() ?

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():
        except Exception as ex:
            # using breakpoint() gives the full stack trace, of course

    def 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
    -> 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()`? 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)

For this contrived example, I can put `breakpoint()` instead of
`post_mortem()`, and get what I want.

But I feel like I'm misunderstanding post-mortem debugging.
Is the full call stack simply not available?

Note: I am aware that I can *print* the full stack trace (including
`main()`), even if it takes some special effort. See these posts: