Conversation
Inferiors started by GDB are attached to a PersistentPTY whose output stream ignores close(), so the PTY can be reused when the inferior is restarted. As a consequence, closing the inferior's input never reached the program: the console EOF action (Ctrl+D) did nothing and a launch with standard input redirected from a file (Common tab > Input File) hung forever in the debugger, while the same launch worked in run mode where a regular PTY sends EOT on close. Hand out a wrapper from MIInferiorProcess.getOutputStream() whose close() writes EOT to the PTY while the inferior is running. CDT's own cleanup (closeIO) still closes the underlying stream directly, so no stray EOT is left in the PTY for a restarted inferior. Windows is unchanged, as EOT does not mean end of input there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
When debugging a C/C++ program with GDB on Linux, the program can never receive EOF on stdin:
while (scanf("%d %d %d", &a, &b, &c) == 3)) hangs on the last read.The same launch works in run mode, and the program works in a terminal with
./prog < file.Cause
For debug sessions,
StartOrRestartProcessSequence_7_0attaches the inferior to aPersistentPTY. Its output stream deliberately ignoresclose()so the PTY can be reused when the inferior is restarted from the GDB console. As a result,MIInferiorProcess.getOutputStream().close(), which is what the platform calls for the console EOF action and, with eclipse-platform/eclipse.platform#2969, at the end of a stdin input file, never writes the EOT that a regularPTYOutputStream(used in run mode) sends on close.Fix
MIInferiorProcess.getOutputStream()now returns, for aPersistentPTYon non-Windows platforms, a thin wrapper whoseclose()writes EOT to the PTY while the inferior is running and keeps the PTY open.closeIO(), which CDT calls itself on termination and dispose, still closes the underlying PTY stream directly. That's a no-op for aPersistentPTY, as before, so no stray EOT is left in the PTY for a restarted inferior. Windows and the no-PTY (GDB MI stream) mode are unchanged.Testing
Verified manually on Linux (GDB 15.1) against CDT 12.6 with a C program reading stdin until EOF:
I didn't add an automated test, because reproducing this needs a real GDB and PTY. Happy to add one to
dsf.gdb.testsif there's a preferred pattern, and to bump the bundle version if the API baseline check requires it.Related platform fix: eclipse-platform/eclipse.platform#2969 (Bug 513713).
🤖 Generated with Claude Code