backward-cpp icon indicating copy to clipboard operation
backward-cpp copied to clipboard

Ultimate stack trace support

Open eldiener opened this issue 6 years ago • 6 comments

"You will need to install some dependencies to get the ultimate stack trace. Two libraries are currently supported, the only difference is which one is the easiest for you to install, so pick your poison:"

after which you mention libbfd, libdw, libdwarf, and libelf, which is four and not two to me. Can you clarify what library(s) are actually needed for this ultimate stack trace support ?

eldiener avatar Aug 28 '18 18:08 eldiener

A description in in the code starting at https://github.com/bombela/backward-cpp/blob/84ae4f5e80381aca765a0810d4c811acae3cd7c7/backward.hpp#L118

In short libdw and libdwarf are the best, BUT libdwarf requries also libelf.

RoyBellingan avatar Aug 28 '18 19:08 RoyBellingan

Yeah doc could be clearer I suppose. libbfd or libdw are used to read and extract basic information from the executable itself.

libdwarf (and libelf as a dependency) is used to decode detailed debugging information stored in the DWARF format embedded within the executable.

As @RoyBellingan said, libdw + libdwarf (and libelf) is the best combination.

bombela avatar Aug 28 '18 19:08 bombela

The comment in backward.hpp says that only one of the symbols should be set at a time. So it does not seem that libdw and libdwarf (and libelf) can be used since I am not supposed to have both #define BACKWARD_HAS_DW 1 and #define BACKWARD_HAS_DWARF 1.

eldiener avatar Aug 28 '18 21:08 eldiener

Sorry, my reply was really confusing. I meant that DW and DWARF are the two best options for reading debug information. Pick the one easiest to install on your system. Let me expand.

There is two important dependencies that are needed for detailed stacktrace. The first, is the ability to walk the call stack. The second is the ability to decode debug information from the executable.

I will be assuming Linux here.

Walking the stack

For walking the stack you have the choice between UNWIND and BACKTRACE (see backward.hpp#L85). UNWIND is the best possible choice. BACKTRACE doesn't report if the address points before the instruction that failed (cpu exception) or after it (signal/interruption).

Reading debug information

For decoding debug information in the DWARF format, the choice is greater (see backward.hpp#L115). The two libraries that offer the best support and most details are DW and DWARF. BFD follows. And BACKTRACE_SYMBOL comes last. If you paid attention, you will notice that BACKTRACE_SYMBOL is the same library as BACKTRACE mentioned above. It offers the bare minimum, but sometimes that's all you have.

Conclusion

UNWIND + (DW or DWARF) will give you perfectly accurate stack traces.

bombela avatar Oct 23 '18 14:10 bombela

@bombela I am a bit late to the party, but you seem to be very well-knowledged inthese matters; so I decided to ask you: there is also such a thing as libdwarf++0 - do you know if it is somehow better/worse than libdwarf?

mike239x avatar Sep 20 '19 15:09 mike239x

Now idea if better or worse. The summary of the libdwarf++0 package on debian says:

Libelfin is a from-scratch C++11 library for reading ELF binaries and DWARFv4 debug information. Libelfin implements a syntactic layer for DWARF and ELF, but not a semantic layer. Interpreting the information stored in DWARF DIE trees still requires a great deal of understanding of DWARF, but libelfin will make sense of the bytes for you.

bombela avatar Sep 20 '19 18:09 bombela