A Disassembly Example with Function and Stack
Explore disassembly of functions and stack operations in ARM64 using GDB. Learn to set breakpoints, examine registers and memory, and identify parameter mismatches in C/C++ programs.
We'll cover the following...
Example of disassembled code with comments
Here is the commented code disassembly of the main function with memory addresses removed for visual clarity:
Here is the commented disassembly of the arithmetic function, with memory addresses removed for visual clarity:
We can put a breakpoint on the first arithmetic calculations address and examine raw stack data pointed to by the sp register:
gcc FunctionParameters.cpp Arithmetic.cpp -o FunctionParameters
gdb ./FunctionParameters
After executing and loading the program, we get into the GDB container and see the following output:
We create the breakpoint of the programs with the break main command:
break main
The breakpoint is shown below:
Now, we run the program until the GDB breaks in:
set disable-randomization off
run
After running the program, it gives the breakpoint and starts the program’s execution: