From: Pedro Alves Date: Wed, 20 May 2026 12:14:07 +0000 (+0100) Subject: Fix "set cwd ..." on Cygwin, part 1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e922d7b7c19e7f2d0b77f1eb182049c907e669dd;p=thirdparty%2Fbinutils-gdb.git Fix "set cwd ..." on Cygwin, part 1 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 Change-Id: I70af6ef394f48da35ccc2e04ef764915e09e59de commit-id: 66c930c2 --- 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)