Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Gary Benson <gbenson@redhat.com>
To: gdb-patches@sourceware.org
Cc: "Cédric Buissart" <cedric.buissart@gmail.com>
Subject: [PATCH 4/5] Add "target:" filename handling to find_separate_debug_file
Date: Tue, 16 Jun 2015 09:48:00 -0000	[thread overview]
Message-ID: <1434447768-17328-5-git-send-email-gbenson@redhat.com> (raw)
In-Reply-To: <1434447768-17328-1-git-send-email-gbenson@redhat.com>

This commit updates find_separate_debug_file to handle filenames
prefixed with "target:".  The same-directory and DEBUG_SUBDIRECTORY
locations are checked with the prefix if supplied.  The debugdir
location is checked both with and without the prefix if one is
supplied.  This makes GDB able to fetch separate debug files from
remote targets and from inferiors in containers.

gdb/ChangeLog:

	* gdb/symfile.c (build_debug_file_name): New argument "prefix".
	(find_separate_debug_file): Separate TARGET_SYSROOT_PREFIX from
	dir.  In debugdir loop, also try location prepended with dir's
	prefix if one was supplied.
---
 gdb/ChangeLog |    7 +++++++
 gdb/symfile.c |   47 +++++++++++++++++++++++++++++++++++++----------
 2 files changed, 44 insertions(+), 10 deletions(-)

diff --git a/gdb/symfile.c b/gdb/symfile.c
index bae144e..0cc940a 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1434,16 +1434,17 @@ separate_debug_file_exists (const char *name, unsigned long crc,
 /* Build the filename of a separate debug file from an arbitrary
    number of components.  Returns an xmalloc'd string that must
    be be freed by the caller.  The final argument of this function
-   must be NULL to mark the end the argument list.  */
+   must be NULL to mark the end the argument list.  PREFIX will
+   be prepended to the result with no directory separator.  */
 
 static char *
-build_debug_file_name (const char *first, ...)
+build_debug_file_name (const char *prefix, const char *first, ...)
 {
   va_list ap;
   const char *arg, *last;
   VEC (char_ptr) *args = NULL;
   struct cleanup *back_to = make_cleanup_free_char_ptr_vec (args);
-  int bufsiz = 0;
+  int bufsiz = strlen (prefix);
   char *buf, *tmp;
   int i;
 
@@ -1495,7 +1496,7 @@ build_debug_file_name (const char *first, ...)
   bufsiz += 1;  /* Terminator.  */
 
   buf = xmalloc (bufsiz);
-  buf[0] = '\0';
+  strcpy (buf, prefix);
   for (i = 0; VEC_iterate (char_ptr, args, i, tmp); i++)
     strcat (buf, tmp);
   gdb_assert (bufsiz == strlen (buf) + 1);
@@ -1537,15 +1538,25 @@ find_separate_debug_file (const char *dir,
   struct cleanup *back_to;
   int ix;
   const char *altdir = NULL;
+  const char *no_prefix = "";
+  const char *dir_prefix = no_prefix;
+
+  /* Separate TARGET_SYSROOT_PREFIX from directory.  */
+  if (is_target_filename (dir))
+    {
+      dir_prefix = TARGET_SYSROOT_PREFIX;
+      dir += strlen (dir_prefix);
+    }
 
   /* First try in the same directory as the original file.  */
-  debugfile = build_debug_file_name (dir, debuglink, NULL);
+  debugfile = build_debug_file_name (dir_prefix, dir, debuglink, NULL);
   if (separate_debug_file_exists (debugfile, crc32, objfile))
     return debugfile;
   xfree (debugfile);
 
   /* Then try in the subdirectory named DEBUG_SUBDIRECTORY.  */
-  debugfile = build_debug_file_name (dir, DEBUG_SUBDIRECTORY,
+  debugfile = build_debug_file_name (dir_prefix, dir,
+				     DEBUG_SUBDIRECTORY,
 				     debuglink, NULL);
   if (separate_debug_file_exists (debugfile, crc32, objfile))
     return debugfile;
@@ -1575,8 +1586,24 @@ find_separate_debug_file (const char *dir,
 
   for (ix = 0; VEC_iterate (char_ptr, debugdir_vec, ix, debugdir); ++ix)
     {
-      debugfile = build_debug_file_name (debugdir, dir, debuglink,
-					 NULL);
+      /* First try with TARGET_SYSROOT_PREFIX if that's how DIR was
+	 supplied.  */
+      if (dir_prefix != no_prefix)
+	{
+	  debugfile = build_debug_file_name (dir_prefix, debugdir, dir,
+					     debuglink, NULL);
+	  if (separate_debug_file_exists (debugfile, crc32, objfile))
+	    {
+	      do_cleanups (back_to);
+	      return debugfile;
+	    }
+	  xfree (debugfile);
+	}
+
+      /* Try the same location but without TARGET_SYSROOT_PREFIX
+	 (i.e. on the local filesystem).  */
+      debugfile = build_debug_file_name (no_prefix, debugdir, dir,
+					 debuglink, NULL);
       if (separate_debug_file_exists (debugfile, crc32, objfile))
 	{
 	  do_cleanups (back_to);
@@ -1586,8 +1613,8 @@ find_separate_debug_file (const char *dir,
 
       if (altdir != NULL)
 	{
-	  debugfile = build_debug_file_name (debugdir, altdir,
-					     debuglink, NULL);
+	  debugfile = build_debug_file_name (no_prefix, debugdir,
+					     altdir, debuglink, NULL);
 	  if (separate_debug_file_exists (debugfile, crc32, objfile))
 	    {
 	      do_cleanups (back_to);
-- 
1.7.1


  parent reply	other threads:[~2015-06-16  9:48 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-16  9:42 [PATCH 0/5] Separate debugfile improvements Gary Benson
2015-06-16  9:42 ` [PATCH 3/5] Update how find_separate_debug_file handles CANON_DIR argument Gary Benson
2015-07-01 11:13   ` Pedro Alves
2015-06-16  9:42 ` [PATCH 1/5] Introduce build_debug_file_name Gary Benson
2015-06-16 14:47   ` Eli Zaretskii
2015-06-17  9:47     ` Gary Benson
2015-06-17 16:42       ` Eli Zaretskii
2015-06-18 10:55         ` Gary Benson
2015-06-18 12:11           ` Eli Zaretskii
2015-06-19  8:32             ` Gary Benson
2015-07-01 11:05   ` Pedro Alves
2015-07-02 11:18     ` Gary Benson
2015-07-02 11:38       ` Pedro Alves
2015-07-02 13:53         ` Gary Benson
2015-07-25 16:20   ` Jan Kratochvil
2015-06-16  9:42 ` [PATCH 2/5] Pre-strip now-unnecessary trailing directory separators Gary Benson
2015-07-01 13:45   ` Pedro Alves
2015-06-16  9:48 ` Gary Benson [this message]
2015-07-01 13:35   ` [PATCH 4/5] Add "target:" filename handling to find_separate_debug_file Pedro Alves
2015-07-23 14:33     ` Gary Benson
2015-07-24 10:28       ` Gary Benson
2015-07-24 11:54         ` Gary Benson
2015-07-25 18:15   ` Jan Kratochvil
2015-06-16  9:50 ` [PATCH 5/5] Also look for debug files in gdb_sysroot Gary Benson
2015-07-01 13:45   ` Pedro Alves
2015-06-23  8:44 ` [PING][PATCH 0/5] Separate debugfile improvements Gary Benson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1434447768-17328-5-git-send-email-gbenson@redhat.com \
    --to=gbenson@redhat.com \
    --cc=cedric.buissart@gmail.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox