Class-ify ui_out
[deliverable/binutils-gdb.git] / gdb / cli / cli-logging.c
index 3f6f85153d381511196b3e7944a7d057e6b9c3eb..46c23064fc37a07df385a7577ae5d6e3a2f1f8f4 100644 (file)
@@ -1,7 +1,6 @@
 /* Command-line output logging for GDB, the GNU debugger.
 
-   Copyright (c) 2003, 2004, 2007, 2008, 2009, 2010, 2011
-   Free Software Foundation, Inc.
+   Copyright (C) 2003-2016 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -21,9 +20,7 @@
 #include "defs.h"
 #include "gdbcmd.h"
 #include "ui-out.h"
-#include "gdb_assert.h"
-
-#include "gdb_string.h"
+#include "interps.h"
 
 /* These hold the pushed copies of the gdb output files.
    If NULL then nothing has yet been pushed.  */
@@ -61,8 +58,9 @@ static void
 show_logging_overwrite (struct ui_file *file, int from_tty,
                        struct cmd_list_element *c, const char *value)
 {
-  fprintf_filtered (file, _("\
-Whether logging overwrites or appends to the log file is %s.\n"),
+  fprintf_filtered (file,
+                   _("Whether logging overwrites or "
+                     "appends to the log file is %s.\n"),
                    value);
 }
 
@@ -78,21 +76,24 @@ static struct ui_file *logging_no_redirect_file;
 static void
 set_logging_redirect (char *args, int from_tty, struct cmd_list_element *c)
 {
-  struct cleanup *cleanups = NULL;
+  struct cleanup *cleanups;
   struct ui_file *output, *new_logging_no_redirect_file;
+  struct ui_out *uiout = current_uiout;
 
   if (saved_filename == NULL
       || (logging_redirect != 0 && logging_no_redirect_file == NULL)
       || (logging_redirect == 0 && logging_no_redirect_file != NULL))
     return;
 
+  cleanups = make_cleanup (null_cleanup, NULL);
+
   if (logging_redirect != 0)
     {
       gdb_assert (logging_no_redirect_file != NULL);
 
       /* ui_out_redirect still has not been called for next
         gdb_stdout.  */
-      cleanups = make_cleanup_ui_file_delete (gdb_stdout);
+      make_cleanup_ui_file_delete (gdb_stdout);
 
       output = logging_no_redirect_file;
       new_logging_no_redirect_file = NULL;
@@ -114,11 +115,17 @@ set_logging_redirect (char *args, int from_tty, struct cmd_list_element *c)
                            logging_filename);
     }
 
-  gdb_stdout = output;
-  gdb_stderr = output;
-  gdb_stdlog = output;
-  gdb_stdtarg = output;
-  gdb_stdtargerr = output;
+  /* Give the current interpreter a chance to do anything special that
+     it might need for logging, such as updating other channels.  */
+  if (current_interp_set_logging (1, output, NULL) == 0)
+    {
+      gdb_stdout = output;
+      gdb_stdlog = output;
+      gdb_stderr = output;
+      gdb_stdtarg = output;
+      gdb_stdtargerr = output;
+    }
+
   logging_no_redirect_file = new_logging_no_redirect_file;
 
   /* There is a former output pushed on the ui_out_redirect stack.  We
@@ -127,12 +134,11 @@ set_logging_redirect (char *args, int from_tty, struct cmd_list_element *c)
      neither of it.  At least do not try to push OUTPUT if the pop
      already failed.  */
 
-  if (ui_out_redirect (uiout, NULL) < 0
-      || ui_out_redirect (uiout, output) < 0)
+  if (uiout->redirect (NULL) < 0
+      || uiout->redirect (output) < 0)
     warning (_("Current output protocol does not support redirection"));
 
-  if (logging_redirect != 0)
-    do_cleanups (cleanups);
+  do_cleanups (cleanups);
 }
 
 static void
@@ -146,26 +152,34 @@ show_logging_redirect (struct ui_file *file, int from_tty,
 static void
 pop_output_files (void)
 {
-  /* Only delete one of the files -- they are all set to the same
-     value.  */
-  ui_file_delete (gdb_stdout);
   if (logging_no_redirect_file)
     {
       ui_file_delete (logging_no_redirect_file);
       logging_no_redirect_file = NULL;
     }
-  gdb_stdout = saved_output.out;
-  gdb_stderr = saved_output.err;
-  gdb_stdlog = saved_output.log;
-  gdb_stdtarg = saved_output.targ;
-  gdb_stdtargerr = saved_output.targ;
+
+  if (current_interp_set_logging (0, NULL, NULL) == 0)
+    {
+      /* Only delete one of the files -- they are all set to the same
+        value.  */
+      ui_file_delete (gdb_stdout);
+
+      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;
+    }
+
   saved_output.out = NULL;
   saved_output.err = NULL;
   saved_output.log = NULL;
   saved_output.targ = NULL;
   saved_output.targerr = NULL;
 
-  ui_out_redirect (uiout, NULL);
+  /* Stay consistent with handle_redirections.  */
+  if (!current_uiout->is_mi_like_p ())
+    current_uiout->redirect (NULL);
 }
 
 /* This is a helper for the `set logging' command.  */
@@ -174,6 +188,7 @@ handle_redirections (int from_tty)
 {
   struct cleanup *cleanups;
   struct ui_file *output;
+  struct ui_file *no_redirect_file = NULL;
 
   if (saved_filename != NULL)
     {
@@ -190,7 +205,7 @@ handle_redirections (int from_tty)
   /* Redirects everything to gdb_stdout while this is running.  */
   if (!logging_redirect)
     {
-      struct ui_file *no_redirect_file = output;
+      no_redirect_file = output;
 
       output = tee_file_new (gdb_stdout, 0, no_redirect_file, 0);
       if (output == NULL)
@@ -219,14 +234,22 @@ handle_redirections (int from_tty)
   saved_output.targ = gdb_stdtarg;
   saved_output.targerr = gdb_stdtargerr;
 
-  gdb_stdout = output;
-  gdb_stderr = output;
-  gdb_stdlog = output;
-  gdb_stdtarg = output;
-  gdb_stdtargerr = output;
+  /* Let the interpreter do anything it needs.  */
+  if (current_interp_set_logging (1, output, no_redirect_file) == 0)
+    {
+      gdb_stdout = output;
+      gdb_stdlog = output;
+      gdb_stderr = output;
+      gdb_stdtarg = output;
+      gdb_stdtargerr = output;
+    }
 
-  if (ui_out_redirect (uiout, output) < 0)
-    warning (_("Current output protocol does not support redirection"));
+  /* Don't do the redirect for MI, it confuses MI's ui-out scheme.  */
+  if (!current_uiout->is_mi_like_p ())
+    {
+      if (current_uiout->redirect (output) < 0)
+       warning (_("Current output protocol does not support redirection"));
+    }
 }
 
 static void
@@ -258,13 +281,12 @@ set_logging_off (char *args, int from_tty)
 static void
 set_logging_command (char *args, int from_tty)
 {
-  printf_unfiltered (_("\
-\"set logging\" lets you log output to a file.\n\
-Usage: set logging on [FILENAME]\n\
-       set logging off\n\
-       set logging file FILENAME\n\
-       set logging overwrite [on|off]\n\
-       set logging redirect [on|off]\n"));
+  printf_unfiltered (_("\"set logging\" lets you log output to a file.\n"
+                      "Usage: set logging on [FILENAME]\n"
+                      "       set logging off\n"
+                      "       set logging file FILENAME\n"
+                      "       set logging overwrite [on|off]\n"
+                      "       set logging redirect [on|off]\n"));
 }
 
 static void
This page took 0.030522 seconds and 4 git commands to generate.