how to use gdb to explore the stack/heap?

Viewed 44564

Could anyone please give me a quick overview/point me to documentation of a way to inspect the stack (and heap?) of a C program? I thought this should be done with GDB, but if there are other more straighforward alternatives, then that should be fine as well.

Thanks.

5 Answers

View stack: gdb> backtrace

View current stack frame: gdb> info frame

View arguments of current stack frame: gdb> info args

View local variable of current stack frame: gdb> info locals

Navigate to parent stack frame: gdb> frame 1

Examining the Stack

core_analyzer has gdb plugin and stand alone tool.
Latest version is only gdb plugin.

gdb plugin command shows memory statistic.

(gdb)
heap  [/verbose or /v]  [/leak or /l]
heap  [/block or /b]  [/cluster or /c]  <addr_exp>
heap  [/usage or /u]  <var_exp>
heap  [/topblock or /tb]  [/topuser or /tu]  <num>

stand alone tool has horizontal search and vertical search and it might be near what you expect.

[0] Print General Core Information
[1] Find References to an Object (horizontal search)
[2] What Is This Address and Underlying Object Type (vertical search)
[3] Objects Shared Between Threads
[4] Memory Pattern Analysis
[5] Query Heap Memory Block
[6] Page Walk (check the integrity of surrounding memory blocks)
[7] Heap Walk (check the whole heap for corruption and memory usage)
[8] Biggest heap memory blocks
[9] Biggest Heap Memory Owners (variables)
[10] Heap Memory Leak Candidates
[11] Quit

In my case, I could not get exprected result from core_analyzer.

Related