Remove target: prefix from gdb_sysroot in find_separate_debug_file

I noticed that, when using gdbserver, gdb might print:

Reading /usr/lib/debug/lib64//libcap.so.2.48-2.48-4.fc36.x86_64.debug from remote target...
Reading target:/usr/lib/debug/lib64//libcap.so.2.48-2.48-4.fc36.x86_64.debug from remote target...

The second line has the "target:" prefix, but from the code it's clear
that this string is being passed verbatim to gdbserver -- which seems
wrong.

I filed PR remote/29929 for this.

The problem here is that find_separate_debug_file uses gdb_sysroot
without checking to see if it starts with the "target:" prefix.  This
patch changes this code to be a little more careful.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29929
This commit is contained in:
Tom Tromey 2022-12-21 13:57:45 -07:00
parent b9877acc81
commit dacf80765d

View file

@ -1470,19 +1470,32 @@ find_separate_debug_file (const char *dir,
return debugfile; return debugfile;
/* If the file is in the sysroot, try using its base path in /* If the file is in the sysroot, try using its base path in
the sysroot's global debugfile directory. */ the sysroot's global debugfile directory. GDB_SYSROOT
debugfile = target_prefix ? "target:" : ""; might refer to a target: path; we strip the "target:"
debugfile += gdb_sysroot; prefix -- but if that would yield the empty string, we
debugfile += debugdir; don't bother at all, because that would just give the
debugfile += "/"; same result as above. */
debugfile += base_path; if (gdb_sysroot != "target:")
debugfile += "/"; {
debugfile += debuglink; debugfile = target_prefix ? "target:" : "";
if (startswith (gdb_sysroot, "target:"))
{
std::string root = gdb_sysroot.substr (strlen ("target:"));
gdb_assert (!root.empty ());
debugfile += root;
}
else
debugfile += gdb_sysroot;
debugfile += debugdir;
debugfile += "/";
debugfile += base_path;
debugfile += "/";
debugfile += debuglink;
if (separate_debug_file_exists (debugfile, crc32, objfile)) if (separate_debug_file_exists (debugfile, crc32, objfile))
return debugfile; return debugfile;
}
} }
} }
return std::string (); return std::string ();