aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli
diff options
context:
space:
mode:
authorAlan Hayward <alan.hayward@arm.com>2019-05-17 14:07:04 +0100
committerAlan Hayward <alan.hayward@arm.com>2019-05-17 14:07:04 +0100
commitf3a09c800fcd1d597fa2b9578cb59adfc15b698d (patch)
tree0cfd6d8b1c65fb029a59d706d47aee2f92c990c7 /gdb/cli
parentaf4fa23fba220c1b26bb3c8a7996b406dcc181cc (diff)
downloadgdb-f3a09c800fcd1d597fa2b9578cb59adfc15b698d.zip
gdb-f3a09c800fcd1d597fa2b9578cb59adfc15b698d.tar.gz
gdb-f3a09c800fcd1d597fa2b9578cb59adfc15b698d.tar.bz2
Change file close behavior for tee_file
Instead of using two bools to decide if the files should close when tee_file is closed, make file one stay open and file two close. This simplifies the use cases for it. Inline the make_logging_output into the calling functions (the logic here looks ugly in order to simplify a later change). Expand ui-redirect.exp to cover the changes, similar to mi-logging.exp. gdb/ChangeLog: * cli/cli-interp.c (cli_interp_base::set_logging): Create tee_file directly. * cli/cli-interp.h (make_logging_output): Remove declaration. * cli/cli-logging.c (make_logging_output): Remove function. * mi/mi-interp.c (mi_interp::set_logging): Create tee_file directly. * ui-file.c (tee_file::tee_file): Remove bools. (tee_file::~tee_file): Remove deletes. * ui-file.h (tee_file): Remove bools. gdb/testsuite/ChangeLog: * gdb.base/ui-redirect.exp: Test redirection.
Diffstat (limited to 'gdb/cli')
-rw-r--r--gdb/cli/cli-interp.c38
-rw-r--r--gdb/cli/cli-interp.h13
-rw-r--r--gdb/cli/cli-logging.c18
3 files changed, 22 insertions, 47 deletions
diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c
index fc4b39a..7876f91 100644
--- a/gdb/cli/cli-interp.c
+++ b/gdb/cli/cli-interp.c
@@ -403,7 +403,7 @@ static saved_output_files saved_output;
void
cli_interp_base::set_logging (ui_file_up logfile, bool logging_redirect)
{
- if (logfile != NULL)
+ if (logfile != nullptr)
{
saved_output.out = gdb_stdout;
saved_output.err = gdb_stderr;
@@ -411,16 +411,22 @@ cli_interp_base::set_logging (ui_file_up logfile, bool logging_redirect)
saved_output.targ = gdb_stdtarg;
saved_output.targerr = gdb_stdtargerr;
- /* A raw pointer since ownership is transferred to
- gdb_stdout. */
- ui_file *output = make_logging_output (gdb_stdout,
- std::move (logfile),
- logging_redirect);
- gdb_stdout = output;
- gdb_stdlog = output;
- gdb_stderr = output;
- gdb_stdtarg = output;
- gdb_stdtargerr = output;
+ /* If logging is being redirected, then grab logfile. */
+ ui_file *logfile_p = nullptr;
+ if (logging_redirect)
+ logfile_p = logfile.release ();
+
+ /* If logging is not being redirected, then a tee containing both the
+ logfile and stdout. */
+ ui_file *tee = nullptr;
+ if (!logging_redirect)
+ tee = new tee_file (gdb_stdout, std::move (logfile));
+
+ gdb_stdout = logging_redirect ? logfile_p : tee;
+ gdb_stdlog = logging_redirect ? logfile_p : tee;
+ gdb_stderr = logging_redirect ? logfile_p : tee;
+ gdb_stdtarg = logging_redirect ? logfile_p : tee;
+ gdb_stdtargerr = logging_redirect ? logfile_p : tee;
}
else
{
@@ -434,11 +440,11 @@ cli_interp_base::set_logging (ui_file_up logfile, bool logging_redirect)
gdb_stdtarg = saved_output.targ;
gdb_stdtargerr = saved_output.targerr;
- saved_output.out = NULL;
- saved_output.err = NULL;
- saved_output.log = NULL;
- saved_output.targ = NULL;
- saved_output.targerr = NULL;
+ saved_output.out = nullptr;
+ saved_output.err = nullptr;
+ saved_output.log = nullptr;
+ saved_output.targ = nullptr;
+ saved_output.targerr = nullptr;
}
}
diff --git a/gdb/cli/cli-interp.h b/gdb/cli/cli-interp.h
index 77d73a2..0c2e73b 100644
--- a/gdb/cli/cli-interp.h
+++ b/gdb/cli/cli-interp.h
@@ -33,19 +33,6 @@ public:
bool supports_command_editing () override;
};
-/* Make the output ui_file to use when logging is enabled.
- CURR_OUTPUT is the stream where output is currently being sent to
- (e.g., gdb_stdout for the CLI, raw output stream for the MI).
- LOGFILE is the log file already opened by the caller.
- LOGGING_REDIRECT is the value of the "set logging redirect"
- setting. If true, the resulting output is the logfile. If false,
- the output stream is a tee, with the log file as one of the
- outputs. Ownership of LOGFILE is transferred to the returned
- output file, which is an owning pointer. */
-extern ui_file *make_logging_output (ui_file *curr_output,
- ui_file_up logfile,
- bool logging_redirect);
-
/* The CLI interpreter's set_logging_proc method. Exported so other
interpreters can reuse it. */
extern void cli_set_logging (struct interp *interp,
diff --git a/gdb/cli/cli-logging.c b/gdb/cli/cli-logging.c
index 3a5e14d..670e7e2 100644
--- a/gdb/cli/cli-logging.c
+++ b/gdb/cli/cli-logging.c
@@ -88,24 +88,6 @@ pop_output_files (void)
current_uiout->redirect (NULL);
}
-/* See cli-interp.h. */
-
-ui_file *
-make_logging_output (ui_file *curr_output, ui_file_up logfile,
- bool logging_redirect)
-{
- if (logging_redirect)
- return logfile.release ();
- else
- {
- /* Note that the "tee" takes ownership of the log file. */
- ui_file *out = new tee_file (curr_output, false,
- logfile.get (), true);
- logfile.release ();
- return out;
- }
-}
-
/* This is a helper for the `set logging' command. */
static void
handle_redirections (int from_tty)