Print the stack frame link list and Hex contents of stack from FP to stack frame

醉酒当歌 提交于 2020-01-06 05:59:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!