ianlancetaylor / libbacktrace

A C library that may be linked into a C/C++ program to produce symbolic backtraces

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Backtrace for shared libraries: difference between elf and pecoff

krlmlr opened this issue · comments

In my use case, I don't care about symbols/debug info in the main executable, only for the shared libraries loaded during run time. Everything works fine on Linux x64, which I believe uses elf.c. On MSYS, with pecoff.c, I only get symbols/debug info for the module that I pass as the filename argument to backtrace_create_state(). (I can pass the path to a shared library to backtrace_create_state(), and the file+line information is extracted from there but not from the other shared libraries loaded from the process.)

Could you please shed some light on the difference in the observed behavior? Does elf.c iterate over all loaded libraries, and pecoff.c not? What's the best way to resolve this?

Reading backtrace_initialize() in elf.c, indeed it uses dl_iterate_phdr() to iterate over all open libraries. It has done so since the beginning, I can't find anything similar in pecoff.c .

I understand that enumerating libraries and address spaces is difficult to do in a portable way, and that dl_iterate_phdr() is not available on MSYS. To achieve this, I have wrapped code from gperftools in https://github.com/r-prof/procmaps/, the main logic is in sysinfo.cc.

Is there a better way to portably enumerate loaded libraries and address spaces? Would you support this functionality in libbacktrace?

I think it would be reason for the the libbacktrace pecoff.c file to call CreateToolhelp32Snapshot on Windows.

I've created a patch series at https://gcc.gnu.org/pipermail/gcc-patches/2022-December/608031.html which solves this issue.