PDB: How to inspect local variables of functions in nested stack frames?

Todd Ditchendorf

Context:

I'm running some python code thru PDB (Python debugger). When I set and subsequently hit a breakpoint, I can inspect the local variables using:

(Pdb) locals()

This prints out a nice dict of name, value pairs of the local variables in the current scope in which I'm paused. Perfect!

I can also see a stack trace using the PDB where command which results in something like this:

  /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/bdb.py(400)run()
-> exec cmd in globals, locals
  <string>(1)<module>()
  .../main.py(116)<module>()
-> run()
  .../main.py(104)run()
-> res = quicksort(res)
> .../main.py(68)quicksort()
-> if len(v) <= 1:

In this example output, I'm paused in the quicksort() function which was called by the run() function.

So far, so good.

Question:

If I can inspect the quicksort() function's local variables with a call to locals(), how can I similarly inspect the local variables of the run() function?

In other words, how can I inspect the local variables of a function which is nested in the call stack?

Important clarification: I DON'T want to continue or step into run() to inspect its local variables. I want to inspect (from my current, paused perspective) the local variables in the run() stack frame currently nested in the call stack.

Jan Vlcinsky

(i)pdb offer commands up and down, allowing you to travel via call stack, this way you can visit higher levels of your call and inspect local variables there.

You can jump up or down the call stack using u(p) or d(own). You can also specify a number of frames to by giving it as an argument to u(p) or d(own).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to inspect the variables of user space functions in systemtap?

From Dev

Using 'get' Inside Nested Functions on Local Variables

From Dev

How to experiment source code with `pdb`, `inspect`, `pprint`?

From Dev

How do local variables get stored in stack?

From Dev

How does gcc push local variables on to the stack?

From Dev

how to reference local variables on the stack properly

From Dev

How to inspect WebSocket frames in Chrome properly?

From Dev

How to modify local variables from a nested closure?

From Dev

Local variables on stack

From Dev

Local variables: are they always on the stack?

From Dev

How to inspect variables after Traceback?

From Dev

How can I extract local variables from a stack trace?

From Dev

How to insist a C compiler put local variables on the stack, not in registers

From Dev

How does initialization of local variables (large arrays) affect stack size?

From Dev

Examining local variables up the stack

From Dev

Compiling local variables for a stack machine

From Dev

Stack overflow from local variables?

From Dev

Compiling local variables for a stack machine

From Dev

Examining local variables up the stack

From Dev

How to use local variables from functions in main program using Ruby?

From Dev

How to inspect the javascript functions and its arguments

From Dev

How do I inspect Pelican variables

From Dev

How can I inspect cmake internal variables?

From Dev

How do you inspect CSS variables in the browser?

From Dev

Using local variables outside their functions

From Dev

Using local variables outside their functions

From Dev

scilab local variables on different functions

From Dev

Why do static functions sometimes have non standard stack frames?

From Dev

How can iterate the stack frames manually in C?

Related Related

  1. 1

    How to inspect the variables of user space functions in systemtap?

  2. 2

    Using 'get' Inside Nested Functions on Local Variables

  3. 3

    How to experiment source code with `pdb`, `inspect`, `pprint`?

  4. 4

    How do local variables get stored in stack?

  5. 5

    How does gcc push local variables on to the stack?

  6. 6

    how to reference local variables on the stack properly

  7. 7

    How to inspect WebSocket frames in Chrome properly?

  8. 8

    How to modify local variables from a nested closure?

  9. 9

    Local variables on stack

  10. 10

    Local variables: are they always on the stack?

  11. 11

    How to inspect variables after Traceback?

  12. 12

    How can I extract local variables from a stack trace?

  13. 13

    How to insist a C compiler put local variables on the stack, not in registers

  14. 14

    How does initialization of local variables (large arrays) affect stack size?

  15. 15

    Examining local variables up the stack

  16. 16

    Compiling local variables for a stack machine

  17. 17

    Stack overflow from local variables?

  18. 18

    Compiling local variables for a stack machine

  19. 19

    Examining local variables up the stack

  20. 20

    How to use local variables from functions in main program using Ruby?

  21. 21

    How to inspect the javascript functions and its arguments

  22. 22

    How do I inspect Pelican variables

  23. 23

    How can I inspect cmake internal variables?

  24. 24

    How do you inspect CSS variables in the browser?

  25. 25

    Using local variables outside their functions

  26. 26

    Using local variables outside their functions

  27. 27

    scilab local variables on different functions

  28. 28

    Why do static functions sometimes have non standard stack frames?

  29. 29

    How can iterate the stack frames manually in C?

HotTag

Archive