Fix crash when exiting TUI with gdb -tui
[deliverable/binutils-gdb.git] / gdb / cli / cli-cmds.c
index c2ba3a4238ab64a0a2fa9a2ffb158f12237d50a8..cd6f7856599d1d672c0f738a713f767b0bc8b6dc 100644 (file)
@@ -191,26 +191,17 @@ error_no_arg (const char *why)
   error (_("Argument required (%s)."), why);
 }
 
-/* The "info" command is defined as a prefix, with allow_unknown = 0.
-   Therefore, its own definition is called only for "info" with no
-   args.  */
+/* This implements the "info" prefix command.  Normally such commands
+   are automatically handled by add_basic_prefix_cmd, but in this case
+   a separate command is used so that it can be hooked into by
+   gdb-gdb.gdb.  */
 
 static void
 info_command (const char *arg, int from_tty)
 {
-  printf_unfiltered (_("\"info\" must be followed by "
-                      "the name of an info command.\n"));
   help_list (infolist, "info ", all_commands, gdb_stdout);
 }
 
-/* The "show" command with no arguments shows all the settings.  */
-
-static void
-show_command (const char *arg, int from_tty)
-{
-  cmd_show_list (showlist, from_tty, "");
-}
-
 /* See cli/cli-cmds.h.  */
 
 void
@@ -839,8 +830,8 @@ shell_escape (const char *arg, int from_tty)
   /* Make sure to return to the directory GDB thinks it is, in case
      the shell command we just ran changed it.  */
   chdir (current_directory);
-  exit_status_set_internal_vars (rc);
 #endif
+  exit_status_set_internal_vars (rc);
 #else /* Can fork.  */
   int status, pid;
 
@@ -945,7 +936,7 @@ edit_command (const char *arg, int from_tty)
            error (_("No source file for address %s."),
                   paddress (get_current_arch (), sal.pc));
 
