Search⌘ K
AI Features

Exploring the Stack in the GDB

Explore how to use GDB to examine the stack on ARM64 Linux systems. Learn to set breakpoints, inspect stack pointers and registers, and analyze call stacks for debugging C/C++ programs at the assembly level.

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:

C++
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:

C++
void func2();
void func()
{
func2();
}

The func2 method

This is the code for func2:

C++
void func3();
void func2()
{
func3();
}

The func3 method

The code for func3 is given below:

C++
void func3()
{
__asm__ volatile("brk #0");
}

Compilation and execution of code:

We compile the files and load ...