diff options
author | Tom Tromey <tromey@adacore.com> | 2022-11-17 08:16:44 -0700 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2022-11-28 13:22:40 -0700 |
commit | 19622df10dd5a8d3567e79d0661770029e4fbcfe (patch) | |
tree | 87ac97fd74bf2da29e08790f67953243a89fbf82 /gdb/cli | |
parent | e1df90510a85d08eae165d868d6aa20bc1d09203 (diff) | |
download | fsf-binutils-gdb-19622df10dd5a8d3567e79d0661770029e4fbcfe.zip fsf-binutils-gdb-19622df10dd5a8d3567e79d0661770029e4fbcfe.tar.gz fsf-binutils-gdb-19622df10dd5a8d3567e79d0661770029e4fbcfe.tar.bz2 |
Remove 'saved_output' global
CLI redirect uses a global variable, 'saved_output'. However, globals
are generally bad, and there is no need for this one -- it can be a
member of cli_interp_base. This patch makes this change.
Diffstat (limited to 'gdb/cli')
-rw-r--r-- | gdb/cli/cli-interp.c | 47 | ||||
-rw-r--r-- | gdb/cli/cli-interp.h | 16 |
2 files changed, 33 insertions, 30 deletions
diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c index ca3a1ab..8c2fb20 100644 --- a/gdb/cli/cli-interp.c +++ b/gdb/cli/cli-interp.c @@ -370,20 +370,6 @@ cli_interp::interp_ui_out () return m_cli_uiout.get (); } -/* These hold the pushed copies of the gdb output files. - If NULL then nothing has yet been pushed. */ -struct saved_output_files -{ - ui_file *out; - ui_file *err; - ui_file *log; - ui_file *targ; - ui_file *targerr; - ui_file_up file_to_delete; - ui_file_up log_to_delete; -}; -static std::unique_ptr<saved_output_files> saved_output; - /* See cli-interp.h. */ void @@ -392,12 +378,13 @@ cli_interp_base::set_logging (ui_file_up logfile, bool logging_redirect, { if (logfile != nullptr) { - saved_output.reset (new saved_output_files); - saved_output->out = gdb_stdout; - saved_output->err = gdb_stderr; - saved_output->log = gdb_stdlog; - saved_output->targ = gdb_stdtarg; - saved_output->targerr = gdb_stdtargerr; + gdb_assert (m_saved_output == nullptr); + m_saved_output.reset (new saved_output_files); + m_saved_output->out = gdb_stdout; + m_saved_output->err = gdb_stderr; + m_saved_output->log = gdb_stdlog; + m_saved_output->targ = gdb_stdtarg; + m_saved_output->targerr = gdb_stdtargerr; /* If something is not being redirected, then a tee containing both the logfile and stdout. */ @@ -406,29 +393,29 @@ cli_interp_base::set_logging (ui_file_up logfile, bool logging_redirect, if (!logging_redirect || !debug_redirect) { tee = new tee_file (gdb_stdout, std::move (logfile)); - saved_output->file_to_delete.reset (tee); + m_saved_output->file_to_delete.reset (tee); } else - saved_output->file_to_delete = std::move (logfile); + m_saved_output->file_to_delete = std::move (logfile); - saved_output->log_to_delete.reset + m_saved_output->log_to_delete.reset (new timestamped_file (debug_redirect ? logfile_p : tee)); gdb_stdout = logging_redirect ? logfile_p : tee; - gdb_stdlog = saved_output->log_to_delete.get (); + gdb_stdlog = m_saved_output->log_to_delete.get (); gdb_stderr = logging_redirect ? logfile_p : tee; gdb_stdtarg = logging_redirect ? logfile_p : tee; gdb_stdtargerr = logging_redirect ? logfile_p : tee; } else { - gdb_stdout = saved_output->out; - gdb_stderr = saved_output->err; - gdb_stdlog = saved_output->log; - gdb_stdtarg = saved_output->targ; - gdb_stdtargerr = saved_output->targerr; + gdb_stdout = m_saved_output->out; + gdb_stderr = m_saved_output->err; + gdb_stdlog = m_saved_output->log; + gdb_stdtarg = m_saved_output->targ; + gdb_stdtargerr = m_saved_output->targerr; - saved_output.reset (nullptr); + m_saved_output.reset (nullptr); } } diff --git a/gdb/cli/cli-interp.h b/gdb/cli/cli-interp.h index 1620305..3c233c0 100644 --- a/gdb/cli/cli-interp.h +++ b/gdb/cli/cli-interp.h @@ -32,6 +32,22 @@ public: bool debug_redirect) override; void pre_command_loop () override; bool supports_command_editing () override; + +private: + struct saved_output_files + { + ui_file *out; + ui_file *err; + ui_file *log; + ui_file *targ; + ui_file *targerr; + ui_file_up file_to_delete; + ui_file_up log_to_delete; + }; + + /* These hold the pushed copies of the gdb output files. If NULL + then nothing has yet been pushed. */ + std::unique_ptr<saved_output_files> m_saved_output; }; /* Returns true if the current stop should be printed to |