]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: avoid duplicate search in build_id_to_bfd_suffix
authorAndrew Burgess <aburgess@redhat.com>
Thu, 23 May 2024 17:11:55 +0000 (18:11 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Tue, 11 Jun 2024 19:41:16 +0000 (20:41 +0100)
In build_id_to_bfd_suffix we look in each debug-file-directory for a
file matching the required build-id.

If we don't find one then we add the sysroot and perform the search
again.

However, the default sysroot is 'target:', and for a native target
this just means to search on the local machine.  So by default, if the
debug information is not present, then we end up searching each
location twice.

I think we only need to perform the "with sysroot" check if either:

 1. The sysroot is something other than 'target:'.  If the user has
 set it to '/some/directory' then we should check this sysroot.  Or if
 the user has set it to 'target:/some/other_directory', this is also
 worth checking.

 2. If the sysroot is 'target:', but the target's filesystem is not
 local (i.e. the user is connected to a remote target), then we should
 check using the sysroot as this will be looking on the remote
 machine.

There's no tests for this as the whole point here is that I'm removing
duplicate work.  No test regressions were seen though.

There should be no user visible changes after this commit.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/build-id.c

index 41667d5e5cf3dd9fb3a9f778fb56d21a2e3485c0..fe0494ae54e54b399fc52ff480086982d1e1326c 100644 (file)
@@ -176,9 +176,15 @@ 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".
 
-      if (!gdb_sysroot.empty ())
+        If the sysroot is 'target:' and the target filesystem is local to
+        GDB then 'target:/path/to/check' becomes '/path/to/check' which
+        we just checked above.  */
+
+      if (!gdb_sysroot.empty ()
+         && (gdb_sysroot != TARGET_SYSROOT_PREFIX
+             || !target_filesystem_is_local ()))
        {
          link = gdb_sysroot + link;
          debug_bfd = build_id_to_debug_bfd_1 (link, build_id_len, build_id);