且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

gcc如何对linux上的C ++异常进行堆栈展开?

更新时间:2023-09-26 08:56:10

请参阅 x86_64 ABI 的第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