Exploring the Stack in the GDB

Explore the stack in GDB disassembly output.

Simple stack in the GDB

To see the call stack in real action, we have a code example called a simple stack.

The source code for the simple stack example is broken down into multiple files that we’ll discuss in the next few sections.

Simple stack

The code for the simple stack is as follows:

Press + to interact
void func();
int main(int argc, char* argv[])
{
func();
return 0;
}

We define three functions, func, func2, and func3 like so:

The func method

The code for func is as follows:

Press + to interact
void func2();
void func()
{
func2();
}

The func2 method

This is the code for func2:

Press + to interact
void func3();
void func2()
{
func3();
}

The func3 method

The code for func3 is given below:

Press + to interact
void func3()
{
__asm__ volatile("brk #0");
}

Compilation and execution of code:

We compile the files and load ...

Access this course and 1400+ top-rated courses and projects.