Is there a simple DWARF CFI represenation for functions that set up a conventional frame pointer?

99封情书 提交于 2019-12-19 18:48:40

问题


I'm programming in a mix of C, C++ and assembly and I'd like to get reliable backtraces from any part of the code.

This mostly works fine for the C and C++ code since I can generate debugging info with -g, which for modern x86 compilers and platforms generates DWARF debugging information which means the final binary includes CFI (Call Frame Information). This information allows walking backwards though the functions in the current call stack. It can support complex scenarios such as functions without a base pointer and where rsp changes in dynamic ways. For C and C++ code I don't have to care: the compiler just generates the right CFI even for optimized code.

For the x86 assembly code, which I write in nasm, the CFI is a problem. Both nasm and the syntax-compatible competitor yasm have some limited support for generating DWARF info, but it mostly involves instruction pointer to line mapping and doens't include any CFI1 (indeed, the an assembly couldn't really produce this even if it wanted since assembly is too low level to unambiguously express the call/return semantics).

I'd like to add CFI for the assembly generated routines, but I don't need the full flexibility of the CFI to identify the CFA based on instruction-granular changes to rsp and so on: I am perfectly happy to set up a standard frame-pointer in rbp for each assembly function and leave it intact for the entire function. Does DWARF3 support this scenario with a simple bit of CFI information, hopefully one that I can generate with an assembler macro?


1 The experimental "nextgen" version of yasm does have support for CFI directives, but that project hasn't been updated in 5 years. There is an open issue to port this support back to the mainline version of yasm.

来源:https://stackoverflow.com/questions/47026338/is-there-a-simple-dwarf-cfi-represenation-for-functions-that-set-up-a-convention

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!