我有由 frameCount 调用的汇编代码,需要返回 frameCount,但不确定如何检索(然后导航)前一帧的指针引用。
获取FP.s
.globl getFP
getFP:
movq %rbp, %rax
ret
Run Code Online (Sandbox Code Playgroud)
帧数
int frameCount() {
int count = 0;
uint64_t fp = getFP();
uint64_t *sp = &fp;
// how do I get the pointer/offset to pointer to the previous stack frame from here?
return count;
}
Run Code Online (Sandbox Code Playgroud)
我已经更新了 frameCount 函数以包含一个遍历堆栈帧链接列表的循环,但是在调用 frameCount 时出现分段错误。
主文件
#include <stdio.h>
#include <inttypes.h>
#include "framecount.c"
int main() {
printf("Number of Frames: %d\n", frameCount());
return(0);
}
Run Code Online (Sandbox Code Playgroud)
帧数
#include <stdio.h>
#include <inttypes.h>
uint64_t* getFP();
int frameCount() { …Run Code Online (Sandbox Code Playgroud)