Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/5] Fix "set cwd ..." on Cygwin, part 1
Date: Fri, 22 May 2026 01:16:22 +0100	[thread overview]
Message-ID: <20260522001626.393908-2-pedro@palves.net> (raw)
In-Reply-To: <20260522001626.393908-1-pedro@palves.net>

When running gdb.base/exitsignal.exp on Cygwin, we see:

 (gdb) set cwd /cygdrive/d/cygwin-gdb/build-testsuite/outputs/gdb.base/exitsignal
 (gdb) run
 Starting program: /cygdrive/d/cygwin-gdb/build-testsuite/outputs/gdb.base/exitsignal/exitsignal
 Error converting inferior cwd: 28
 (gdb) FAIL: gdb.base/exitsignal.exp: runto: run to main

28 is ENOSPC.  But this isn't really literally no space left, though.
cygwin_conv_path documentation mentions that error code.

According to the Cygwin API documentation for cygwin_conv_path, the
function fails with ENOSPC ("No space left on device") when the size
of the destination buffer is smaller than what is required for the
conversion.  See:

 https://cygwin.com/cygwin-api/func-cygwin-conv-path.html

If we look closely at how the buffer size argument is being passed, we
see we have two problems here:

1) Incorrectly passing down the input buffer size instead of the
output size.

The code passes strlen(inferior_cwd) as the size of the destination
buffer (infcwd). However, the target Windows path format
(e.g. "D:\cygwin-gdb\..." in my case) could be longer or shorter than
the POSIX source path ("/cygdrive/d/...").  In my specific case, the
source string is 64 characters, while the target Windows string is 61
(wide) characters (and twice as many bytes).

2) Incorrectly passing character count instead of byte count

The conversion target token is CCP_POSIX_TO_WIN_W.  The _W means that
the destination buffer infcwd takes wide characters (wchar_t).  The
documentation states that the size argument is in bytes, not
characters.

This commit fixes it, by passing the byte size of the destination
buffer.

Change-Id: I70af6ef394f48da35ccc2e04ef764915e09e59de
commit-id: 66c930c2
---
 gdb/windows-nat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index d506b42fbda..862568fa21e 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -2925,7 +2925,7 @@ windows_nat_target::create_inferior (const char *exec_file,
 
   if (inferior_cwd != NULL
       && cygwin_conv_path (CCP_POSIX_TO_WIN_W, inferior_cwd,
-			   infcwd, strlen (inferior_cwd)) < 0)
+			   infcwd, sizeof (infcwd)) < 0)
     error (_("Error converting inferior cwd: %d"), errno);
 
   args = (wchar_t *) alloca ((wcslen (toexec) + wcslen (cygallargs) + 2)
-- 
2.53.0


  reply	other threads:[~2026-05-22  0:17 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-22  0:16 [PATCH 0/5] Fix a few Cygwin/MinGW problems Pedro Alves
2026-05-22  0:16 ` Pedro Alves [this message]
2026-05-22 13:54   ` [PATCH 1/5] Fix "set cwd ..." on Cygwin, part 1 Tom Tromey
2026-05-22  0:16 ` [PATCH 2/5] Fix "set cwd ..." on Cygwin, part 2 Pedro Alves
2026-05-22 14:37   ` Tom Tromey
2026-05-25 16:43     ` Pedro Alves
2026-05-22  0:16 ` [PATCH 3/5] Adjust gdb.base/exitsignal.exp for Cygwin Pedro Alves
2026-05-22 15:09   ` Tom Tromey
2026-05-22  0:16 ` [PATCH 4/5] Fix exit/signal code on Cygwin Pedro Alves
2026-05-22  7:15   ` Eli Zaretskii
2026-05-25 16:47     ` Pedro Alves
2026-05-22  0:16 ` [PATCH 5/5] Adjust gdb.python/py-events.exp for Cygwin/MinGW Pedro Alves
2026-05-22  7:18   ` Eli Zaretskii

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=20260522001626.393908-2-pedro@palves.net \
    --to=pedro@palves.net \
    --cc=gdb-patches@sourceware.org \
    /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