Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH 0/2] [gdb/testsuite] Fix host_file_normalize with host mingw
@ 2025-08-27 13:14 Tom de Vries
  2025-08-27 13:14 ` [PATCH 1/2] [gdb/testsuite] Add gdb.testsuite/mount-point-map.exp Tom de Vries
  2025-08-27 13:14 ` [PATCH 2/2] [gdb/testsuite] Fix host_file_normalize_mingw Tom de Vries
  0 siblings, 2 replies; 8+ messages in thread
From: Tom de Vries @ 2025-08-27 13:14 UTC (permalink / raw)
  To: gdb-patches

On msys2-ucrt64 I ran into a problem with proc host_file_normalize.

The first patch factors out a new proc host_file_normalize_mingw, and uses it
in a new test-case that can also be run on for instance aarch64-linux.

The second patch fixes the problem and adds a corresponding test to the
test-case.

Tom de Vries (2):
  [gdb/testsuite] Add gdb.testsuite/mount-point-map.exp
  [gdb/testsuite] Fix host_file_normalize_mingw

 .../gdb.testsuite/mount-point-map.exp         | 30 +++++++++++
 gdb/testsuite/lib/gdb.exp                     | 54 +++++++++++--------
 2 files changed, 62 insertions(+), 22 deletions(-)
 create mode 100644 gdb/testsuite/gdb.testsuite/mount-point-map.exp


base-commit: 93dfa8e923a06c52a707e19109fef07601f6d114
-- 
2.43.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/2] [gdb/testsuite] Add gdb.testsuite/mount-point-map.exp
  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
  2025-08-27 13:14 ` [PATCH 2/2] [gdb/testsuite] Fix host_file_normalize_mingw Tom de Vries
  1 sibling, 0 replies; 8+ messages in thread
From: Tom de Vries @ 2025-08-27 13:14 UTC (permalink / raw)
  To: gdb-patches

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/2] [gdb/testsuite] Fix host_file_normalize_mingw
  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 ` [PATCH 1/2] [gdb/testsuite] Add gdb.testsuite/mount-point-map.exp Tom de Vries
@ 2025-08-27 13:14 ` Tom de Vries
  2025-08-29 19:47   ` Pedro Alves
  1 sibling, 1 reply; 8+ messages in thread
From: Tom de Vries @ 2025-08-27 13:14 UTC (permalink / raw)
  To: gdb-patches

I ran the testsuite on msys2-ucrt64 with mount point map:
...
  /bin C:/msys64/usr/bin
  /c   C:
  /    C:/msys64
...
and ran into the problem that host_file_normalize didn't translate:
...
/home/user/gdb/build/gdb/testsuite/temp/n/x
...
into:
...
C:/msys64/home/user/gdb/build/gdb/testsuite/temp/n/x
...

Fix this in host_file_normalize_mingw and add a corresponding test in
test-case gdb.testsuite/mount-point-map.exp.

Tested on aarch64-linux and msys2-ucrt64.
---
 gdb/testsuite/gdb.testsuite/mount-point-map.exp | 4 ++++
 gdb/testsuite/lib/gdb.exp                       | 4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/gdb/testsuite/gdb.testsuite/mount-point-map.exp b/gdb/testsuite/gdb.testsuite/mount-point-map.exp
index d4c8bfdeff6..cc070622b13 100644
--- a/gdb/testsuite/gdb.testsuite/mount-point-map.exp
+++ b/gdb/testsuite/gdb.testsuite/mount-point-map.exp
@@ -24,3 +24,7 @@ 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 }
+
+set f1 "/home/user/gdb/build/gdb/testsuite/temp/n/x"
+set f2 "C:/msys64/home/user/gdb/build/gdb/testsuite/temp/n/x"
+gdb_assert { [host_file_normalize_mingw $f1 $unix_to_win] == $f2 }
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index b7961eb30dc..4b0249db70b 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -2381,9 +2381,9 @@ proc host_file_normalize_mingw {filename unix_to_win} {
 	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 "/"} {
+	    } elseif {[string index $filename [expr $mount_len - 1]] eq "/"} {
 		set rest [string range $filename $mount_len end]
-		return "$win_filename$rest"
+		return "$win_filename/$rest"
 	    }
 	}
     }
-- 
2.43.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] [gdb/testsuite] Fix host_file_normalize_mingw
  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
  0 siblings, 1 reply; 8+ messages in thread
From: Pedro Alves @ 2025-08-29 19:47 UTC (permalink / raw)
  To: Tom de Vries, gdb-patches

Hi Tom,

On 2025-08-27 14:14, Tom de Vries wrote:

> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> index b7961eb30dc..4b0249db70b 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -2381,9 +2381,9 @@ proc host_file_normalize_mingw {filename unix_to_win} {
>  	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 "/"} {
> +	    } elseif {[string index $filename [expr $mount_len - 1]] eq "/"} {
>  		set rest [string range $filename $mount_len end]
> -		return "$win_filename$rest"
> +		return "$win_filename/$rest"
>  	    }
>  	}
>      }


Unfortunately, this breaks things for me.
I test on a directory under c:/, and the testsuite broke very visibly.  :-)

For example, the patch makes us mishandle this:

 set f3 "/c/foo/bar"
 set f4 "C:/foo/bar"
 gdb_assert { [host_file_normalize_mingw $f3 $unix_to_win] == $f4 }

Instead of turning $f3 into:
   C:/foo/bar
it turns it into:
   C:/msys64/c/foo/bar

Notice that the "/" mount point is the only one that ends in "/".  This
is even if you try to create one explicitly with a trailing /.  On MSYS2:

 $ mount c:/foo /foo/
 mount: warning - /foo/ does not exist.
 $ mount
 C:/foo on /foo type ntfs (binary,user)
 ...

So I think we need to instead special case the "/" mount point.

And then... while playing with this, I noticed I had done something strange with this case:

  	    if {[string length $filename] == $mount_len} {
  		return "$win_filename/"

The intent was to append the slash when the mount is a drive letter, like 'cygpath -ma' does:

 $ cygpath -ma /c
 C:/

Other cases do not get a trailing slash:

 $ cygpath -ma /c/foo
 C:/foo

I think this is because on Windows, every drive letter has a current directory, and really "C:" means
"current directory of drive letter C:", not "root of C:".  Resolving it to "C:/" makes it unambiguous.

However, I mishandled that, and made the code append the slash whenever the input filename matches
a mount exactly, any mount.

And then I noticed that TCL's "file normalize" on Linux always removes the trailing slash, and since
host_file_normalize is an abstraction for it, I thought host_file_normalize_mingw should do the same.
Likewise for duplicate slashes, "file normalize" gets rid of them.

I was going to give you a suggestion for the root mount fix, and handle the slashes things in a follow
up patch to yours, but fixing the slashes details changes how to address the issue with handling the
root dir, so I ended up doing it all in one patch.  See below.

I changed how one adds tests to your new testcase to a way that I think is much easier to write, read,
and makes gdb.sum results also have some sense.  It also prints some info to gdb.log that helped me
understand what went wrong when a test FAILs.

The "/foo" test I added has the same effect as yours, just with a shorter and simpler filename, that
fits better with the other new tests I added.  What matters is that this case is a file/directory under
a mount point, and I made the testcase test that for every mount point (root, drive letter, other).

I absolutely love the idea of a testcase for this.  It helps so much!  Thanks a lot for starting that.

WDYT?  Does this version work for you?  I smoke tested it here with a few of the testcases that required
tweaking in the patch that added host_file_normalize like gdb.base/source-dir.exp and gdb.base/fullname.exp
and they still passed.

From de4e47323d9e7df1b09cd635bfce902b00b3371b Mon Sep 17 00:00:00 2001
From: Pedro Alves <pedro@palves.net>
Date: Fri, 29 Aug 2025 20:05:48 +0100
Subject: [PATCH] Fix host_file_normalize_mingw

Change-Id: I852a8662f0cb8b0ee4e683e9b157618cf6955477
---
 .../gdb.testsuite/mount-point-map.exp         | 33 ++++++++++++++++---
 gdb/testsuite/lib/gdb.exp                     | 26 +++++++++++++--
 2 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/gdb/testsuite/gdb.testsuite/mount-point-map.exp b/gdb/testsuite/gdb.testsuite/mount-point-map.exp
index d4c8bfdeff6..9e462bb63e9 100644
--- a/gdb/testsuite/gdb.testsuite/mount-point-map.exp
+++ b/gdb/testsuite/gdb.testsuite/mount-point-map.exp
@@ -18,9 +18,32 @@ set unix_to_win {
     / C:/msys64
 }
 
-set d1 "/"
-set d2 "C:/msys64/"
-gdb_assert { [host_file_normalize_mingw $d1 $unix_to_win] == $d2 }
+# Test that FROM is normalized to TO.
 
-set d3 "C:/msys64"
-gdb_assert { [host_file_normalize_mingw $d3 $unix_to_win] == $d3 }
+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
+}
+
+# Drive letters always get a '/' suffix, other Windows file names do
+# not.
+test "/" "C:/msys64"
+test "/c" "C:/"
+test "/bin" "C:/msys64/usr/bin"
+
+# A file name that already starts with a drive letter.
+test "C:/msys64" "C:/msys64"
+
+# A subdir/subfile under each mount.
+test "/foo" "C:/msys64/foo"
+test "/c/foo" "C:/foo"
+test "/bin/foo" "C:/msys64/usr/bin/foo"
+
+# Test slash normalization.
+test "//" "C:/msys64"
+test "/c///foo//bar//" "C:/foo/bar"
+# We don't currently handle UNC paths.
+test "//server///" "C:/msys64/server"
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 18e449ad8a0..17eb00a10f3 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -2374,12 +2374,34 @@ proc host_file_normalize_mingw {filename unix_to_win} {
 	return $filename
     }
 
