Change the pager to a ui_file
[binutils-gdb.git] / gdb / cli / cli-cmds.c
index 138a146c7d6a4a8bcaa12d7f1f0c7b70d8fe5e79..b6baca948596aba8d11c29dd985dffc12c2ac31f 100644 (file)
@@ -1,6 +1,6 @@
 /* GDB CLI commands.
 
-   Copyright (C) 2000-2021 Free Software Foundation, Inc.
+   Copyright (C) 2000-2022 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -24,7 +24,7 @@
 #include "target.h"    /* For baud_rate, remote_debug and remote_timeout.  */
 #include "gdbsupport/gdb_wait.h"       /* For shell escape implementation.  */
 #include "gdbcmd.h"
-#include "gdb_regex.h" /* Used by apropos_command.  */
+#include "gdbsupport/gdb_regex.h"      /* Used by apropos_command.  */
 #include "gdb_vfork.h"
 #include "linespec.h"
 #include "expression.h"
@@ -192,6 +192,11 @@ static const char *const script_ext_enums[] = {
 
 static const char *script_ext_mode = script_ext_soft;
 \f
+
+/* User-controllable flag to suppress event notification on CLI.  */
+
+static bool user_wants_cli_suppress_notification = false;
+
 /* Utility used everywhere when at least one argument is needed and
    none is supplied.  */
 
@@ -501,14 +506,14 @@ pwd_command (const char *args, int from_tty)
           safe_strerror (errno));
 
   if (strcmp (cwd.get (), current_directory) != 0)
-    printf_unfiltered (_("Working directory %ps\n (canonically %ps).\n"),
-                      styled_string (file_name_style.style (),
-                                     current_directory),
-                      styled_string (file_name_style.style (), cwd.get ()));
+    printf_filtered (_("Working directory %ps\n (canonically %ps).\n"),
+                    styled_string (file_name_style.style (),
+                                   current_directory),
+                    styled_string (file_name_style.style (), cwd.get ()));
   else
-    printf_unfiltered (_("Working directory %ps.\n"),
-                      styled_string (file_name_style.style (),
-                                     current_directory));
+    printf_filtered (_("Working directory %ps.\n"),
+                    styled_string (file_name_style.style (),
+                                   current_directory));
 }
 
 void
@@ -838,10 +843,10 @@ echo_command (const char *text, int from_tty)
          printf_filtered ("%c", c);
       }
 
-  reset_terminal_style (gdb_stdout);
+  gdb_stdout->reset_style ();
 
   /* Force this output to appear now.  */
-  wrap_here ("");
+  gdb_stdout->wrap_here (0);
   gdb_flush (gdb_stdout);
 }
 
@@ -943,7 +948,6 @@ edit_command (const char *arg, int from_tty)
   struct symtab_and_line sal;
   struct symbol *sym;
   const char *editor;
-  char *p;
   const char *fn;
 
   /* Pull in the current default source line if necessary.  */
@@ -969,6 +973,10 @@ edit_command (const char *arg, int from_tty)
       arg1 = arg;
       event_location_up location = string_to_event_location (&arg1,
                                                             current_language);
+
+      if (*arg1)
+       error (_("Junk at end of line specification."));
+
       std::vector<symtab_and_line> sals = decode_line_1 (location.get (),
                                                         DECODE_LINE_LIST_MODE,
                                                         NULL, NULL, 0);
@@ -988,9 +996,6 @@ edit_command (const char *arg, int from_tty)
 
       sal = sals[0];
 
-      if (*arg1)
-       error (_("Junk at end of line specification."));
-
       /* If line was specified by address, first print exactly which
         line, and which file.  In this case, sal.symtab == 0 means
         address is outside of all known source files, not that user
@@ -1003,7 +1008,7 @@ edit_command (const char *arg, int from_tty)
            error (_("No source file for address %s."),
                   paddress (get_current_arch (), sal.pc));
 
-         gdbarch = SYMTAB_OBJFILE (sal.symtab)->arch ();
+         gdbarch = sal.symtab->objfile ()->arch ();
          sym = find_pc_function (sal.pc);
          if (sym)
            printf_filtered ("%s is in %s (%s:%d).\n",
@@ -1032,9 +1037,9 @@ edit_command (const char *arg, int from_tty)
 
   /* Quote the file name, in case it has whitespace or other special
      characters.  */
-  p = xstrprintf ("%s +%d \"%s\"", editor, sal.line, fn);
-  shell_escape (p, from_tty);
-  xfree (p);
+  gdb::unique_xmalloc_ptr<char> p
+    = xstrprintf ("%s +%d \"%s\"", editor, sal.line, fn);
+  shell_escape (p.get (), from_tty);
 }
 
 /* The options for the "pipe" command.  */
