public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb/gdb-8.3-branch] Fix lookup of separate debug file on MS-Windows.
@ 2019-05-03  7:35 Eli Zaretskii
  0 siblings, 0 replies; only message in thread
From: Eli Zaretskii @ 2019-05-03  7:35 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=661f388860346b3747b3b76479f2a784f3b8e9da

commit 661f388860346b3747b3b76479f2a784f3b8e9da
Author: Eli Zaretskii <eliz@gnu.org>
Date:   Fri May 3 10:29:59 2019 +0300

    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 would 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
    
    This commit fixes that by removing the colon of the drive letter,
    thus producing
    
       d:/usr/lib/debug/d/usr/bin/foo.debug
    
    gdb/ChangeLog:
    2019-05-03  Eli Zaretskii  <eliz@gnu.org>
    
    	* symfile.c (find_separate_debug_file): Remove colon from the
    	drive spec of DOS/Windows file names of the target, so that the
    	file name produced from DEBUGDIR and the target's directory will
    	be valid on DOS/Windows systems.
    
    gdb/doc/ChangeLog:
    2019-05-03  Eli Zaretskii  <eliz@gnu.org>
    
    	* gdb.texinfo (Separate Debug Files): Document how the
    	subdirectory of the global debug directory is computed on
    	MS-Windows/MS-DOS.
    
    (cherry picked from commit 5f2459c233faebe8f882e556b2f4a86594a51292)

Diff:
---
 gdb/ChangeLog       |  7 +++++++
 gdb/doc/ChangeLog   |  6 ++++++
 gdb/doc/gdb.texinfo | 10 +++++++---
 gdb/symfile.c       | 22 ++++++++++++++++++++++
 4 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 993abdb..e5dac9b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2019-05-03  Eli Zaretskii  <eliz@gnu.org>
+
+	* symfile.c (find_separate_debug_file): Remove colon from the
+	drive spec of DOS/Windows file names of the target, so that the
+	file name produced from DEBUGDIR and the target's directory will
+	be valid on DOS/Windows systems.
+
 2019-04-30  Joel Brobecker  <brobecker@adacore.com>
 
 	* windows-nat.c (get_windows_debug_event) <EXIT_PROCESS_DEBUG_EVENT>:
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 84865f0..ba631da 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,9 @@
+2019-05-03  Eli Zaretskii  <eliz@gnu.org>
+
+	* gdb.texinfo (Separate Debug Files): Document how the
+	subdirectory of the global debug directory is computed on
+	MS-Windows/MS-DOS.
+
 2019-03-14  Tom Tromey  <tromey@adacore.com>
 
 	* gdb.texinfo (Output Styling): Document "set style source" and
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 27c996b..dba648c 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -19893,9 +19893,13 @@ uses two different methods of looking for the debug file:
 @item
 For the ``debug link'' method, @value{GDBN} looks up the named file in
 the directory of the executable file, then in a subdirectory of that
-directory named @file{.debug}, and finally under each one of the global debug
-directories, in a subdirectory whose name is identical to the leading
-directories of the executable's absolute file name.
+directory named @file{.debug}, and finally under each one of the
+global debug directories, in a subdirectory whose name is identical to
+the leading directories of the executable's absolute file name.  (On
+MS-Windows/MS-DOS, the drive letter of the executable's leading
+directories is converted to a one-letter subdirectory, i.e.@:
+@file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
+filesystems disallow colons in file names.)
 
 @item
 For the ``build ID'' method, @value{GDBN} looks in the
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 6148382..bd79315 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1443,11 +1443,33 @@ find_separate_debug_file (const char *dir,
     = 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
+    convert the drive letter into a one-letter directory, so that the
+    file name resulting from splicing below will be valid.
+
+    FIXME: The below only works when GDB runs on MS-Windows/MS-DOS.
+    There are various remote-debugging scenarios where such a
+    transformation of the drive letter might be required when GDB runs
+    on a Posix host, see
+
+    https://sourceware.org/ml/gdb-patches/2019-04/msg00605.html
+
+    If some of those scenarions need to be supported, we will need to
+    use a different condition for HAS_DRIVE_SPEC and a different macro
+    instead of STRIP_DRIVE_SPEC, which work on Posix systems as well.  */
+  std::string drive;
+  if (HAS_DRIVE_SPEC (dir_notarget))
+    {
+      drive = dir_notarget[0];
+      dir_notarget = STRIP_DRIVE_SPEC (dir_notarget);
+    }
+
   for (const gdb::unique_xmalloc_ptr<char> &debugdir : debugdir_vec)
     {
       debugfile = target_prefix ? "target:" : "";
       debugfile += debugdir.get ();
       debugfile += "/";
+      debugfile += drive;
       debugfile += dir_notarget;
       debugfile += debuglink;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-05-03  7:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-03  7:35 [binutils-gdb/gdb-8.3-branch] Fix lookup of separate debug file on MS-Windows Eli Zaretskii

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).