编译阶段:
- -fno-omit-frame-pointer:开启帧指针
- -fomit-frame-pointer:关闭帧指针
代码中添加:
- __attribute__((optimize("no-omit-frame-pointer"))) 修饰函数,开启帧指针
- __attribute__((optimize("omit-frame-pointer"))) 修饰函数,关闭帧指针
反汇编测试
#ifdef OFF
#define _frame_pointer __attribute__((optimize("omit-frame-pointer")))
#else
#define _frame_pointer
#endif
_frame_pointer int foo()
{
int i = 0;
return i+1;
}