--- /dev/null
+# 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"
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'
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]