Call Frames and Machine Code Correlation
For a call to a function, the machine code generated typically contains:
- The machine code before the call performs the following
operations:
- Sets some context registers
- Puts the parameters either in registers or memory
- Loads the address of the function into a register
- Loads the address to return to into a register
- Branches to the function
- The machine code at the start of the called function
performs the following operations:
- Sets some context registers
- Allocates stack space
- Saves some registers in the stack space
- Performs some setup of the local variables
- The machine code at the end of the called function
performs the following operations:
- Restores the saved registers from the stack space
- Deallocates the stack space
- Branches to the address to return to
- The machine code at the return address of the call
frame sets some context registers.
When the thread is partway through the call frame creation or tear-down,
the debugger will still show the call frame, but will not be able to show
correct values for the variables or parameters.