From: Tom de Vries Date: Tue, 2 Sep 2025 10:41:02 +0000 (+0100) Subject: Add gdb.testsuite/mount-point-map.exp X-Git-Tag: gdb-17-branchpoint~94 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2ffc998813e84365505a4d8835a1c28d279fa382;p=thirdparty%2Fbinutils-gdb.git 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 Change-Id: Ia130de5c12c940852b6367c422d04896863bfc02 --- 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..e36f9f0893b --- /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 . + +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 9970af675d0..1f59284bfb1 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]