小编yib*_*ibo的帖子

我如何在我的 frameCount 函数中计算堆栈帧的数量?

我有由 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)

c assembly x86-64 backtrace stack-frame

3
推荐指数
1
解决办法
195
查看次数

标签 统计

assembly ×1

backtrace ×1

c ×1

stack-frame ×1

x86-64 ×1