@@ -401,7 +401,8 @@ static saved_output_files saved_output;
/* See cli-interp.h. */
void
-cli_interp_base::set_logging (ui_file_up logfile, bool logging_redirect)
+cli_interp_base::set_logging (ui_file_up logfile, bool logging_redirect,
+ bool debug_redirect)
{
if (logfile != NULL)
{
@@ -411,16 +412,18 @@ 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;
+ ui_file *tee = nullptr;
+ /* Note that the "tee" takes ownership of the log file. */
+ if (!logging_redirect || !debug_redirect)
+ tee = new tee_file (gdb_stdout, false, logfile.get (), true);
+
+ ui_file *released_log = logfile.release ();
+
+ gdb_stdout = logging_redirect ? released_log : tee;
+ gdb_stdlog = debug_redirect ? released_log : tee;
+ gdb_stderr = logging_redirect ? released_log : tee;
+ gdb_stdtarg = logging_redirect ? released_log : tee;
+ gdb_stdtargerr = logging_redirect ? released_log : tee;
}
else
{
@@ -28,29 +28,12 @@ public:
explicit cli_interp_base (const char *name);
virtual ~cli_interp_base () = 0;
- void set_logging (ui_file_up logfile, bool logging_redirect) override;
+ void set_logging (ui_file_up logfile, bool logging_redirect,
+ bool debug_redirect) override;
void pre_command_loop () override;
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,
- ui_file_up logfile, bool logging_redirect);
-
extern int cli_interpreter_supports_command_editing (struct interp *interp);
extern void cli_interpreter_pre_command_loop (struct interp *self);
@@ -62,6 +62,7 @@ show_logging_overwrite (struct ui_file *file, int from_tty,
/* Value as configured by the user. */
static int logging_redirect;
+static int debug_redirect;
static void
set_logging_redirect (const char *args,
@@ -81,31 +82,13 @@ show_logging_redirect (struct ui_file *file, int from_tty,
static void
pop_output_files (void)
{
- current_interp_set_logging (NULL, false);
+ current_interp_set_logging (NULL, false, false);
/* Stay consistent with handle_redirections. */
if (!current_uiout->is_mi_like_p ())
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)
@@ -130,12 +113,20 @@ handle_redirections (int from_tty)
else
fprintf_unfiltered (gdb_stdout, "Redirecting output to %s.\n",
logging_filename);
+
+ if (!debug_redirect)
+ fprintf_unfiltered (gdb_stdout, "Copying debug output to %s.\n",
+ logging_filename);
+ else
+ fprintf_unfiltered (gdb_stdout, "Redirecting debug output to %s.\n",
+ logging_filename);
}
saved_filename = xstrdup (logging_filename);
/* Let the interpreter do anything it needs. */
- current_interp_set_logging (std::move (log), logging_redirect);
+ current_interp_set_logging (std::move (log), logging_redirect,
+ debug_redirect);
/* Redirect the current ui-out object's output to the log. Use
gdb_stdout, not log, since the interpreter may have created a tee
@@ -203,6 +194,11 @@ show_logging_command (const char *args, int from_tty)
printf_unfiltered (_("Output will be sent only to the log file.\n"));
else
printf_unfiltered (_("Output will be logged and displayed.\n"));
+
+ if (debug_redirect)
+ printf_unfiltered (_("Debug output will be sent only to the log file.\n"));
+ else
+ printf_unfiltered (_("Debug output will be logged and displayed.\n"));
}
void
@@ -231,6 +227,15 @@ If redirect is on, output will go only to the log file."),
set_logging_redirect,
show_logging_redirect,
&set_logging_cmdlist, &show_logging_cmdlist);
+ add_setshow_boolean_cmd ("debugredirect", class_support,
+ &debug_redirect, _("\
+Set the logging debug output mode."), _("\
+Show the logging debug output mode."), _("\
+If debug redirect is off, debug will go to both the screen and the log file.\n\
+If debug redirect is on, debug will go only to the log file."),
+ set_logging_redirect,
+ show_logging_redirect,
+ &set_logging_cmdlist, &show_logging_cmdlist);
add_setshow_filename_cmd ("file", class_support, &logging_filename, _("\
Set the current logfile."), _("\
Show the current logfile."), _("\
@@ -254,13 +254,13 @@ set_top_level_interpreter (const char *name)
}
void
-current_interp_set_logging (ui_file_up logfile,
- bool logging_redirect)
+current_interp_set_logging (ui_file_up logfile, bool logging_redirect,
+ bool debug_redirect)
{
struct ui_interp_info *ui_interp = get_current_interp_info ();
struct interp *interp = ui_interp->current_interpreter;
- interp->set_logging (std::move (logfile), logging_redirect);
+ interp->set_logging (std::move (logfile), logging_redirect, debug_redirect);
}
/* Temporarily overrides the current interpreter. */
@@ -61,7 +61,8 @@ public:
/* Provides a hook for interpreters to do any additional
setup/cleanup that they might need when logging is enabled or
disabled. */
- virtual void set_logging (ui_file_up logfile, bool logging_redirect) = 0;
+ virtual void set_logging (ui_file_up logfile, bool logging_redirect,
+ bool debug_redirect) = 0;
/* Called before starting an event loop, to give the interpreter a
chance to e.g., print a prompt. */
@@ -141,9 +142,12 @@ extern int current_interp_named_p (const char *name);
interpreter should configure the output streams to send output only
to the logfile. If false, the interpreter should configure the
output streams to send output to both the current output stream
- (i.e., the terminal) and the log file. */
+ (i.e., the terminal) and the log file. DEBUG_REDIRECT is same as
+ LOGGING_REDIRECT, but for the value of "set logging debugredirect"
+ instead. */
extern void current_interp_set_logging (ui_file_up logfile,
- bool logging_redirect);
+ bool logging_redirect,
+ bool debug_redirect);
/* Returns the top-level interpreter. */
extern struct interp *top_level_interpreter (void);
@@ -66,7 +66,8 @@ public:
void suspend () override;
gdb_exception exec (const char *command_str) override;
ui_out *interp_ui_out () override;
- void set_logging (ui_file_up logfile, bool logging_redirect) override;
+ void set_logging (ui_file_up logfile, bool logging_redirect,
+ bool debug_redirect) override;
void pre_command_loop () override;
/* MI's output channels */
@@ -1279,17 +1279,24 @@ mi_interp::interp_ui_out ()
the consoles to use the supplied ui-file(s). */
void
-mi_interp::set_logging (ui_file_up logfile, bool logging_redirect)
+mi_interp::set_logging (ui_file_up logfile, bool logging_redirect,
+ bool debug_redirect)
{
struct mi_interp *mi = this;
if (logfile != NULL)
{
mi->saved_raw_stdout = mi->raw_stdout;
- mi->raw_stdout = make_logging_output (mi->raw_stdout,
- std::move (logfile),
- logging_redirect);
+ if (logging_redirect)
+ mi->raw_stdout = logfile.release ();
+ else
+ {
+ /* Note that the "tee" takes ownership of the log file. */
+ ui_file *tee = new tee_file (gdb_stdout, false, logfile.get (), true);
+ logfile.release ();
+ mi->raw_stdout = tee;
+ }
}
else
{