@@ -1239,6 +1244,15 @@ list_command (const char *arg, int from_tty)
     {
       event_location_up location = string_to_event_location (&arg1,
                                                             current_language);
+
+      /* We know that the ARG string is not empty, yet the attempt to parse
+        a location from the string consumed no characters.  This most
+        likely means that the first thing in ARG looks like a location
+        condition, and so the string_to_event_location call stopped
+        parsing.  */
+      if (arg1 == arg)
+       error (_("Junk at end of line specification."));
+
       sals = decode_line_1 (location.get (), DECODE_LINE_LIST_MODE,
                            NULL, NULL, 0);
       filter_sals (sals);
@@ -1287,6 +1301,9 @@ list_command (const char *arg, int from_tty)
          event_location_up location
            = string_to_event_location (&arg1, current_language);
 
+         if (*arg1)
+           error (_("Junk at end of line specification."));
+
          std::vector<symtab_and_line> sals_end
            = (dummy_beg
               ? decode_line_1 (location.get (), DECODE_LINE_LIST_MODE,
@@ -1330,7 +1347,7 @@ list_command (const char *arg, int from_tty)
        error (_("No source file for address %s."),
               paddress (get_current_arch (), sal.pc));
 
-      gdbarch = SYMTAB_OBJFILE (sal.symtab)->arch ();
+      gdbarch = sal.symtab->objfile ()->arch ();
       sym = find_pc_function (sal.pc);
       if (sym)
        printf_filtered ("%s is in %s (%s:%d).\n",
@@ -2034,8 +2051,8 @@ ambiguous_line_spec (gdb::array_view<const symtab_and_line> sals,
 static int
 cmp_symtabs (const symtab_and_line &sala, const symtab_and_line &salb)
 {
-  const char *dira = SYMTAB_DIRNAME (sala.symtab);
-  const char *dirb = SYMTAB_DIRNAME (salb.symtab);
+  const char *dira = sala.symtab->dirname ();
+  const char *dirb = salb.symtab->dirname ();
   int r;
 
   if (dira == NULL)
@@ -2124,6 +2141,28 @@ show_max_user_call_depth (struct ui_file *file, int from_tty,
                    value);
 }
 
+/* Implement 'show suppress-cli-notifications'.  */
+
+static void
+show_suppress_cli_notifications (ui_file *file, int from_tty,
+                                cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("Suppression of printing CLI notifications "
+                           "is %s.\n"), value);
+}
+
+/* Implement 'set suppress-cli-notifications'.  */
+
+static void
+set_suppress_cli_notifications (const char *args, int from_tty,
+                               cmd_list_element *c)
+{
+  cli_suppress_notification.user_selected_context
+    = user_wants_cli_suppress_notification;
+  cli_suppress_notification.normal_stop
+    = user_wants_cli_suppress_notification;
+}
+
 /* Returns the cmd_list_element in SHOWLIST corresponding to the first
    argument of ARGV, which must contain one single value.
    Throws an error if no value provided, or value not correct.
@@ -2446,7 +2485,7 @@ strict == evaluate script according to filename extension, error if not supporte
   cmd_list_element *quit_cmd
     = add_com ("quit", class_support, quit_command, _("\
 Exit gdb.\n\
-Usage: quit [EXPR]\n\
+Usage: quit [EXPR] or exit [EXPR]\n\
 The optional expression EXPR, if present, is evaluated and the result\n\
 used as GDB's exit code.  The default is zero."));
   cmd_list_element *help_cmd
@@ -2454,6 +2493,7 @@ used as GDB's exit code.  The default is zero."));
               _("Print list of commands."));
   set_cmd_completer (help_cmd, command_completer);
   add_com_alias ("q", quit_cmd, class_support, 1);
+  add_com_alias ("exit", quit_cmd, class_support, 1);
   add_com_alias ("h", help_cmd, class_support, 1);
 
   add_setshow_boolean_cmd ("verbose", class_support, &info_verbose, _("\
@@ -2721,6 +2761,18 @@ Make \"wLapPeu\" an alias of 2 nested \"with\":\n\
 
   set_cmd_completer_handle_brkchars (c, alias_command_completer);
 
+  add_setshow_boolean_cmd ("suppress-cli-notifications", no_class,
+                          &user_wants_cli_suppress_notification,
+                          _("\
+Set whether printing notifications on CLI is suppressed."), _("\
+Show whether printing notifications on CLI is suppressed."), _("\
+When on, printing notifications (such as inferior/thread switch)\n\
+on CLI is suppressed."),
+                          set_suppress_cli_notifications,
+                          show_suppress_cli_notifications,
+                          &setlist,
+                          &showlist);
+
   const char *source_help_text = xstrprintf (_("\
 Read commands from a file named FILE.\n\
 \n\
@@ -2730,7 +2782,7 @@ Usage: source [-s] [-v] FILE\n\
 -v: each command in FILE is echoed as it is executed.\n\
 \n\
 Note that the file \"%s\" is read automatically in this way\n\
-when GDB is started."), GDBINIT);
+when GDB is started."), GDBINIT).release ();
   c = add_cmd ("source", class_support, source_command,
               source_help_text, &cmdlist);
   set_cmd_completer (c, filename_completer);