Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Pedro Alves <pedro@palves.net>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Windows: Normalize backward slashes to forward slashes
Date: Tue, 30 Jun 2026 18:11:59 +0300	[thread overview]
Message-ID: <86qzlocbb4.fsf@gnu.org> (raw)
In-Reply-To: <dec1a9e0-3f94-4b04-a016-0992627729dd@palves.net> (message from Pedro Alves on Tue, 30 Jun 2026 15:47:54 +0100)

> Date: Tue, 30 Jun 2026 15:47:54 +0100
> Cc: gdb-patches@sourceware.org
> From: Pedro Alves <pedro@palves.net>
> 
> On 2026-06-30 12:26, Eli Zaretskii wrote:
> >> From: Pedro Alves <pedro@palves.net>
> >> Date: Mon, 29 Jun 2026 22:24:30 +0100
> >>
> >>   Starting program: C:/msys2/home/alves/gdb/build-testsuite/outputs/gdb.rocm/simple/simple
> > 
> > Are forward slashes only shown to the user, or does the code pas the
> > file name with forward slashes to CreateProcess?  (I'm not familiar
> > with thecode enough to determine which one myself, sorry.)  If we pass
> > forward slashes to CreateProcess, it could cause problems, IME; it is
> > much safer to use backslashes there.
> 
> We now pass forward slashes down to CreateProcess.  It just works on my Windows 11 machine, though.  I forgot to
> mention, but I (painfully) ran the whole testsuite before and after this patch (that's how I discovered the need
> to tweak the gdb.base/set-cwd.exp testcase).
> 
> Searching online, I found this:
> 
>   https://stackoverflow.com/questions/5652834/c-createprocess-wont-work-with-app-and-args-with-forward-slash-worked
> 
> ... where someone said:
> 
>   "CreateProcess does work with forward-slashes on Windows 7. I'm guessing this is a version-specific feature (or bug)."
> 
> And here:
> 
>   https://www.reddit.com/r/programmingmemes/comments/1k8ctk2/comment/mp8lvsr/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button
> 
> Someone said: 
> 
>   "At least since Windows 2000, probably since always."
> 
> I asked an LLM, and got this:
> 
>   "That normalization is original to NT -- Windows NT 3.1 (1993). The kernel's RtlDosPathNameToNtPathName has always treated / as an alternate separator. CreateProcess
>   itself never "added" the feature -- it just calls through to the kernel, which handles it transparently."
> 
> So I wonder whether what you're recalling is something from the Windows 9x days, which we no longer support (we support WinXP and up).  Do you happen to recall?

No, I don't.  But I stopped using Windows 9X a very long time ago, and
my main development machine ran XP until two years ago.  So if I had
to guess, I'd guess it was on XP.

The articles you cite are correct in that the low-level Windows APIs
which accept file names treat the forward slash as a directory
separator.  But CreateProcess has some application-level logic of
itself: it accepts a complete command line as a single string, not as
argv[]-style array, and decides by itself which part of that command
line is the executable and which the rest of the command line.  It is
this part that I'm afraid of: it could treat the two slash variants
differently.  That happens before the command line gets to the
low-level APIs which accept file names.

> If it's really a problem on supported Windows versions, it should be a matter of converting back to forward slashes before we
> call CreateProcess.  We already do that in gdb/windows-nat.c:windows_nat_target::create_inferior, for "set cwd":
> 
>       /* Mirror slashes on inferior's cwd.  */
>       std::replace (expanded_infcwd.begin (), expanded_infcwd.end (),
> 		    '/', '\\');
> 
> we'd just need to do the same for exec_file.

Yes, I think it's safer to convert to all backslashes in the argument
we pass to CreateProcess.  And it will not show outside of that place,
so the (very positive and welcome) effects of your changes will not be
affected.

Thanks.

  reply	other threads:[~2026-06-30 15:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-29 21:24 Pedro Alves
2026-06-30 11:26 ` Eli Zaretskii
2026-06-30 14:47   ` Pedro Alves
2026-06-30 15:11     ` Eli Zaretskii [this message]
2026-07-01 11:28       ` [PATCH v2] " Pedro Alves
2026-07-01 12:07         ` Eli Zaretskii
2026-07-01 19:28           ` Pedro Alves
2026-07-02  5:28             ` Eli Zaretskii
2026-07-06 12:07         ` Andrew Burgess
2026-07-06 22:35           ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86qzlocbb4.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=pedro@palves.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox