]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
Rewrite output redirection and logging
authorTom Tromey <tom@tromey.com>
Sat, 6 Dec 2025 21:12:37 +0000 (15:12 -0600)
committerTom Tromey <tom@tromey.com>
Mon, 9 Feb 2026 15:15:44 +0000 (08:15 -0700)
commit817003ed46963e6f8e0782a2e709a9cfde71b0d9
treefe0e6292b4a9474a6b0b0963cbace2be2fe09fc0
parentaed0772e66e921c235165480276600a7c7dfc048
Rewrite output redirection and logging

This patch changes how gdb output redirection is done.

Currently, output is done via the UI.  gdb_stdout, for example, is a
define the expands to an lvalue referencing a field in the current UI.
When redirecting, this field may temporarily be reset; and when
logging is enabled or disabled, this is also done.

This has lead to bugs where the combination of redirection and logging
results in use-after-free.  Crashes are readily observable; see the
new test cases.

This patch upends this.  Now, gdb_stdout is simply an rvalue, and
refers to the current interpreter.  The interpreter provides ui_files
that do whatever rewriting is needed (mostly for MI); then output is
forward to the current UI via an indirection (see the new
ui::passthrough_file).

The ui provides paging, logging, timestamps, and the final stream that
writes to an actual file descriptor.

Redirection is handled at the ui layer.  Rather than changing the
output pipeline, new ui_files are simply swapped in by rewriting
pointers, hopefully with a scoped_restore.

Redirecting at the ui layer means that interpreter rewriting is still
applied when capturing output.  This fixes one of the reported bugs.

Not changing the pipeline means that the problems with the combination
of redirect and logging simply vanish.  Logging just changes a flag
and doesn't involve object destruction.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17697
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28620
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28798
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28948
Approved-By: Andrew Burgess <aburgess@redhat.com>
22 files changed:
gdb/buffered-streams.c
gdb/cli/cli-interp.c
gdb/cli/cli-interp.h
gdb/cli/cli-logging.c
gdb/fork-child.c
gdb/guile/scm-ports.c
gdb/interps.c
gdb/interps.h
gdb/main.c
gdb/mi/mi-console.c
gdb/mi/mi-console.h
gdb/mi/mi-interp.c
gdb/mi/mi-interp.h
gdb/python/py-dap.c
gdb/testsuite/gdb.base/early-logging.exp [new file with mode: 0644]
gdb/testsuite/gdb.python/python.exp
gdb/top.c
gdb/tui/tui-interp.c
gdb/tui/tui-io.c
gdb/ui.c
gdb/ui.h
gdb/utils.h