aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2025-12-06 15:12:37 -0600
committerTom Tromey <tom@tromey.com>2026-02-09 08:15:44 -0700
commit817003ed46963e6f8e0782a2e709a9cfde71b0d9 (patch)
treefe0e6292b4a9474a6b0b0963cbace2be2fe09fc0 /gdb/python
parentaed0772e66e921c235165480276600a7c7dfc048 (diff)
downloadbinutils-817003ed46963e6f8e0782a2e709a9cfde71b0d9.tar.gz
binutils-817003ed46963e6f8e0782a2e709a9cfde71b0d9.tar.bz2
binutils-817003ed46963e6f8e0782a2e709a9cfde71b0d9.zip
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>
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-dap.c10
1 files changed, 2 insertions, 8 deletions
diff --git a/gdb/python/py-dap.c b/gdb/python/py-dap.c
index 47d90e51938..07cd47bdc0e 100644
--- a/gdb/python/py-dap.c
+++ b/gdb/python/py-dap.c
@@ -27,9 +27,9 @@ class dap_interp final : public interp
public:
explicit dap_interp (const char *name)
- : interp (name),
- m_ui_out (new cli_ui_out (gdb_stdout))
+ : interp (name)
{
+ m_ui_out = std::make_unique<cli_ui_out> (m_stdout.get ());
}
~dap_interp () override = default;
@@ -49,12 +49,6 @@ public:
/* Just ignore it. */
}
- void set_logging (ui_file_up logfile, bool logging_redirect,
- bool debug_redirect) override
- {
- /* Just ignore it. */
- }
-
ui_out *interp_ui_out () override
{
return m_ui_out.get ();