Exploring Stack in GDB
Explore how to use GDB to examine the stack, inspect function call sequences, and analyze registers and memory during program execution. Understand how to set breakpoints, view the call stack with backtrace, and interpret disassembly for debugging C programs on x64 Linux.
Simple stack in GDB
To see the call stack in action, we’ll use a project called SimpleStack.
Source code
The source code of the stack is given below:
Simple stack
The code for the simple stack is:
We define three functions func, func2, and func3 as below:
Method func
The code for func is:
Method func2
The code for func2 is:
Method func3
The code for func3 is:
Compilation and execution of code:
We compile the files and load the executable into GDB:
gcc SimpleStack.c func.c func2.c func3.c -o SimpleStack
gdb ./SimpleStack
Note: You can practice all ...