Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support separate debug symbol files (as in GDB) #253

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alexezeder
Copy link
Contributor

@alexezeder alexezeder commented Jan 17, 2022

backward-cpp already supports loading debug symbols from a separate file. But currently, a separate file with debug symbols has to be located in the current working directory while the GDB documentation says:

For the “debug link” method, GDB looks up the named file in the directory of the executable file, then in a subdirectory of that directory named .debug, and finally under each one of the global debug directories, in a subdirectory whose name is identical to the leading directories of the executable’s absolute file name.

This way, we have to look for a separate debug symbols file differently to replicate GDB behavior.

There are also a few points that I explained inline.

@@ -261,6 +261,7 @@
#else
#include <dlfcn.h>
#endif
#include <libgen.h>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect libgen.h header to exist when libdwarf is available, but that can be not true.

@@ -2431,17 +2432,25 @@ class TraceResolverLinuxImpl<trace_resolver_tag::libdwarf>
ELF_GET_DATA(32)
} else if (e_ident[EI_CLASS] == ELFCLASS64) {
// libelf might have been built without 64 bit support
#if __LIBELF64
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit unrelated, but libelf installed on my PC (it's Arch Linux, but it's true also for Ubuntu 20.04 at least) does not have this definition, so the entire branch is omitted, so no 64-bit data, so no debuglink info. Probably we can work it around in a better way, but this line really stops me from having nice source locations.

Comment on lines +2443 to +2453
{
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));
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are only 2 locations covered since I don't know what global debug directories contain.

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));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect debuglink to have only filename since, according to docs:

The executable contains a debug link that specifies the name of the separate debug info file.

Also, objcopy tool writes only the filename component in the .gnu_debuglink section even if an absolute path is provided:
https://github.com/bminor/binutils-gdb/blob/b4edb38e827974ecdbc4a6712d8b21bf876018a2/bfd/opncls.c#L1707-L1708

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant