]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
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)
commite922d7b7c19e7f2d0b77f1eb182049c907e669dd
tree264235519328fd9aa6a14f1658c86ad35ecb8ce5
parent565074f17c6d3849e8a496d5bd7fbf7147b134bf
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 <tom@tromey.com>
Change-Id: I70af6ef394f48da35ccc2e04ef764915e09e59de
commit-id: 66c930c2
gdb/windows-nat.c