gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / gdb / infcmd.c
index 62890bde2a22de57e90616a65d1b8b5d6e9136ba..891da91c806e42612ded631e7063b942e8056d54 100644 (file)
@@ -151,12 +151,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 +257,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
@@ -914,18 +788,21 @@ continue_command (const char *args, int from_tty)
   continue_1 (all_threads_p);
 }
 \f
-/* Record the starting point of a "step" or "next" command.  */
+/* Record in TP the starting point of a "step" or "next" command.  */
 
 static void
-set_step_frame (void)
+set_step_frame (thread_info *tp)
 {
+  /* This can be removed once this function no longer implicitly relies on the
+     inferior_ptid value.  */
+  gdb_assert (inferior_ptid == tp->ptid);
+
   frame_info *frame = get_current_frame ();
 
   symtab_and_line sal = find_frame_sal (frame);
-  set_step_info (frame, sal);
+  set_step_info (tp, frame, sal);
 
   CORE_ADDR pc = get_frame_pc (frame);
-  thread_info *tp = inferior_thread ();
   tp->control.step_start_function = find_pc_function (pc);
 }
 
@@ -1002,7 +879,7 @@ step_command_fsm_prepare (struct step_command_fsm *sm,
   thread->control.stepping_command = 1;
 }
 
-static int prepare_one_step (struct step_command_fsm *sm);
+static int prepare_one_step (thread_info *, struct step_command_fsm *sm);
 
 static void
 step_1 (int skip_subroutines, int single_inst, const char *count_string)
@@ -1040,7 +917,7 @@ step_1 (int skip_subroutines, int single_inst, const char *count_string)
      loop.  Let the continuation figure out how many other steps we
      need to do, and handle them one at the time, through
      step_once.  */
-  if (!prepare_one_step (step_sm))
+  if (!prepare_one_step (thr, step_sm))
     proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
   else
     {
@@ -1070,7 +947,7 @@ step_command_fsm::should_stop (struct thread_info *tp)
       /* There are more steps to make, and we did stop due to
         ending a stepping range.  Do another step.  */
       if (--count > 0)
-       return prepare_one_step (this);
+       return prepare_one_step (tp, this);
 
       set_finished ();
     }
@@ -1102,19 +979,17 @@ step_command_fsm::do_async_reply_reason ()
    resumed.  */
 
 static int
-prepare_one_step (struct step_command_fsm *sm)
+prepare_one_step (thread_info *tp, struct step_command_fsm *sm)
 {
+  /* This can be removed once this function no longer implicitly relies on the
+     inferior_ptid value.  */
+  gdb_assert (inferior_ptid == tp->ptid);
+
   if (sm->count > 0)
     {
       struct frame_info *frame = get_current_frame ();
 
-      /* Don't assume THREAD is a valid thread id.  It is set to -1 if
-        the longjmp breakpoint was not required.  Use the
-        INFERIOR_PTID thread instead, which is the same thread when
-        THREAD is set.  */
-      struct thread_info *tp = inferior_thread ();
-
-      set_step_frame ();
+      set_step_frame (tp);
 
       if (!sm->single_inst)
        {
@@ -1146,7 +1021,7 @@ prepare_one_step (struct step_command_fsm *sm)
                  || !function_name_is_marked_for_skip (fn, sal))
                {
                  sm->count--;
-                 return prepare_one_step (sm);
+                 return prepare_one_step (tp, sm);
                }
            }
 
@@ -1488,7 +1363,7 @@ until_next_command (int from_tty)
   struct until_next_fsm *sm;
 
   clear_proceed_status (0);
-  set_step_frame ();
+  set_step_frame (tp);
 
   frame = get_current_frame ();
 
@@ -1588,7 +1463,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)
@@ -1679,7 +1554,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
@@ -1743,7 +1618,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;
 
@@ -1945,7 +1820,7 @@ finish_command (const char *arg, int from_tty)
         called by that frame.  We don't use the magic "1" value for
         step_range_end, because then infrun will think this is nexti,
         and not step over the rest of this inlined function call.  */
-      set_step_info (frame, {});
+      set_step_info (tp, frame, {});
       tp->control.step_range_start = get_frame_pc (frame);
       tp->control.step_range_end = tp->control.step_range_start;
       tp->control.step_over_calls = STEP_OVER_ALL;
@@ -2249,8 +2124,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);
@@ -2259,9 +2134,7 @@ default_print_one_register_info (struct ui_file *file,
       get_user_print_options (&opts);
       opts.deref_ref = 1;
 
-      val_print (regtype,
-                value_embedded_offset (val), 0,
-                &format_stream, 0, val, &opts, current_language);
+      common_val_print (val, &format_stream, 0, &opts, current_language);
 
       if (print_raw_format)
        {
@@ -2279,9 +2152,7 @@ default_print_one_register_info (struct ui_file *file,
       /* Print the register in hex.  */
       get_formatted_print_options (&opts, 'x');
       opts.deref_ref = 1;
-      val_print (regtype,
-                value_embedded_offset (val), 0,
-                &format_stream, 0, val, &opts, current_language);
+      common_val_print (val, &format_stream, 0, &opts, current_language);
       /* If not a vector register, print it also according to its
         natural format.  */
       if (print_raw_format && TYPE_VECTOR (regtype) == 0)
@@ -2289,9 +2160,7 @@ default_print_one_register_info (struct ui_file *file,
          pad_to_column (format_stream, value_column_2);
          get_user_print_options (&opts);
          opts.deref_ref = 1;
-         val_print (regtype,
-                    value_embedded_offset (val), 0,
-                    &format_stream, 0, val, &opts, current_language);
+         common_val_print (val, &format_stream, 0, &opts, current_language);
        }
     }
 
@@ -3046,14 +2915,6 @@ info_float_command (const char *args, int from_tty)
   gdbarch_print_float_info (get_frame_arch (frame), gdb_stdout, frame, args);
 }
 \f
-static void
-unset_command (const char *args, int from_tty)
-{
-  printf_filtered (_("\"unset\" must be followed by the "
-                    "name of an unset subcommand.\n"));
-  help_list (unsetlist, "unset ", all_commands, gdb_stdout);
-}
-
 /* Implement `info proc' family of commands.  */
 
 static void
@@ -3193,7 +3054,7 @@ is restored."),
   cmd_name = "inferior-tty";
   c = lookup_cmd (&cmd_name, setlist, "", -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,
@@ -3234,9 +3095,9 @@ give the program being debugged.  With no arguments, prints the entire\n\
 environment to be given to the program."), &showlist);
   set_cmd_completer (c, noop_completer);
 
-  add_prefix_cmd ("unset", no_class, unset_command,
-                 _("Complement to certain \"set\" commands."),
-                 &unsetlist, "unset ", 0, &cmdlist);
+  add_basic_prefix_cmd ("unset", no_class,
+                       _("Complement to certain \"set\" commands."),
+                       &unsetlist, "unset ", 0, &cmdlist);
 
   c = add_cmd ("environment", class_run, unset_environment_command, _("\
 Cancel environment variable VAR for the program.\n\
@@ -3331,14 +3192,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.02834 seconds and 4 git commands to generate.