问题
I'm given the following code:
#include <stdio.h>
#include <stdlib.h>
int A(int x, int y);
int B(int x, int y);
int *FP;
int main(int argc, char *argv[], char *env[]){
int a, b, c;
printf("enter main\n");
A(a,b);
printf("exit main\n");
return 0;
}
int A(int x, int y)
{
int d, e, f;
printf("enter A\n");
d = 4; e = 5; f = 6;
B(d,e);
printf("exit A\n");
}
int B(int x, int y)
{
int u, v, w;
printf("enter B\n");
u = 7; v = 8; w = 9;
asm("movl %ebp, FP"); // set FP = CPU's %ebp register
//Write C code to question here
printf("exit B\n");
}
I'm asked to:
- In B(), FP points the stack frame link list in stack. Print the stack frame link list.
- Print in HEX the address and contents of the stack from FP to the stack frame of main().
I'm not sure how to get started and was wondering if I could get some advice/hints. Since FP is already pointing to the stack frame, would it be something like printf("%p", &FP)
? All help is much appreciated.
来源:https://stackoverflow.com/questions/48271127/print-the-stack-frame-link-list-and-hex-contents-of-stack-from-fp-to-stack-frame