]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add gdb.testsuite/mount-point-map.exp
authorTom de Vries <tdevries@suse.de>
Tue, 2 Sep 2025 10:41:02 +0000 (11:41 +0100)
committerPedro Alves <pedro@palves.net>
Tue, 2 Sep 2025 12:01:53 +0000 (13:01 +0100)
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

gdb/testsuite/gdb.testsuite/mount-point-map.exp [new file with mode: 0644]
gdb/testsuite/lib/gdb.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 (file)
index 0000000..e36f9f0
--- /dev/null
@@ -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"
index 9970af675d0316804c8ba4dbff40b1535d4360a1..1f59284bfb19aec6407771d5332531c64dbe34c5 100644 (file)
@@ -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]