public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Remove target: prefix from gdb_sysroot in find_separate_debug_file
@ 2022-12-21 20:59 Tom Tromey
  2022-12-22 19:32 ` John Baldwin
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2022-12-21 20:59 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

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
---
 gdb/symfile.c | 37 +++++++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 12 deletions(-)

diff --git a/gdb/symfile.c b/gdb/symfile.c
index eb27668f9d3..46f4dd28fc1 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1470,19 +1470,32 @@ find_separate_debug_file (const char *dir,
 	    return debugfile;
 
 	  /* If the file is in the sysroot, try using its base path in
-	     the sysroot's global debugfile directory.  */
-	  debugfile = target_prefix ? "target:" : "";
-	  debugfile += gdb_sysroot;
-	  debugfile += debugdir;
-	  debugfile += "/";
-	  debugfile += base_path;
-	  debugfile += "/";
-	  debugfile += debuglink;
-
-	  if (separate_debug_file_exists (debugfile, crc32, objfile))
-	    return debugfile;
+	     the sysroot's global debugfile directory.  GDB_SYSROOT
+	     might refer to a target: path; we strip the "target:"
+	     prefix -- but if that would yield the empty string, we
+	     don't bother at all, because that would just give the
+	     same result as above.  */
+	  if (gdb_sysroot != "target:")
+	    {
+	      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))
+		return debugfile;
+	    }
 	}
-
     }
 
   return std::string ();
-- 
2.38.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Remove target: prefix from gdb_sysroot in find_separate_debug_file
  2022-12-21 20:59 [PATCH] Remove target: prefix from gdb_sysroot in find_separate_debug_file Tom Tromey
@ 2022-12-22 19:32 ` John Baldwin
  0 siblings, 0 replies; 2+ messages in thread
From: John Baldwin @ 2022-12-22 19:32 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 12/21/22 12:59 PM, Tom Tromey via Gdb-patches wrote:
> 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.

Thanks, LGTM.  I added this additional use of gdb_sysroot in
402d2bfec425f29c5b54089d5ff98ca9a1b8ec27 and hadn't realized it
could contain a "target:" prefix at the time.

-- 
John Baldwin


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-22 19:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-21 20:59 [PATCH] Remove target: prefix from gdb_sysroot in find_separate_debug_file Tom Tromey
2022-12-22 19:32 ` John Baldwin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).