diff --git a/backward.hpp b/backward.hpp index 19d5ba3..1f61af4 100644 --- a/backward.hpp +++ b/backward.hpp @@ -261,6 +261,7 @@ #else #include #endif +#include #endif #if (BACKWARD_HAS_BACKTRACE == 1) || (BACKWARD_HAS_BACKTRACE_SYMBOL == 1) @@ -2152,7 +2153,7 @@ class TraceResolverLinuxImpl } trace.object_filename = resolve_exec_path(symbol_info); - dwarf_fileobject &fobj = load_object_with_dwarf(symbol_info.dli_fname); + dwarf_fileobject &fobj = load_object_with_dwarf(symbol_info.dli_fname, trace.object_filename); if (!fobj.dwarf_handle) { return trace; // sad, we couldn't load the object :( } @@ -2312,7 +2313,7 @@ class TraceResolverLinuxImpl return strcmp(a, b) == 0; } - dwarf_fileobject &load_object_with_dwarf(const std::string &filename_object) { + dwarf_fileobject &load_object_with_dwarf(const std::string &filename_object, const std::string &object_filename) { if (!_dwarf_loaded) { // Set the ELF library operating version @@ -2431,9 +2432,7 @@ class TraceResolverLinuxImpl ELF_GET_DATA(32) } else if (e_ident[EI_CLASS] == ELFCLASS64) { // libelf might have been built without 64 bit support -#if __LIBELF64 ELF_GET_DATA(64) -#endif } if (!debuglink.empty()) { @@ -2441,7 +2440,17 @@ class TraceResolverLinuxImpl // file instead. If we can't open the file, then return // the elf handle we had already opened. dwarf_file_t debuglink_file; - debuglink_file.reset(open(debuglink.c_str(), O_RDONLY)); + { + char* object_filename_copy = strdup(object_filename.c_str()); + const std::string directory_path = std::string(dirname(object_filename_copy)); + free(object_filename_copy); + debuglink_file.reset( + open((directory_path + '/' + debuglink).c_str(), O_RDONLY)); + if (debuglink_file.get() < 0) { + debuglink_file.reset(open( + (directory_path + "/.debug/" + debuglink).c_str(), O_RDONLY)); + } + } if (debuglink_file.get() > 0) { dwarf_elf_t debuglink_elf; debuglink_elf.reset(elf_begin(debuglink_file.get(), ELF_C_READ, NULL));