.cfi指令解读(一)

转自:http://51hired.com/questions/14933/%E5%A6%82%E4%BD%95%E7%90%86%E8%A7%A3%E8%BF%99%E4%BA%9B.cfi%E6%8C%87%E4%BB%A4%EF%BC%9F

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 xxxSP(stack pointer)所指向的地址。

pushl    %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8

表示执行完pushl %ebpSPCFA偏了8字节(4字节return address,4字节ebp

movl    %esp, %ebp
.cfi_def_cfa_register 5

表示执行完movl %esp, %ebpcfa_register不再是esp,而是ebp

leave
.cfi_restore 5
.cfi_def_cfa 4, 4

表示执行完leaveebp的值已经恢复到初始状态,并且CFA的计算方式应该是esp+4

其中寄存器对应的数字是架构相关的,详细参考xxx_map_dwarf_register

  1. i386
  2. x86_64
  3. sparc
  4. arm

参考:

Dwarf2 Exception Handler HOWTO

CFI directives

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值