184k views
5 votes
Given the following C program tmpVars.c and its ARM64 assembly version tmpVars.s, type in or copy the two into Raspberry Pi with Geany or text editor. Use "gee −g−0 tmpe terminal and "gdb tmpa" in the other. Set a break point at main, list the source program in each, run them. Print out the contents of the main stack frame with " x/16xb$sp " command before running any line of code. Run a single line of code with next command, and then print out values of the variable and the stack frame. Verify the values of local variables and stack memory value with your explanation or comments.

1 Answer

2 votes

Final answer:

The question involves debugging a C program and its equivalent ARM64 assembly code on a Raspberry Pi using gdb to view the stack frame and variable values after each executed line of code.

Step-by-step explanation:

The student is working with programming in C and debugging ARM64 assembly language on a Raspberry Pi. Initially, they are asked to copy or type in the provided C program (tmpVars.c) and its assembly version (tmpVars.s) into a text editor such as Geany. Then, they must compile the program with specific compiler flags using the command gcc -g -O0 tmpVars.c and proceed to debug it using gdb tmpVars. A breakpoint is set at the main function to start debugging. Before executing any lines of code, stack frame contents are inspected with the x/16xb $sp command to print the memory at the stack pointer (sp). Then, the next command is used to step through each line of code while observing changes in the stack frame and monitoring the values of local variables.

User Hexagon Theory
by
7.7k points