gdb: make inferior::terminal a unique ptr
[deliverable/binutils-gdb.git] / gdb / infcmd.c
index 9bbb413d4e494cf3b79040e27afde3607281a695..48d6a91c0c2499ae7fcd4c0aef8f02d6c4da6d34 100644 (file)
@@ -108,10 +108,8 @@ int stopped_by_random_signal;
 void 
 set_inferior_io_terminal (const char *terminal_name)
 {
-  xfree (current_inferior ()->terminal);
-
   if (terminal_name != NULL && *terminal_name != '\0')
-    current_inferior ()->terminal = xstrdup (terminal_name);
+    current_inferior ()->terminal.reset (xstrdup (terminal_name));
   else
     current_inferior ()->terminal = NULL;
 }
@@ -119,7 +117,7 @@ set_inferior_io_terminal (const char *terminal_name)
 const char *
 get_inferior_io_terminal (void)
 {
-  return current_inferior ()->terminal;
+  return current_inferior ()->terminal.get ();
 }
 
 static void
@@ -151,12 +149,10 @@ get_inferior_args (void)
 {
   if (current_inferior ()->argc != 0)
     {
-      char *n;
-
-      n = construct_inferior_arguments (current_inferior ()->argc,
-                                       current_inferior ()->argv);
-      set_inferior_args (n);
-      xfree (n);
+      gdb::array_view<char * const> args (current_inferior ()->argv,
+                                          current_inferior ()->argc);
+      std::string n = construct_inferior_arguments (args);
+      set_inferior_args (n.c_str ());
     }
 
   if (current_inferior ()->args == NULL)
@@ -259,130 +255,6 @@ server's cwd if remote debugging.\n"));
                        "when starting the inferior is \"%s\".\n"), cwd);
 }
 
-\f
-/* Compute command-line string given argument vector.  This does the
-   same shell processing as fork_inferior.  */
-
-char *
-construct_inferior_arguments (int argc, char **argv)
-{
-  char *result;
-
-  /* ARGC should always be at least 1, but we double check this
-     here.  This is also needed to silence -Werror-stringop
-     warnings.  */
-  gdb_assert (argc > 0);
-
-  if (startup_with_shell)
-    {
-#ifdef __MINGW32__
-      /* This holds all the characters considered special to the
-        Windows shells.  */
-      static const char special[] = "\"!&*|[]{}<>?`~^=;, \t\n";
-      static const char quote = '"';
-#else
-      /* This holds all the characters considered special to the
-        typical Unix shells.  We include `^' because the SunOS
-        /bin/sh treats it as a synonym for `|'.  */
-      static const char special[] = "\"!#$&*()\\|[]{}<>?'`~^; \t\n";
-      static const char quote = '\'';
-#endif
-      int i;
-      int length = 0;
-      char *out, *cp;
-
-      /* We over-compute the size.  It shouldn't matter.  */
-      for (i = 0; i < argc; ++i)
-       length += 3 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0');
-
-      result = (char *) xmalloc (length);
-      out = result;
-
-      for (i = 0; i < argc; ++i)
-       {
-         if (i > 0)
-           *out++ = ' ';
-
-         /* Need to handle empty arguments specially.  */
-         if (argv[i][0] == '\0')
-           {
-             *out++ = quote;
-             *out++ = quote;
-           }
-         else
-           {
-#ifdef __MINGW32__
-             int quoted = 0;
-
-             if (strpbrk (argv[i], special))
-               {
-                 quoted = 1;
-                 *out++ = quote;
-               }
-#endif
-             for (cp = argv[i]; *cp; ++cp)
-               {
-                 if (*cp == '\n')
-                   {
-                     /* A newline cannot be quoted with a backslash (it
-                        just disappears), only by putting it inside
-                        quotes.  */
-                     *out++ = quote;
-                     *out++ = '\n';
-                     *out++ = quote;
-                   }
-                 else
-                   {
-#ifdef __MINGW32__
-                     if (*cp == quote)
-#else
-                     if (strchr (special, *cp) != NULL)
-#endif
-                       *out++ = '\\';
-                     *out++ = *cp;
-                   }
-               }
-#ifdef __MINGW32__
-             if (quoted)
-               *out++ = quote;
-#endif
-           }
-       }
-      *out = '\0';
-    }
-  else
-    {
-      /* In this case we can't handle arguments that contain spaces,
-        tabs, or newlines -- see breakup_args().  */
-      int i;
-      int length = 0;
-
-      for (i = 0; i < argc; ++i)
-       {
-         char *cp = strchr (argv[i], ' ');
-         if (cp == NULL)
-           cp = strchr (argv[i], '\t');
-         if (cp == NULL)
-           cp = strchr (argv[i], '\n');
-         if (cp != NULL)
-           error (_("can't handle command-line "
-                    "argument containing whitespace"));
-         length += strlen (argv[i]) + 1;
-       }
-
-      result = (char *) xmalloc (length);
-      result[0] = '\0';
-      for (i = 0; i < argc; ++i)
-       {
-         if (i > 0)
-           strcat (result, " ");
-         strcat (result, argv[i]);
-       }
-    }
-
-  return result;
-}
-\f
 
 /* This function strips the '&' character (indicating background
    execution) that is added as *the last* of the arguments ARGS of a
@@ -1589,7 +1461,7 @@ get_return_value (struct value *function, struct type *value_type)
   struct value *value;
 
   value_type = check_typedef (value_type);
-  gdb_assert (TYPE_CODE (value_type) != TYPE_CODE_VOID);
+  gdb_assert (value_type->code () != TYPE_CODE_VOID);
 
   /* FIXME: 2003-09-27: When returning from a nested inferior function
      call, it's possible (with no help from the architecture vector)
@@ -1680,7 +1552,7 @@ void
 print_return_value (struct ui_out *uiout, struct return_value_info *rv)
 {
   if (rv->type == NULL
-      || TYPE_CODE (check_typedef (rv->type)) == TYPE_CODE_VOID)
+      || check_typedef (rv->type)->code () == TYPE_CODE_VOID)
     return;
 
   try
@@ -1744,7 +1616,7 @@ finish_command_fsm::should_stop (struct thread_info *tp)
        internal_error (__FILE__, __LINE__,
                        _("finish_command: function has no target type"));
 
-      if (TYPE_CODE (check_typedef (rv->type)) != TYPE_CODE_VOID)
+      if (check_typedef (rv->type)->code () != TYPE_CODE_VOID)
        {
          struct value *func;
 
@@ -2250,8 +2122,8 @@ default_print_one_register_info (struct ui_file *file,
 
   /* If virtual format is floating, print it that way, and in raw
      hex.  */
