fix: read command output from a UTF-16 log on multibyte code pages - #103
Merged
Conversation
svnscha
marked this pull request as draft
September 4, 2026 21:46
svnscha
force-pushed
the
fix/multibyte-output
branch
from
September 4, 2026 22:05
3c5ac46 to
2edaa04
Compare
svnscha
force-pushed
the
fix/multibyte-output
branch
from
September 4, 2026 22:50
2edaa04 to
1e8fbb2
Compare
svnscha
force-pushed
the
fix/multibyte-output
branch
4 times, most recently
from
September 4, 2026 23:52
a223bba to
eca732a
Compare
On a multibyte system code page (Chinese 936, Japanese 932, Korean 949, or the "Use Unicode UTF-8" setting 65001) the debugger truncates its text output over a pipe: it writes each line's character count as a byte count, so the tail of any line with non-ASCII text, its newline included, is dropped. This lost the end of du strings and other Unicode output, and a line cut in the middle of a character wedged the session. It affects every command, not just du, and no debugger output mode over the pipe avoids it. .logopen /u writes a UTF-16 log that is complete and flushes per command. So on a multibyte code page the session now opens such a log at startup and reads each command's output from it, keyed by the same .echo markers the pipe already uses to synchronize. The pipe stays the control channel; only the returned content comes from the log. Single-byte code pages (e.g. Western 1252), where the pipe is lossless, are detected via GetCPInfo and keep the pipe path, byte-for-byte unchanged. The pipe is also decoded with the debugger's own ANSI code page and with errors="replace", so a multibyte sequence split across reads cannot raise in the reader thread on the paths that still read the pipe (a live target's asynchronous output). Verified on a Windows 11 VM with cdb 10.0.26100.1742 under code pages 1252 (passthrough), 936 and 65001 (all commands return complete Unicode). Fixes #102.
svnscha
force-pushed
the
fix/multibyte-output
branch
from
September 5, 2026 08:11
eca732a to
4d3e4d5
Compare
svnscha
marked this pull request as ready for review
September 5, 2026 08:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #102.
Problem
On Windows whose system code page is multibyte (Chinese 936, Japanese 932, Korean 949, or the "Use Unicode UTF-8" setting 65001), the debugger truncates its text output over a pipe: each line is written short by its multibyte expansion, dropping the tail (and newline) of any line that contains non-ASCII text. This lost the end of
dustrings and other Unicode output, and a line cut in the middle of a character left the session unresponsive to every later command.Reproduced on a Windows 11 VM. It affects every command that prints Unicode, not just
du, and no pipe output mode avoids it: interactive,-cbatch, and.logopento an ANSI file all truncate, because the miscount is in the debugger's writer.Fix (transport level, not per-command)
.logopen /uwrites a UTF-16 log that is complete and flushes per command. On a multibyte code page the session opens such a log at startup and reads each command's output from it, keyed by the same.echomarkers the pipe already uses to synchronize.-remoteclient drives the engine on the server, so it keeps the pipe (see Limitations).GetCPInfoand keep the pipe path, byte-for-byte unchanged.0:000>, kernel0: kd>/ locallkd>, WOW641:001:x86>, and remote[server (tcp ...)] 0:000>forms.errors="replace", so a split multibyte sequence can no longer raise in the reader thread on the paths that still read the pipe.Research: can the pipe itself be UTF-16?
Checked before going the log route. A Windows pipe is a raw byte stream; the writer picks the encoding, and cdb/kd convert their internal Unicode to the ANSI code page (the truncating
WriteFilepath) whenever stdout is a redirected handle. There is no cdb.exe switch to emit UTF-16/UTF-8 to the pipe. The only native Unicode sinks the engine offers are the wide output callbackIDebugOutputCallbacksWide(which would mean hostingdbgeng.dllourselves, a full re-architecture) and the Unicode log (.logopen /u, or the command-line-logou/-logau). A pseudo-console (ConPTY) would make cdb callWriteConsoleW, but its output arrives wrapped in VT escape sequences and hard-wrapped at the console width, which is worse to parse than the log. The log is the supported, clean mechanism.Verification
Reproduced at the 1.2.1 release commit and verified with this branch on a Windows 11 VM, stock SDK cdb/kd 10.0.26100.1742:
du,dw,db,.echo,versionand the rest return complete text; the temp log leaves nothing behind. Full suite: 106 passed on the 1252 host and 111 on the VM under both 936 and 65001; the hermetic tests drive the log path on any platform (a fake debugger mirrors a UTF-16 log) and are pinned to the single-byte path by default so they behave the same regardless of the host's real code page.du/du <addr> L<n>under 936 and 65001.version,lm m ntand a live kernel-memory read return complete output with thelkd>prompt stripped and the temp log cleaned up.-remote): end-to-end against a real.serverhost - attach, process (|), threads (~), modules (lm) and registers all work. The log stays off (engine is on the server), so this is unchanged from before.Limitations
-remoteclient on a multibyte code page still truncates Unicode output: the engine runs on the server, so its Unicode log is not on our machine (and for a cross-machine server would not be reachable at all). Remote debugging otherwise works; this is unchanged from before the fix.