I'm working on a garbage collector, and in one case, I'm trying to resolve why a piece of memory is not being collected. I have instrumented my GC to print out all known stack ranges and addresses that are live, and what they refer to. And in this graph, I can discover the path between the stack frame and the live data.
Now, given this, inside gdb I can start from the stack variable and get to the bottom of what is happening. However, the graph is not typed, so the first thing I need to do is figure out which variable represents the address. I want to say "given address 0x12345678, which local stack symbol lives there?". I know gdb has the information, as once I find the right symbol, I can verify that it's living at the address provided.
Is there a way to do this? Preferably over the entire stack, but even would be helpful within a specific frame.
Is there a way to do this?
You can enumerate all variables using GDB with embedded Python. Start here.
However note that not every stack location corresponds to a named variable -- a compiler will often create unnamed temporaries or just spill registers into a stack location (especially on register-starved architectures such as i*86
and (to a lesser extent) x86_64
.