CFI(calling frame info
)的作用是出现异常时stack
的回滚(unwind
)
而回滚的过程是一级级CFA往上回退,直到异常被catch
。
DWARF4
标准的section 6.4
:
The call frame is identified by an address on the stack. We refer to this address as the Canonical Frame Address orCFA. Typically, the CFA is defined to be the value of the stack pointer at the call site in the previous frame (which may be different from its value on entry to the current frame).
即CFA定义为执行call xxx
时SP(stack pointer
)所指向的地址。
-
pushl %ebp
-
.cfi_def_cfa_offset 8
-
.cfi_offset 5, -8
表示执行完pushl %ebp
后SP与CFA偏了8
字节(4
字节return address
,4
字节ebp
)
-
movl %esp, %ebp
-
.cfi_def_cfa_register 5
表示执行完movl %esp, %ebp
后cfa_register
不再是esp
,而是ebp
-
leave
-
.cfi_restore 5
-
.cfi_def_cfa 4, 4
表示执行完leave
后ebp
的值已经恢复到初始状态,并且CFA的计算方式应该是esp+4
其中寄存器对应的数字是架构相关的,详细参考xxx_map_dwarf_register
:
参考:
Dwarf2 Exception Handler HOWTO
都是英文版的,可以下载谷歌浏览器,查看时翻译,正确率很高够用。
转自:
https://blog.csdn.net/jtli_embeddedcv/article/details/9321253