]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix "set cwd ..." on Cygwin, part 1
authorPedro Alves <pedro@palves.net>
Wed, 20 May 2026 12:14:07 +0000 (13:14 +0100)
committerPedro Alves <pedro@palves.net>
Mon, 25 May 2026 14:34:58 +0000 (15:34 +0100)
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.

Approved-By: Tom Tromey <tom@tromey.com>
Change-Id: I70af6ef394f48da35ccc2e04ef764915e09e59de
commit-id: 66c930c2

gdb/windows-nat.c

index d506b42fbdac22aaac6c6a5b411d841f95f6914d..862568fa21e01cd8f3cd22652a60391950bc6501 100644 (file)
@@ -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)