-  if (TYPE_CODE (regtype) == TYPE_CODE_FLT
-      || TYPE_CODE (regtype) == TYPE_CODE_DECFLOAT)
+  if (regtype->code () == TYPE_CODE_FLT
+      || regtype->code () == TYPE_CODE_DECFLOAT)
     {
       struct value_print_options opts;
       const gdb_byte *valaddr = value_contents_for_printing (val);
@@ -3178,9 +3050,9 @@ is restored."),
                                     show_inferior_tty_command,
                                     &setlist, &showlist);
   cmd_name = "inferior-tty";
-  c = lookup_cmd (&cmd_name, setlist, "", -1, 1);
+  c = lookup_cmd (&cmd_name, setlist, "", NULL, -1, 1);
   gdb_assert (c != NULL);
-  add_alias_cmd ("tty", c, class_alias, 0, &cmdlist);
+  add_alias_cmd ("tty", c, class_run, 0, &cmdlist);
 
   cmd_name = "args";
   add_setshow_string_noescape_cmd (cmd_name, class_run,
@@ -3191,7 +3063,7 @@ Follow this command with any number of args, to be passed to the program."),
                                   set_args_command,
                                   show_args_command,
                                   &setlist, &showlist);
-  c = lookup_cmd (&cmd_name, setlist, "", -1, 1);
+  c = lookup_cmd (&cmd_name, setlist, "", NULL, -1, 1);
   gdb_assert (c != NULL);
   set_cmd_completer (c, filename_completer);
 
@@ -3210,7 +3082,7 @@ working directory."),
                                   set_cwd_command,
                                   show_cwd_command,
                                   &setlist, &showlist);
-  c = lookup_cmd (&cmd_name, setlist, "", -1, 1);
+  c = lookup_cmd (&cmd_name, setlist, "", NULL, -1, 1);
   gdb_assert (c != NULL);
   set_cmd_completer (c, filename_completer);
 
@@ -3318,14 +3190,14 @@ Step one instruction exactly.\n\
 Usage: stepi [N]\n\
 Argument N means step N times (or till program stops for another \
 reason)."));
-  add_com_alias ("si", "stepi", class_alias, 0);
+  add_com_alias ("si", "stepi", class_run, 0);
 
   add_com ("nexti", class_run, nexti_command, _("\
 Step one instruction, but proceed through subroutine calls.\n\
 Usage: nexti [N]\n\
 Argument N means step N times (or till program stops for another \
 reason)."));
-  add_com_alias ("ni", "nexti", class_alias, 0);
+  add_com_alias ("ni", "nexti", class_run, 0);
 
   add_com ("finish", class_run, finish_command, _("\
 Execute until selected stack frame returns.\n\
This page took 0.026767 seconds and 4 git commands to generate.