问题描述
gcc如何在linux上为C ++异常展开堆栈?特别地,它如何知道在展开框架时要调用哪个析构函数(即,存储什么样的信息以及存储在哪里)?
How does gcc implement stack unrolling for C++ exceptions on linux? In particular, how does it know which destructors to call when unrolling a frame (i.e., what kind of information is stored and where is it stored)?
推荐答案
请参阅的第6.2节。这详细介绍了接口,但不是很多基础数据。这也是独立于C ++,可以想象也可以用于其他目的。
See section 6.2 of the x86_64 ABI. This details the interface but not a lot of the underlying data. This is also independent of C++ and could conceivably be used for other purposes as well.
主要由gcc发出的ELF二进制文件的两个部分异常处理。他们是 .eh_frame
和 .gcc_except_table
。
There are primarily two sections of the ELF binary as emitted by gcc which are of interest for exception handling. They are .eh_frame
and .gcc_except_table
.
.eh_frame
遵循DWARF格式(当您使用gdb时主要播放的调试格式) 。它与使用 -g
进行编译时发出的 .debug_frame
部分格式完全相同。从本质上讲,它包含了在调用堆栈上的任意一点弹出机器寄存器和堆栈状态所需的信息。请参阅dwarfstd.org上的Dwarf标准,了解更多有关此信息的信息。
.eh_frame
follows the DWARF format (the debugging format that primarily comes into play when you're using gdb). It has exactly the same format as the .debug_frame
section emitted when compiling with -g
. Essentially, it contains the information necessary to pop back to the state of the machine registers and the stack at any point higher up the call stack. See the Dwarf Standard at dwarfstd.org for more information on this.
.gcc_except_table
包含有关异常处理的信息登陆垫处理程序的位置。这是必要的,以便知道何时停止放松。不幸的是,这一节没有很好的记录。我已经能够收集的唯一的信息片段来自gcc邮件列表。特别参见
.gcc_except_table
contains information about the exception handling "landing pads" the locations of handlers. This is necessary so as to know when to stop unwinding. Unfortunately this section is not well documented. The only snippets of information I have been able to glean come from the gcc mailing list. See particularly this post
剩下的信息是什么实际代码解释这些数据部分中发现的信息。相关代码存在于libstdc ++和libgcc中。目前我记不住哪一块生活在哪一个。 DWARF调用框架信息的解释器可以在文件gcc / unwind-dw.c中的gcc源代码中找到。
The remaining piece of information is then what actual code interprets the information found in these data sections. The relevant code lives in libstdc++ and libgcc. I cannot remember at the moment which pieces live in which. The interpreter for the DWARF call frame information can be found in the gcc source code in the file gcc/unwind-dw.c
这篇关于gcc如何对linux上的C ++异常进行堆栈展开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!