diff mbox

[3/5] Update how find_separate_debug_file handles CANON_DIR argument

Message ID 1434447768-17328-4-git-send-email-gbenson@redhat.com
State New
Headers show

Commit Message

Gary Benson June 16, 2015, 9:42 a.m. UTC
find_separate_debug_file's CANON_DIR argument is used to create an
alternate location to search for debug files.  This commit moves
that logic out of the loop it's in and introduces a new variable
altdir to hold the generated alternate location.  A check is added
to inhibit the altdir search if alternate location is the same as
the regular location specified in DIR.  A check was also added for
gdb_sysroot == NULL, which the original code was missing.

gdb/ChangeLog:

	* gdb/symfile.c (find_separate_debug_file): Move canon_dir
	logic out of loop.  Add check for NULL gdb_sysroot.  Don't
	check the same location twice.
---
 gdb/ChangeLog |    6 ++++++
 gdb/symfile.c |   25 +++++++++++++++++--------
 2 files changed, 23 insertions(+), 8 deletions(-)

Comments

Pedro Alves July 1, 2015, 11:13 a.m. UTC | #1
On 06/16/2015 10:42 AM, Gary Benson wrote:
> find_separate_debug_file's CANON_DIR argument is used to create an
> alternate location to search for debug files.  This commit moves
> that logic out of the loop it's in and introduces a new variable
> altdir to hold the generated alternate location.  A check is added
> to inhibit the altdir search if alternate location is the same as
> the regular location specified in DIR.  A check was also added for
> gdb_sysroot == NULL, which the original code was missing.

I think the "gdb_sysroot != NULL" check is no longer necessary, right?

Otherwise looks fine.

Thanks,
Pedro Alves
diff mbox

Patch

diff --git a/gdb/symfile.c b/gdb/symfile.c
index 77aaeed..bae144e 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1536,6 +1536,7 @@  find_separate_debug_file (const char *dir,
   VEC (char_ptr) *debugdir_vec;
   struct cleanup *back_to;
   int ix;
+  const char *altdir = NULL;
 
   /* First try in the same directory as the original file.  */
   debugfile = build_debug_file_name (dir, debuglink, NULL);
@@ -1558,6 +1559,20 @@  find_separate_debug_file (const char *dir,
   debugdir_vec = dirnames_to_char_ptr_vec (debug_file_directory);
   back_to = make_cleanup_free_char_ptr_vec (debugdir_vec);
 
+  /* If the file is in the sysroot, try its base path in the
+     global debugfile directory as an alternate location.  */
+  if (canon_dir != NULL
+      && gdb_sysroot != NULL && *gdb_sysroot != '\0'
+      && filename_ncmp (canon_dir, gdb_sysroot,
+			strlen (gdb_sysroot)) == 0
+      && IS_DIR_SEPARATOR (canon_dir[strlen (gdb_sysroot)]))
+    {
+      altdir = canon_dir + strlen (gdb_sysroot);
+
+      if (strcmp (altdir, dir) == 0)
+	altdir = NULL;
+    }
+
   for (ix = 0; VEC_iterate (char_ptr, debugdir_vec, ix, debugdir); ++ix)
     {
       debugfile = build_debug_file_name (debugdir, dir, debuglink,
@@ -1569,15 +1584,9 @@  find_separate_debug_file (const char *dir,
 	}
       xfree (debugfile);
 
-      /* If the file is in the sysroot, try using its base path in the
-	 global debugfile directory.  */
-      if (canon_dir != NULL
-	  && filename_ncmp (canon_dir, gdb_sysroot,
-			    strlen (gdb_sysroot)) == 0
-	  && IS_DIR_SEPARATOR (canon_dir[strlen (gdb_sysroot)]))
+      if (altdir != NULL)
 	{
-	  debugfile = build_debug_file_name (debugdir, canon_dir
-					     + strlen (gdb_sysroot),
+	  debugfile = build_debug_file_name (debugdir, altdir,
 					     debuglink, NULL);
 	  if (separate_debug_file_exists (debugfile, crc32, objfile))
 	    {