Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/2] [gdb/testsuite] Add gdb.testsuite/mount-point-map.exp
Date: Wed, 27 Aug 2025 15:14:38 +0200	[thread overview]
Message-ID: <20250827131439.27473-2-tdevries@suse.de> (raw)
In-Reply-To: <20250827131439.27473-1-tdevries@suse.de>

Proc host_file_normalize is structured like this:
...
proc host_file_normalize {filename} {
    if {[ishost *-*-mingw*]} {
        ...
    }

    return [file normalize $filename]
...
so a test-case exercising the mingw specific part can only be run on a mingw host.

Factor out a new proc host_file_normalize_mingw, which can be used on any host
platform.

Add test-case gdb.testsuite/mount-point-map.exp, exercising
host_file_normalize_mingw.

Tested on aarch64-linux and msys2-ucrt64.
---
 .../gdb.testsuite/mount-point-map.exp         | 26 +++++++++
 gdb/testsuite/lib/gdb.exp                     | 54 +++++++++++--------
 2 files changed, 58 insertions(+), 22 deletions(-)
 create mode 100644 gdb/testsuite/gdb.testsuite/mount-point-map.exp

diff --git a/gdb/testsuite/gdb.testsuite/mount-point-map.exp b/gdb/testsuite/gdb.testsuite/mount-point-map.exp
new file mode 100644
index 00000000000..d4c8bfdeff6
--- /dev/null
+++ b/gdb/testsuite/gdb.testsuite/mount-point-map.exp
@@ -0,0 +1,26 @@
+# Copyright 2025 Free Software Foundation, Inc.
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+set unix_to_win {
+    /bin C:/msys64/usr/bin
+    /c C:
+    / C:/msys64
+}
+
+set d1 "/"
+set d2 "C:/msys64/"
+gdb_assert { [host_file_normalize_mingw $d1 $unix_to_win] == $d2 }
+
+set d3 "C:/msys64"
+gdb_assert { [host_file_normalize_mingw $d3 $unix_to_win] == $d3 }
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index d3e2a454902..b7961eb30dc 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -2360,6 +2360,37 @@ proc build_file_normalize {filename} {
     return [file normalize $filename]
 }
 
+# Normalize a file name for the host machine and native Windows GDB.
+# This converts a Unix file name to a Windows filename,
+# per the mount table.  E.g., '/c/foo' (on MSYS2) or '/cygdrive/c/foo'
+# (on Cygwin) is converted to 'c:/foo'.
+
+proc host_file_normalize_mingw {filename unix_to_win} {
+    set filename [host_file_sanitize $filename]
+
+    # If the file name already starts with a drive letter (e.g.,
+    # C:/foo), we're done.  Don't let it fallthrough to "file
+    # normalize", which would misinterpret it as a relative file
+    # name.
+    if {[regexp {^[A-Z]:/} $filename]} {
+	return $filename
+    }
+
+    foreach {unix_filename win_filename} $unix_to_win {
+	set mount_len [string length $unix_filename]
+	if {[string equal -length $mount_len $unix_filename $filename]} {
+	    if {[string length $filename] == $mount_len} {
+		return "$win_filename/"
+	    } elseif {[string index $filename $mount_len] eq "/"} {
+		set rest [string range $filename $mount_len end]
+		return "$win_filename$rest"
+	    }
+	}
+    }
+
+    return [file normalize $filename]
+}
+
 # Normalize a file name for the host machine.  If running native
 # Windows GDB, this converts a Unix file name to a Windows filename,
 # per the mount table.  E.g., '/c/foo' (on MSYS2) or '/cygdrive/c/foo'
@@ -2367,30 +2398,9 @@ proc build_file_normalize {filename} {
 
 proc host_file_normalize {filename} {
     if {[ishost *-*-mingw*]} {
-	set filename [host_file_sanitize $filename]
-
-	# If the file name already starts with a drive letter (e.g.,
-	# C:/foo), we're done.  Don't let it fallthrough to "file
-	# normalize", which would misinterpret it as a relative file
-	# name.
-	if {[regexp {^[A-Z]:/} $filename]} {
-	    return $filename
-	}
-
 	# Get Unix => Windows map.
 	lassign [get_mount_point_map] _ unix_to_win
-
-	foreach {unix_filename win_filename} $unix_to_win {
-	    set mount_len [string length $unix_filename]
-	    if {[string equal -length $mount_len $unix_filename $filename]} {
-		if {[string length $filename] == $mount_len} {
-		    return "$win_filename/"
-		} elseif {[string index $filename $mount_len] eq "/"} {
-		    set rest [string range $filename $mount_len end]
-		    return "$win_filename$rest"
-		}
-	    }
-	}
+	return [host_file_normalize_mingw $filename $unix_to_win]
     }
 
     return [file normalize $filename]
-- 
2.43.0


  reply	other threads:[~2025-08-27 13:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-27 13:14 [PATCH 0/2] [gdb/testsuite] Fix host_file_normalize with host mingw Tom de Vries
2025-08-27 13:14 ` Tom de Vries [this message]
2025-08-27 13:14 ` [PATCH 2/2] [gdb/testsuite] Fix host_file_normalize_mingw Tom de Vries
2025-08-29 19:47   ` Pedro Alves
2025-09-02  9:18     ` Tom de Vries
2025-09-02 11:34       ` Pedro Alves
2025-09-02 11:44         ` Tom de Vries
2025-09-02 12:06           ` Pedro Alves

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=20250827131439.27473-2-tdevries@suse.de \
    --to=tdevries@suse.de \
    --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