How can iterate the stack frames manually in C?

前端 未结 3 2152
孤街浪徒
孤街浪徒 2021-01-06 18:17

While handling signals in applications I can correctly see the backtrace in the debugger.But the backtrace system call is not showing the stack frames correctly.Is there a d

3条回答
  •  我在风中等你
    2021-01-06 19:16

    The debugger uses an additional set of extra data placed into the binary by the compiler by gcc when you use the -g option. This data is not used by the backtrace call and only the basic linker information is used. This means for example any static data is not viewable by the backtrace but is by gdb, this also results in various optimizations breaking backtrace which gdb works around through explicit knowledge.

    Remember, gdb is specific to a certain language and compiler while backtrace is much more portable.

    See the man page of backtrace http://linux.die.net/man/3/backtrace:

    Omission of the frame pointers (as implied by any of gcc(1)'s nonzero optimization levels) may cause these assumptions to be violated.

    If the backtrace call wanted to use this information it would have to force you to always compile with debug symbols and would have much greater overhead and many other issues.

提交回复
热议问题