Search⌘ K
AI Features

Local Variables

Explore how local variables are managed within function stack frames on ARM64 and learn to debug them using GDB. Understand function prolog and epilog sequences through disassembly and practice commands to analyze compiled code effectively.

Local variables example

Local variables are variables that are only available and accessible within the function.

Source code

The source code of the local variables is given below:

C++
int main()
{
int a, b;
a = 1;
b = 1;
b = b + a;
++a;
b = b * a;
return 0;
}

Compilation and execution of code

We compile the file and load the executable into the GDB:

C++
gcc LocalVariables.cpp -o LocalVariables
gdb ./LocalVariables

The output after loading the executable file will be as follows:

Loading object code into GDB
Loading object code into GDB

Then we put a breakpoint to the main function:

Assembly (GAS x86)
break main

The breakpoint of the ...