aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2025-09-02 11:41:02 +0100
committerPedro Alves <pedro@palves.net>2025-09-02 13:01:53 +0100
commit2ffc998813e84365505a4d8835a1c28d279fa382 (patch)
tree2be4afd29be542eebaf011a08d9edf428efd0499
parent8f9ec03f819f40515b6f354b3d44e5c334fe6652 (diff)
downloadbinutils-2ffc998813e84365505a4d8835a1c28d279fa382.zip
binutils-2ffc998813e84365505a4d8835a1c28d279fa382.tar.gz
binutils-2ffc998813e84365505a4d8835a1c28d279fa382.tar.bz2
Add gdb.testsuite/mount-point-map.exp
Proc host_file_normalize is structured like this: ... proc host_file_normalize {filename} { if {[ishost *-*-mingw*]} { ... } return [file normalize $filename] ... so a testcase 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 testcase gdb.testsuite/mount-point-map.exp, exercising host_file_normalize_mingw. Tested on aarch64-linux, x86-64-linux, msys2-ucrt64, and msys2-mingw. Co-Authored-By: Pedro Alves <pedro@palves.net> Change-Id: Ia130de5c12c940852b6367c422d04896863bfc02
-rw-r--r--gdb/testsuite/gdb.testsuite/mount-point-map.exp33
-rw-r--r--gdb/testsuite/lib/gdb.exp54
2 files changed, 65 insertions, 22 deletions
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 0000000..e36f9f0
--- /dev/null
+++ b/gdb/testsuite/gdb.testsuite/mount-point-map.exp
@@ -0,0 +1,33 @@
+# 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
+}
+
+# Test that FROM is normalized to TO.
+
+proc test {from to} {
+ set got [host_file_normalize_mingw $from $::unix_to_win]
+ verbose -log "input: $from"
+ verbose -log "expected: $to"
+ verbose -log "got: $got"
+ gdb_assert {$got == $to} $from
+}
+
+test "/" "C:/msys64/"
+
+test "C:/msys64" "C:/msys64"
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 9970af6..1f59284 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]