+    # Collapse all repeated forward slashes.
+    set filename [regsub -all {//+} $filename {/}]
+
+    # Strip trailing slash, except for root.
+    if {$filename ne "/" && [string match */ $filename]} {
+	set filename [string range $filename 0 end-1]
+    }
+
     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/"
+	    if {$unix_filename eq "/"} {
+		if {$filename eq "/"} {
+		    return "$win_filename"
+		} else {
+		    return "$win_filename$filename"
+		}
+	    } elseif {[string length $filename] == $mount_len} {
+		# Like "cygpath -ma" if the file name resolves to a
+		# drive letter, append a slash, to make it unambiguous
+		# that we resolved to the root of the drive and not
+		# the drive's current directory.
+		if {[string match {[A-Za-z]:} $win_filename]} {
+		    return "$win_filename/"
+		} else {
+		    return "$win_filename"
+		}
 	    } elseif {[string index $filename $mount_len] eq "/"} {
 		set rest [string range $filename $mount_len end]
 		return "$win_filename$rest"

-- 
2.50.1



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] [gdb/testsuite] Fix host_file_normalize_mingw
  2025-08-29 19:47   ` Pedro Alves
@ 2025-09-02  9:18     ` Tom de Vries
  2025-09-02 11:34       ` Pedro Alves
  0 siblings, 1 reply; 8+ messages in thread
From: Tom de Vries @ 2025-09-02  9:18 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches

On 8/29/25 21:47, Pedro Alves wrote:
> Hi Tom,
> 
> On 2025-08-27 14:14, Tom de Vries wrote:
> 
>> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
>> index b7961eb30dc..4b0249db70b 100644
>> --- a/gdb/testsuite/lib/gdb.exp
>> +++ b/gdb/testsuite/lib/gdb.exp
>> @@ -2381,9 +2381,9 @@ proc host_file_normalize_mingw {filename unix_to_win} {
>>   	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 "/"} {
>> +	    } elseif {[string index $filename [expr $mount_len - 1]] eq "/"} {
>>   		set rest [string range $filename $mount_len end]
>> -		return "$win_filename$rest"
>> +		return "$win_filename/$rest"
>>   	    }
>>   	}
>>       }
> 
> 
> Unfortunately, this breaks things for me.
> I test on a directory under c:/, and the testsuite broke very visibly.  :-)
> 
> For example, the patch makes us mishandle this:
> 
>   set f3 "/c/foo/bar"
>   set f4 "C:/foo/bar"
>   gdb_assert { [host_file_normalize_mingw $f3 $unix_to_win] == $f4 }
> 
> Instead of turning $f3 into:
>     C:/foo/bar
> it turns it into:
>     C:/msys64/c/foo/bar
> 
> Notice that the "/" mount point is the only one that ends in "/".  This
> is even if you try to create one explicitly with a trailing /.  On MSYS2:
> 
>   $ mount c:/foo /foo/
>   mount: warning - /foo/ does not exist.
>   $ mount
>   C:/foo on /foo type ntfs (binary,user)
>   ...
> 
> So I think we need to instead special case the "/" mount point.
> 
> And then... while playing with this, I noticed I had done something strange with this case:
> 
>    	    if {[string length $filename] == $mount_len} {
>    		return "$win_filename/"
> 
> The intent was to append the slash when the mount is a drive letter, like 'cygpath -ma' does:
> 
>   $ cygpath -ma /c
>   C:/
> 
> Other cases do not get a trailing slash:
> 
>   $ cygpath -ma /c/foo
>   C:/foo
> 
> I think this is because on Windows, every drive letter has a current directory, and really "C:" means
> "current directory of drive letter C:", not "root of C:".  Resolving it to "C:/" makes it unambiguous.
> 
> However, I mishandled that, and made the code append the slash whenever the input filename matches
> a mount exactly, any mount.
> 
> And then I noticed that TCL's "file normalize" on Linux always removes the trailing slash, and since
> host_file_normalize is an abstraction for it, I thought host_file_normalize_mingw should do the same.
> Likewise for duplicate slashes, "file normalize" gets rid of them.
> 
> I was going to give you a suggestion for the root mount fix, and handle the slashes things in a follow
> up patch to yours, but fixing the slashes details changes how to address the issue with handling the
> root dir, so I ended up doing it all in one patch.  See below.
> 
> I changed how one adds tests to your new testcase to a way that I think is much easier to write, read,
> and makes gdb.sum results also have some sense.  It also prints some info to gdb.log that helped me
> understand what went wrong when a test FAILs.
> 
> The "/foo" test I added has the same effect as yours, just with a shorter and simpler filename, that
> fits better with the other new tests I added.  What matters is that this case is a file/directory under
> a mount point, and I made the testcase test that for every mount point (root, drive letter, other).
> 
> I absolutely love the idea of a testcase for this.  It helps so much!  Thanks a lot for starting that.
> 
> WDYT?  Does this version work for you?  I smoke tested it here with a few of the testcases that required
> tweaking in the patch that added host_file_normalize like gdb.base/source-dir.exp and gdb.base/fullname.exp
> and they still passed.
> 

Hi Pedro,

I ran the test-case on both x86_64-linux and msys2-ucrt64, and it passed 
in both cases, so I think it should be fine.

Feel free to commit this together with the first patch, or perhaps to 
combined into one patch.

Given that the second patch now changes the setup of the test-case, I 
think squashing makes more sense.

Thanks,
- Tom

>  From de4e47323d9e7df1b09cd635bfce902b00b3371b Mon Sep 17 00:00:00 2001
> From: Pedro Alves <pedro@palves.net>
> Date: Fri, 29 Aug 2025 20:05:48 +0100
> Subject: [PATCH] Fix host_file_normalize_mingw
> 
> Change-Id: I852a8662f0cb8b0ee4e683e9b157618cf6955477
> ---
>   .../gdb.testsuite/mount-point-map.exp         | 33 ++++++++++++++++---
>   gdb/testsuite/lib/gdb.exp                     | 26 +++++++++++++--
>   2 files changed, 52 insertions(+), 7 deletions(-)
> 
> diff --git a/gdb/testsuite/gdb.testsuite/mount-point-map.exp b/gdb/testsuite/gdb.testsuite/mount-point-map.exp
> index d4c8bfdeff6..9e462bb63e9 100644
> --- a/gdb/testsuite/gdb.testsuite/mount-point-map.exp
> +++ b/gdb/testsuite/gdb.testsuite/mount-point-map.exp
> @@ -18,9 +18,32 @@ set unix_to_win {
>       / C:/msys64
>   }
>   
> -set d1 "/"
> -set d2 "C:/msys64/"
> -gdb_assert { [host_file_normalize_mingw $d1 $unix_to_win] == $d2 }
> +# Test that FROM is normalized to TO.
>   
> -set d3 "C:/msys64"
> -gdb_assert { [host_file_normalize_mingw $d3 $unix_to_win] == $d3 }
> +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
> +}
> +
> +# Drive letters always get a '/' suffix, other Windows file names do
> +# not.
> +test "/" "C:/msys64"
> +test "/c" "C:/"
> +test "/bin" "C:/msys64/usr/bin"
> +
> +# A file name that already starts with a drive letter.
> +test "C:/msys64" "C:/msys64"
> +
> +# A subdir/subfile under each mount.
> +test "/foo" "C:/msys64/foo"
> +test "/c/foo" "C:/foo"
> +test "/bin/foo" "C:/msys64/usr/bin/foo"
> +
> +# Test slash normalization.
> +test "//" "C:/msys64"
> +test "/c///foo//bar//" "C:/foo/bar"
> +# We don't currently handle UNC paths.
> +test "//server///" "C:/msys64/server"
> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> index 18e449ad8a0..17eb00a10f3 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -2374,12 +2374,34 @@ proc host_file_normalize_mingw {filename unix_to_win} {
>   	return $filename
>       }
>   
> +    # Collapse all repeated forward slashes.
> +    set filename [regsub -all {//+} $filename {/}]
> +
> +    # Strip trailing slash, except for root.
> +    if {$filename ne "/" && [string match */ $filename]} {
> +	set filename [string range $filename 0 end-1]
> +    }
> +
>       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/"
> +	    if {$unix_filename eq "/"} {
> +		if {$filename eq "/"} {
> +		    return "$win_filename"
> +		} else {
> +		    return "$win_filename$filename"
> +		}
> +	    } elseif {[string length $filename] == $mount_len} {
> +		# Like "cygpath -ma" if the file name resolves to a
> +		# drive letter, append a slash, to make it unambiguous
> +		# that we resolved to the root of the drive and not
> +		# the drive's current directory.
> +		if {[string match {[A-Za-z]:} $win_filename]} {
> +		    return "$win_filename/"
> +		} else {
> +		    return "$win_filename"
> +		}
>   	    } elseif {[string index $filename $mount_len] eq "/"} {
>   		set rest [string range $filename $mount_len end]
>   		return "$win_filename$rest"
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] [gdb/testsuite] Fix host_file_normalize_mingw
  2025-09-02  9:18     ` Tom de Vries
@ 2025-09-02 11:34       ` Pedro Alves
  2025-09-02 11:44         ` Tom de Vries
  0 siblings, 1 reply; 8+ messages in thread
From: Pedro Alves @ 2025-09-02 11:34 UTC (permalink / raw)
  To: Tom de Vries, gdb-patches

Hi Tom,

On 2025-09-02 10:18, Tom de Vries wrote:

> I ran the test-case on both x86_64-linux and msys2-ucrt64, and it passed in both cases, so I think it should be fine.
> 
> Feel free to commit this together with the first patch, or perhaps to combined into one patch.
> 
> Given that the second patch now changes the setup of the test-case, I think squashing makes more sense.

I tried a combined patch, but it makes it hard to see the changes to host_file_normalize_mingw, because we'd
be moving the code to a separate procedure and changing it at the same time.

So I kept the patches separate, but adjusted the first patch to use the "proc test" way.  I think it makes
sense this way, and lets me keep you as main author of that patch.

I sent it all as a v2 here:
   https://inbox.sourceware.org/gdb-patches/20250902112742.1407890-1-pedro@palves.net/T/

I didn't merge it yet, I wanted to give you a chance to double check the commit logs.
The resulting code is the exact same, though.

Pedro Alves

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] [gdb/testsuite] Fix host_file_normalize_mingw
  2025-09-02 11:34       ` Pedro Alves
@ 2025-09-02 11:44         ` Tom de Vries
  2025-09-02 12:06           ` Pedro Alves
  0 siblings, 1 reply; 8+ messages in thread
From: Tom de Vries @ 2025-09-02 11:44 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches

On 9/2/25 13:34, Pedro Alves wrote:
> Hi Tom,
> 
> On 2025-09-02 10:18, Tom de Vries wrote:
> 
>> I ran the test-case on both x86_64-linux and msys2-ucrt64, and it passed in both cases, so I think it should be fine.
>>
>> Feel free to commit this together with the first patch, or perhaps to combined into one patch.
>>
>> Given that the second patch now changes the setup of the test-case, I think squashing makes more sense.
> 
> I tried a combined patch, but it makes it hard to see the changes to host_file_normalize_mingw, because we'd
> be moving the code to a separate procedure and changing it at the same time.
> 
> So I kept the patches separate, but adjusted the first patch to use the "proc test" way.  I think it makes
> sense this way, and lets me keep you as main author of that patch.
> 
Hi Pedro,

I see, agreed.

> I sent it all as a v2 here:
>     https://inbox.sourceware.org/gdb-patches/20250902112742.1407890-1-pedro@palves.net/T/
> 
> I didn't merge it yet, I wanted to give you a chance to double check the commit logs.
> The resulting code is the exact same, though.


LGTM, please apply.

Thanks,
- Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] [gdb/testsuite] Fix host_file_normalize_mingw
  2025-09-02 11:44         ` Tom de Vries
@ 2025-09-02 12:06           ` Pedro Alves
  0 siblings, 0 replies; 8+ messages in thread
From: Pedro Alves @ 2025-09-02 12:06 UTC (permalink / raw)
  To: Tom de Vries, gdb-patches

On 2025-09-02 12:44, Tom de Vries wrote:
> On 9/2/25 13:34, Pedro Alves wrote:
>> I sent it all as a v2 here:
>>     https://inbox.sourceware.org/gdb-patches/20250902112742.1407890-1-pedro@palves.net/T/
>>
>> I didn't merge it yet, I wanted to give you a chance to double check the commit logs.
>> The resulting code is the exact same, though.
> 
> 
> LGTM, please apply.

Thanks, done.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-09-02 12:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 1/2] [gdb/testsuite] Add gdb.testsuite/mount-point-map.exp Tom de Vries
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox