diff options
author | Daniel Black <daniel@mariadb.org> | 2021-10-18 17:06:47 +1100 |
---|---|---|
committer | Simon Marchi <simon.marchi@efficios.com> | 2021-10-19 13:30:00 -0400 |
commit | 4a2f674a688df474639066922f4ce70ce97b30d2 (patch) | |
tree | c540bbb00b0f938700daa9e4672c80ab48335a11 /gdb/build-id.c | |
parent | cf487499e0d7ef64ab63d6c76bf298bfaf64b980 (diff) | |
download | gdb-4a2f674a688df474639066922f4ce70ce97b30d2.zip gdb-4a2f674a688df474639066922f4ce70ce97b30d2.tar.gz gdb-4a2f674a688df474639066922f4ce70ce97b30d2.tar.bz2 |
Fix PR gdb/17917 Lookup build-id in remote binaries
GDB doesn't support loading debug files using build-id from remote
target filesystems.
This is the case when gdbserver attached to a process and a gdb target
remote occurs over tcp.
With this change we make build-id lookups possible:
(gdb) show debug-file-directory
The directory where separate debug symbols are searched for is "/usr/local/lib/debug".
(gdb) set debug-file-directory /usr/lib/debug
(gdb) show sysroot
The current system root is "target:".
(gdb) target extended-remote :46615
Remote debugging using :46615
warning: Can not parse XML target description; XML support was disabled at compile time
Reading /usr/sbin/mariadbd from remote target...
warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.
Reading /usr/sbin/mariadbd from remote target...
Reading symbols from target:/usr/sbin/mariadbd...
Reading /usr/lib/debug/.build-id/6e/0a874dca5a7ff831396ddc0785d939a192efe3.debug from remote target...
Reading /usr/lib/debug/.build-id/6e/0a874dca5a7ff831396ddc0785d939a192efe3.debug from remote target...
Reading symbols from target:/usr/lib/debug/.build-id/6e/0a874dca5a7ff831396ddc0785d939a192efe3.debug...
Reading /lib/x86_64-linux-gnu/libpcre2-8.so.0 from remote target...
...
Before this change, the lookups would have been (GNU gdb (GDB) Fedora 10.2-3.fc34):
(gdb) target extended-remote :46615
Remote debugging using :46615
Reading /usr/sbin/mariadbd from remote target...
warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.
Reading /usr/sbin/mariadbd from remote target...
Reading symbols from target:/usr/sbin/mariadbd...
Reading /usr/sbin/0a874dca5a7ff831396ddc0785d939a192efe3.debug from remote target...
Reading /usr/sbin/.debug/0a874dca5a7ff831396ddc0785d939a192efe3.debug from remote target...
Reading /usr/lib/debug//usr/sbin/0a874dca5a7ff831396ddc0785d939a192efe3.debug from remote target...
Reading /usr/lib/debug/usr/sbin//0a874dca5a7ff831396ddc0785d939a192efe3.debug from remote target...
Reading target:/usr/lib/debug/usr/sbin//0a874dca5a7ff831396ddc0785d939a192efe3.debug from remote target...
Missing separate debuginfo for target:/usr/sbin/mariadbd
Try: dnf --enablerepo='*debug*' install /usr/lib/debug/.build-id/6e/0a874dca5a7ff831396ddc0785d939a192efe3.debug
(No debugging symbols found in target:/usr/sbin/mariadbd)
Observe it didn't look for
/usr/lib/debug/.build-id/6e/0a874dca5a7ff831396ddc0785d939a192efe3.debug
on the remote target (where it is) and expected them to be installed
locally.
As a minor optimization, this also changes the build-id lookup such that
if sysroot is empty, no second lookup of the same location is performed.
Change-Id: I5181696d271c325a25a0805a8defb8ab7f9b3f55
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17917
Diffstat (limited to 'gdb/build-id.c')
-rw-r--r-- | gdb/build-id.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/gdb/build-id.c b/gdb/build-id.c index 553d6ce..d68b7a7 100644 --- a/gdb/build-id.c +++ b/gdb/build-id.c @@ -81,9 +81,15 @@ build_id_to_debug_bfd_1 (const std::string &link, size_t build_id_len, } /* lrealpath() is expensive even for the usually non-existent files. */ - gdb::unique_xmalloc_ptr<char> filename; - if (access (link.c_str (), F_OK) == 0) - filename.reset (lrealpath (link.c_str ())); + gdb::unique_xmalloc_ptr<char> filename_holder; + const char *filename = nullptr; + if (startswith (link, TARGET_SYSROOT_PREFIX)) + filename = link.c_str (); + else if (access (link.c_str (), F_OK) == 0) + { + filename_holder.reset (lrealpath (link.c_str ())); + filename = filename_holder.get (); + } if (filename == NULL) { @@ -94,7 +100,7 @@ build_id_to_debug_bfd_1 (const std::string &link, size_t build_id_len, } /* We expect to be silent on the non-existing files. */ - gdb_bfd_ref_ptr debug_bfd = gdb_bfd_open (filename.get (), gnutarget); + gdb_bfd_ref_ptr debug_bfd = gdb_bfd_open (filename, gnutarget); if (debug_bfd == NULL) { @@ -162,12 +168,9 @@ build_id_to_bfd_suffix (size_t build_id_len, const bfd_byte *build_id, /* Try to look under the sysroot as well. If the sysroot is "/the/sysroot", it will give - "/the/sysroot/usr/lib/debug/.build-id/ab/cdef.debug". + "/the/sysroot/usr/lib/debug/.build-id/ab/cdef.debug". */ - Don't do it if the sysroot is the target system ("target:"). It - could work in theory, but the lrealpath in build_id_to_debug_bfd_1 - only works with local paths. */ - if (gdb_sysroot != TARGET_SYSROOT_PREFIX) + if (!gdb_sysroot.empty ()) { link = gdb_sysroot + link; debug_bfd = build_id_to_debug_bfd_1 (link, build_id_len, build_id); |