ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

GCC之CFI

2019-03-04 22:48:55  阅读:396  来源: 互联网

标签:GCC cfi frame CFI esp CFA ebp cfa


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


 
  1. pushl %ebp

  2. .cfi_def_cfa_offset 8

  3. .cfi_offset 5, -8

  4.  

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


 
  1. movl %esp, %ebp

  2. .cfi_def_cfa_register 5

  3.  

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


 
  1. leave

  2. .cfi_restore 5

  3. .cfi_def_cfa 4, 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

都是英文版的,可以下载谷歌浏览器,查看时翻译,正确率很高够用。

转自:

https://blog.csdn.net/jtli_embeddedcv/article/details/9321253

标签:GCC,cfi,frame,CFI,esp,CFA,ebp,cfa
来源: https://blog.csdn.net/Comet_sgf/article/details/88141935

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有