Skip to content

Send EOF to debugged inferior when its input stream is closed - #1522

Open
anydoby wants to merge 1 commit into
eclipse-cdt:mainfrom
anydoby:debug-input-eof
Open

anydoby wants to merge 1 commit into
eclipse-cdt:mainfrom
anydoby:debug-input-eof

Conversation

@anydoby

@anydoby anydoby commented Sep 27, 2026

Copy link
Copy Markdown

Problem

When debugging a C/C++ program with GDB on Linux, the program can never receive EOF on stdin:

  • With standard input redirected from a file (Common tab → Input File), a program that reads until EOF (e.g. while (scanf("%d %d %d", &a, &b, &c) == 3)) hangs on the last read.
  • The console's manual EOF action (Ctrl+D) has no effect either.

The same launch works in run mode, and the program works in a terminal with ./prog < file.

Cause

For debug sessions, StartOrRestartProcessSequence_7_0 attaches the inferior to a PersistentPTY. Its output stream deliberately ignores close() 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 regular PTYOutputStream (used in run mode) sends on close.

Fix

MIInferiorProcess.getOutputStream() now returns, for a PersistentPTY on non-Windows platforms, a thin wrapper whose close() 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 a PersistentPTY, 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:

  • Debug with Input File set: the program reads the file, gets EOF and exits normally (previously hung).
  • Debug without an input file, typing into the console, then Ctrl+D: the program gets EOF (previously nothing happened).
  • Restarting the debug session afterwards: the restarted program reads input normally.

I didn't add an automated test, because reproducing this needs a real GDB and PTY. Happy to add one to dsf.gdb.tests if 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

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant