This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix lookup of separate debug file on MS-Windows


If you put the separate debug file in a global debug directory, GDB on
MS-Windows will currently fail to find it.  This happens because we
obtain the directory to look up the debug file by concatenating the
debug directory name with the leading directories of the executable,
and the latter includes the drive letter on MS-Windows.  So we get an
invalid file name like

   d:/usr/lib/debug/d:/usr/bin/foo.debug

The patch below fixes that:

--- gdb/symfile.c~0	2019-03-27 00:52:05.000000000 +0200
+++ gdb/symfile.c	2019-04-18 13:19:05.231697600 +0300
@@ -1443,6 +1443,18 @@ find_separate_debug_file (const char *di
     = dirnames_to_char_ptr_vec (debug_file_directory);
   gdb::unique_xmalloc_ptr<char> canon_sysroot = gdb_realpath (gdb_sysroot);
 
+  /* MS-Windows/MS-DOS don't allow colons in file names; we must strip
+     the drive letter, so that the file name resulting from splicing
+     below will be valid.  */
+  if (HAS_DRIVE_SPEC (dir_notarget))
+    {
+      dir_notarget = STRIP_DRIVE_SPEC (dir_notarget);
+      /* We will append a slash to debugdir, so remove the leading
+	 slash as well.  */
+      if (IS_DIR_SEPARATOR (dir_notarget[0]))
+	dir_notarget++;
+    }
+
   for (const gdb::unique_xmalloc_ptr<char> &debugdir : debugdir_vec)
     {
       debugfile = target_prefix ? "target:" : "";


OK to commit to both branches (with the necessary ChangeLog entries)?

Btw, the removal of the leading slash of dir_notarget could
potentially benefit Posix systems as well.  Or maybe we should not
append the literal slash in this snippet from
find_separate_debug_file:

      debugfile = target_prefix ? "target:" : "";
      debugfile += debugdir.get ();
      debugfile += "/";  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
      debugfile += dir_notarget;
      debugfile += debuglink;

since AFAICT dir_notarget will always begin with a slash (I added a
test for that because I wasn't sure that is indeed so).


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]