From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id xb2zBQEEsmhwhw8AWB0awg (envelope-from ) for ; Fri, 29 Aug 2025 15:48:17 -0400 Received: by simark.ca (Postfix, from userid 112) id F38161E023; Fri, 29 Aug 2025 15:48:16 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=no autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id ED4F91E023 for ; Fri, 29 Aug 2025 15:48:15 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 526B93858421 for ; Fri, 29 Aug 2025 19:48:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 526B93858421 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) by sourceware.org (Postfix) with ESMTPS id DF65D3858408 for ; Fri, 29 Aug 2025 19:47:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DF65D3858408 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DF65D3858408 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756496862; cv=none; b=MQ0kixmZxARk0Qsu4YI93ennSR5q9scn/RNTyyCh57H3dkUOy0uegW8T1izT/7ZyORruqMCZLJd6RkNdPt9c9k8MYUViuowf9mpLppn/2WtpHGg2+kjpnzon0PzcUGmoO4pZmIQ1JDc5dy60EMDFKgXZpaYellzQYHOedHGh+jI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756496862; c=relaxed/simple; bh=pfUdIy0d8xUnD1+WgskwBdMxIOUl+PHJpU78S2UiuoA=; h=Message-ID:Date:MIME-Version:Subject:To:From; b=ub7qGqb9BWg95mSA/Lk92KOBA2bf8HbqtFccom1q4k55L5T+wdMKHLmuuuFbnf656inFbw5G51LcaN0XgFKE9Mra/XesUnvTOAlMhDrzwdMJHPZ5OEqE1A8JuTs/pqg7uORAtIuO8IoDDFKy6GlS+2ELiuXjDVI2MOQasLPdUME= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DF65D3858408 Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-3cbe70a7923so1973573f8f.2 for ; Fri, 29 Aug 2025 12:47:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756496860; x=1757101660; h=content-transfer-encoding:in-reply-to:content-language:from :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Oweyni3vUXK3z/g4tIyb45w+EhTG/ZYtXs/ZoADaD10=; b=a9Sq1Ugs6dvBDUenahO4p/SZvAeMDaMGwhXvLhvVg/N64hZL07+K6UfzlxH3YQvo8k sjv7QVhgND4qaNnf/u/RwO7TSPzHgM/yN7XRkl+9O2G4NDjf6+jhQ2qh8evDzbuOomDQ G2ookwfcO2lF+pWgja9tHBYyD6BvY3iqxllq+4mh50/Rmq9b0qPxEyPtWKEvSqa82LWR YisaMtckt8AECSL/CjUbt7WM0AUJJh3xZsmXT/YZNLPMr3PQrMkYn0NbllxB76GOzGh3 t9YPw576Xpcz9sBH7ML+2mkrrPe2rQv9327jb+wv4IGFoIETkC25w5wRhFPzhllOqGZj S0qg== X-Forwarded-Encrypted: i=1; AJvYcCWMLS3SeULTKhX0284h3N/y2dEwDMbVh2iAdqYvJiHOmu5pXE/ZL8Qbs00oZ1EOK4dg0FzwCHF1MOCuDA==@sourceware.org X-Gm-Message-State: AOJu0YyaIvoMddeUEcgldqIY7QnQpPcfCiJfLCWJTKPPualAPODl4cSo 8hGhCsW6RNbHzwChJWG1kGXueXWkpMaKNjVDqPJYxbRLM1eF4S7ppJiL8Dow5Q== X-Gm-Gg: ASbGncuLuQRPuSBYBsbL7Pm11zBsPsr/J73f4iv8EUq6bYDwGPFAh1CnY1n0H9ujR4C O8gDevgOqeesLhIBFfAQwkCBAhjPjeav8+xtpKKoQWSUHBKbuFzM2SVpcFT+Dr428u8YwQ0NP5s +xuGN/jWyIkRLbBgL0HwlpL3nhxGn9+o12efJFaiEVPftnEAiFosXj0t6ZRM6RZiCS6L7Er7QSL N+U1CTzOHpM+Z7vdR+RqFHG7nn9Kmn77wPwO9jVuuohimSt88N/4pioq9R1hxCmJNYPzDJ0PMCZ F/tMDhzveM7Vu6C+OCwbj/TmjnUjllgSxmVLfnMoCqm0eFN7wi0HVJAbRiPVsd6iGG4yk32onRP GZ/rqN5bW7y4EVbVUZXcc6XGUyBD8KYLekZXOF7/tFbx3L6pG3nU7arZ53YlnPFRtPen+tmJ9+V kJZQiITzZ3 X-Google-Smtp-Source: AGHT+IH5YLBFp9SwWPTwdHIIO2+kdX4eWe9AFx+IQti1RjOuLkX0z9IG15e4w2+zaal2pZMhyMmnuA== X-Received: by 2002:a05:6000:40cb:b0:3d1:59a:b81b with SMTP id ffacd0b85a97d-3d1059ab9aamr2414060f8f.11.1756496859938; Fri, 29 Aug 2025 12:47:39 -0700 (PDT) Received: from ?IPV6:2001:8a0:fad8:400:b454:3d0e:ccc3:510c? ([2001:8a0:fad8:400:b454:3d0e:ccc3:510c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3cf33fba9c4sm4372829f8f.48.2025.08.29.12.47.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 29 Aug 2025 12:47:39 -0700 (PDT) Message-ID: <64decff4-3ff0-4033-812e-df98f7fb6912@palves.net> Date: Fri, 29 Aug 2025 20:47:21 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/2] [gdb/testsuite] Fix host_file_normalize_mingw To: Tom de Vries , gdb-patches@sourceware.org References: <20250827131439.27473-1-tdevries@suse.de> <20250827131439.27473-3-tdevries@suse.de> From: Pedro Alves Content-Language: en-US In-Reply-To: <20250827131439.27473-3-tdevries@suse.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org 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 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