-         gdbarch = get_objfile_arch (SYMTAB_OBJFILE (sal.symtab));
+         gdbarch = SYMTAB_OBJFILE (sal.symtab)->arch ();
           sym = find_pc_function (sal.pc);
           if (sym)
            printf_filtered ("%s is in %s (%s:%d).\n",
@@ -1277,7 +1268,7 @@ list_command (const char *arg, int from_tty)
        error (_("No source file for address %s."),
               paddress (get_current_arch (), sal.pc));
 
-      gdbarch = get_objfile_arch (SYMTAB_OBJFILE (sal.symtab));
+      gdbarch = SYMTAB_OBJFILE (sal.symtab)->arch ();
       sym = find_pc_function (sal.pc);
       if (sym)
        printf_filtered ("%s is in %s (%s:%d).\n",
@@ -1703,8 +1694,29 @@ alias_command (const char *args, int from_tty)
   /* ALIAS must not exist.  */
   std::string alias_string (argv_to_string (alias_argv, alias_argc));
   alias = alias_string.c_str ();
-  if (valid_command_p (alias))
-    error (_("Alias already exists: %s"), alias);
+  {
+    cmd_list_element *alias_cmd, *prefix_cmd, *cmd;
+
+    if (lookup_cmd_composition (alias, &alias_cmd, &prefix_cmd, &cmd))
+      {
+       const char *alias_name = alias_argv[alias_argc-1];
+
+       /* If we found an existing ALIAS_CMD, check that the prefix differ or
+          the name differ.  */
+
+       if (alias_cmd != nullptr
+           && alias_cmd->prefix == prefix_cmd
+           && strcmp (alias_name, alias_cmd->name) == 0)
+         error (_("Alias already exists: %s"), alias);
+
+       /* Check ALIAS differs from the found CMD.  */
+
+       if (cmd->prefix == prefix_cmd
+           && strcmp (alias_name, cmd->name) == 0)
+         error (_("Alias %s is the name of an existing command"), alias);
+      }
+  }
+
 
   /* If ALIAS is one word, it is an alias for the entire COMMAND.
      Example: alias spe = set print elements
@@ -1852,20 +1864,6 @@ filter_sals (std::vector<symtab_and_line> &sals)
   sals.erase (from, sals.end ());
 }
 
-static void
-set_debug (const char *arg, int from_tty)
-{
-  printf_unfiltered (_("\"set debug\" must be followed by "
-                      "the name of a debug subcommand.\n"));
-  help_list (setdebuglist, "set debug ", all_commands, gdb_stdout);
-}
-
-static void
-show_debug (const char *args, int from_tty)
-{
-  cmd_show_list (showdebuglist, from_tty, "");
-}
-
 void
 init_cmd_lists (void)
 {
@@ -1935,8 +1933,8 @@ setting_cmd (const char *fnname, struct cmd_list_element *showlist,
 
   struct type *type0 = check_typedef (value_type (argv[0]));
 
-  if (TYPE_CODE (type0) != TYPE_CODE_ARRAY
-      && TYPE_CODE (type0) != TYPE_CODE_STRING)
+  if (type0->code () != TYPE_CODE_ARRAY
+      && type0->code () != TYPE_CODE_STRING)
     error (_("First argument of %s must be a string."), fnname);
 
   const char *a0 = (const char *) value_contents (argv[0]);
@@ -2113,8 +2111,9 @@ gdb_maint_setting_str_internal_fn (struct gdbarch *gdbarch,
                                 gdbarch);
 }
 
+void _initialize_cli_cmds ();
 void
-_initialize_cli_cmds (void)
+_initialize_cli_cmds ()
 {
   struct cmd_list_element *c;
 
@@ -2151,6 +2150,12 @@ Variable lookups are done with respect to the selected frame.\n\
 When the program being debugged stops, gdb selects the innermost frame.\n\
 The commands below can be used to select other frames by number or address."),
           &cmdlist);
+#ifdef TUI
+  add_cmd ("text-user-interface", class_tui,
+          _("TUI is the GDB text based interface.\n\
+In TUI mode, GDB can display several text windows showing\n\
+the source file, the processor registers, the program disassembly, ..."), &cmdlist);
+#endif
   add_cmd ("running", class_run, _("Running the program."), &cmdlist);
 
   /* Define general commands.  */
@@ -2207,12 +2212,12 @@ Show verbosity."), NULL,
                           show_info_verbose,
                           &setlist, &showlist);
 
-  add_prefix_cmd ("history", class_support, set_history,
-                 _("Generic command for setting command history parameters."),
-                 &sethistlist, "set history ", 0, &setlist);
-  add_prefix_cmd ("history", class_support, show_history,
-                 _("Generic command for showing command history parameters."),
-                 &showhistlist, "show history ", 0, &showlist);
+  add_basic_prefix_cmd ("history", class_support, _("\
+Generic command for setting command history parameters."),
+                       &sethistlist, "set history ", 0, &setlist);
+  add_show_prefix_cmd ("history", class_support, _("\
+Generic command for showing command history parameters."),
+                      &showhistlist, "show history ", 0, &showlist);
 
   add_setshow_boolean_cmd ("expansion", no_class, &history_expansion_p, _("\
 Set history expansion on command input."), _("\
@@ -2231,11 +2236,11 @@ Generic command for showing things about the program being debugged."),
   add_com ("complete", class_obscure, complete_command,
           _("List the completions for the rest of the line as a command."));
 
-  add_prefix_cmd ("show", class_info, show_command, _("\
+  c = add_show_prefix_cmd ("show", class_info, _("\
 Generic command for showing things about the debugger."),
-                 &showlist, "show ", 0, &cmdlist);
+                          &showlist, "show ", 0, &cmdlist);
   /* Another way to get at the same thing.  */
-  add_info ("set", show_command, _("Show all GDB settings."));
+  add_alias_cmd ("set", c, class_info, 0, &infolist);
 
   c = add_com ("with", class_vars, with_command, _("\
 Temporarily set SETTING to VALUE, run COMMAND, and restore SETTING.\n\
@@ -2323,13 +2328,13 @@ from the target."),
                                       show_remote_timeout,
                                       &setlist, &showlist);
 
-  add_prefix_cmd ("debug", no_class, set_debug,
-                 _("Generic command for setting gdb debugging flags."),
-                 &setdebuglist, "set debug ", 0, &setlist);
+  add_basic_prefix_cmd ("debug", no_class,
+                       _("Generic command for setting gdb debugging flags."),
+                       &setdebuglist, "set debug ", 0, &setlist);
 
-  add_prefix_cmd ("debug", no_class, show_debug,
-                 _("Generic command for showing gdb debugging flags."),
-                 &showdebuglist, "show debug ", 0, &showlist);
+  add_show_prefix_cmd ("debug", no_class,
+                      _("Generic command for showing gdb debugging flags."),
+                      &showdebuglist, "show debug ", 0, &showlist);
 
   c = add_com ("shell", class_support, shell_command, _("\
 Execute the rest of the line as a shell command.\n\
@@ -2455,7 +2460,7 @@ Usage: alias [-a] [--] ALIAS = COMMAND\n\
 ALIAS is the name of the alias command to create.\n\
 COMMAND is the command being aliased to.\n\
 If \"-a\" is specified, the command is an abbreviation,\n\
-and will not appear in help command list output.\n\
+and will not be used in command completion.\n\
 \n\
 Examples:\n\
 Make \"spe\" an alias of \"set print elements\":\n\
This page took 0.025856 seconds and 4 git commands to generate.