Remove the global stop_step in favour of a per-thread
[deliverable/binutils-gdb.git] / gdb / infcmd.c
index fead6d16a7aa8cd953d48325495c4ef6aadc8f4e..a4c6c94a47cc1bcd24cb900b8406974f67786c2f 100644 (file)
@@ -73,9 +73,6 @@ static void nofp_registers_info (char *, int);
 static void print_return_value (struct type *func_type,
                                struct type *value_type);
 
-static void finish_command_continuation (struct continuation_arg *, 
-                                        int error_p);
-
 static void until_next_command (int);
 
 static void until_command (char *, int);
@@ -108,7 +105,6 @@ static void jump_command (char *, int);
 
 static void step_1 (int, int, char *);
 static void step_once (int skip_subroutines, int single_inst, int count, int thread);
-static void step_1_continuation (struct continuation_arg *arg, int error_p);
 
 static void next_command (char *, int);
 
@@ -151,27 +147,15 @@ static char *inferior_io_terminal;
 
 ptid_t inferior_ptid;
 
-/* Last signal that the inferior received (why it stopped).  */
-
-enum target_signal stop_signal;
-
 /* Address at which inferior stopped.  */
 
 CORE_ADDR stop_pc;
 
-/* Chain containing status of breakpoint(s) that we have stopped at.  */
-
-bpstat stop_bpstat;
-
 /* Flag indicating that a command has proceeded the inferior past the
    current breakpoint.  */
 
 int breakpoint_proceeded;
 
-/* Nonzero if stopped due to a step command.  */
-
-int stop_step;
-
 /* Nonzero if stopped due to completion of a stack dummy routine.  */
 
 int stop_stack_dummy;
@@ -181,27 +165,6 @@ int stop_stack_dummy;
 
 int stopped_by_random_signal;
 
-/* Range to single step within.
-   If this is nonzero, respond to a single-step signal
-   by continuing to step if the pc is in this range.  */
-
-CORE_ADDR step_range_start;    /* Inclusive */
-CORE_ADDR step_range_end;      /* Exclusive */
-
-/* Stack frame address as of when stepping command was issued.
-   This is how we know when we step into a subroutine call,
-   and how to set the frame for the breakpoint used to step out.  */
-
-struct frame_id step_frame_id;
-
-enum step_over_calls_kind step_over_calls;
-
-/* If stepping, nonzero means step count is > 1
-   so don't print frame next time inferior stops
-   if it stops due to stepping.  */
-
-int step_multi;
-
 /* Environment to use for running inferior,
    in format described in environ.h.  */
 
@@ -491,11 +454,6 @@ run_command_1 (char *args, int from_tty, int tbreak_at_main)
      this function should probably be moved into target_pre_inferior.  */
   target_pre_inferior (from_tty);
 
-  /* Purge old solib objfiles. */
-  objfile_purge_solibs ();
-
-  clear_solib ();
-
   /* The comment here used to read, "The exec file is re-read every
      time we do a generic_mourn_inferior, so we just have to worry
      about the symbol file."  The `generic_mourn_inferior' function
@@ -512,6 +470,9 @@ run_command_1 (char *args, int from_tty, int tbreak_at_main)
 
   exec_file = (char *) get_exec_file (0);
 
+  if (non_stop && !target_supports_non_stop ())
+    error (_("The target does not support running in non-stop mode."));
+
   /* We keep symbols from add-symbol-file, on the grounds that the
      user might want to add some symbols before running the program
      (right?).  But sometimes (dynamic loading where the user manually
@@ -608,15 +569,56 @@ start_command (char *args, int from_tty)
   run_command_1 (args, from_tty, 1);
 } 
 
+static int
+proceed_thread_callback (struct thread_info *thread, void *arg)
+{
+  if (!is_stopped (thread->ptid))
+    return 0;
+
+  context_switch_to (thread->ptid);
+  clear_proceed_status ();
+  proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
+  return 0;
+}
+
+void
+continue_1 (int all_threads)
+{
+  ERROR_NO_INFERIOR;
+
+  if (non_stop && all_threads)
+    {
+      /* Don't error out if the current thread is running, because
+        there may be other stopped threads.  */
+      struct cleanup *old_chain;
+
+      /* Backup current thread and selected frame.  */
+      old_chain = make_cleanup_restore_current_thread ();
+
+      iterate_over_threads (proceed_thread_callback, NULL);
+
+      /* Restore selected ptid.  */
+      do_cleanups (old_chain);
+    }
+  else
+    {
+      ensure_not_running ();
+      clear_proceed_status ();
+      proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
+    }
+}
+
+/* continue [-a] [proceed-count] [&]  */
 void
-continue_command (char *proc_count_exp, int from_tty)
+continue_command (char *args, int from_tty)
 {
   int async_exec = 0;
+  int all_threads = 0;
   ERROR_NO_INFERIOR;
 
   /* Find out whether we must run in the background. */
-  if (proc_count_exp != NULL)
-    async_exec = strip_bg_char (&proc_count_exp);
+  if (args != NULL)
+    async_exec = strip_bg_char (&args);
 
   /* If we must run in the background, but the target can't do it,
      error out. */
@@ -631,19 +633,51 @@ continue_command (char *proc_count_exp, int from_tty)
       async_disable_stdin ();
     }
 
-  /* If have argument (besides '&'), set proceed count of breakpoint
-     we stopped at.  */
-  if (proc_count_exp != NULL)
+  if (args != NULL)
     {
-      bpstat bs = stop_bpstat;
+      if (strncmp (args, "-a", sizeof ("-a") - 1) == 0)
+       {
+         all_threads = 1;
+         args += sizeof ("-a") - 1;
+         if (*args == '\0')
+           args = NULL;
+       }
+    }
+
+  if (!non_stop && all_threads)
+    error (_("`-a' is meaningless in all-stop mode."));
+
+  if (args != NULL && all_threads)
+    error (_("\
+Can't resume all threads and specify proceed count simultaneously."));
+
+  /* If we have an argument left, set proceed count of breakpoint we
+     stopped at.  */
+  if (args != NULL)
+    {
+      bpstat bs = NULL;
       int num, stat;
       int stopped = 0;
+      struct thread_info *tp;
+
+      if (non_stop)
+       tp = find_thread_pid (inferior_ptid);
+      else
+       {
+         ptid_t last_ptid;
+         struct target_waitstatus ws;
+
+         get_last_target_status (&last_ptid, &ws);
+         tp = find_thread_pid (last_ptid);
+       }
+      if (tp != NULL)
+       bs = tp->stop_bpstat;
 
       while ((stat = bpstat_num (&bs, &num)) != 0)
        if (stat > 0)
          {
            set_ignore_count (num,
-                             parse_and_eval_long (proc_count_exp) - 1,
+                             parse_and_eval_long (args) - 1,
                              from_tty);
            /* set_ignore_count prints a message ending with a period.
               So print two spaces before "Continuing.".  */
@@ -662,9 +696,7 @@ continue_command (char *proc_count_exp, int from_tty)
   if (from_tty)
     printf_filtered (_("Continuing.\n"));
 
-  clear_proceed_status ();
-
-  proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
+  continue_1 (all_threads);
 }
 \f
 /* Step until outside of current statement.  */
@@ -714,6 +746,7 @@ step_1 (int skip_subroutines, int single_inst, char *count_string)
   int thread = -1;
 
   ERROR_NO_INFERIOR;
+  ensure_not_running ();
 
   if (count_string)
     async_exec = strip_bg_char (&count_string);
@@ -748,21 +781,22 @@ step_1 (int skip_subroutines, int single_inst, char *count_string)
     {
       for (; count > 0; count--)
        {
+         struct thread_info *tp = inferior_thread ();
          clear_proceed_status ();
 
          frame = get_current_frame ();
-         if (!frame)           /* Avoid coredump here.  Why tho? */
-           error (_("No current frame"));
-         step_frame_id = get_frame_id (frame);
+         tp->step_frame_id = get_frame_id (frame);
 
          if (!single_inst)
            {
-             find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
-             if (step_range_end == 0)
+             find_pc_line_pc_range (stop_pc,
+                                    &tp->step_range_start, &tp->step_range_end);
+             if (tp->step_range_end == 0)
                {
                  char *name;
-                 if (find_pc_partial_function (stop_pc, &name, &step_range_start,
-                                               &step_range_end) == 0)
+                 if (find_pc_partial_function (stop_pc, &name,
+                                               &tp->step_range_start,
+                                               &tp->step_range_end) == 0)
                    error (_("Cannot find bounds of current function"));
 
                  target_terminal_ours ();
@@ -774,21 +808,22 @@ which has no line number information.\n"), name);
          else
            {
              /* Say we are stepping, but stop after one insn whatever it does.  */
-             step_range_start = step_range_end = 1;
+             tp->step_range_start = tp->step_range_end = 1;
              if (!skip_subroutines)
                /* It is stepi.
                   Don't step over function calls, not even to functions lacking
                   line numbers.  */
-               step_over_calls = STEP_OVER_NONE;
+               tp->step_over_calls = STEP_OVER_NONE;
            }
 
          if (skip_subroutines)
-           step_over_calls = STEP_OVER_ALL;
+           tp->step_over_calls = STEP_OVER_ALL;
 
-         step_multi = (count > 1);
+         tp->step_multi = (count > 1);
          proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
 
-         if (!stop_step)
+         if (!target_has_execution
+             || !inferior_thread ()->stop_step)
            break;
        }
 
@@ -808,35 +843,43 @@ which has no line number information.\n"), name);
     }
 }
 
+struct step_1_continuation_args
+{
+  int count;
+  int skip_subroutines;
+  int single_inst;
+  int thread;
+};
+
 /* Called after we are done with one step operation, to check whether
    we need to step again, before we print the prompt and return control
    to the user. If count is > 1, we will need to do one more call to
    proceed(), via step_once(). Basically it is like step_once and
    step_1_continuation are co-recursive. */
 static void
-step_1_continuation (struct continuation_arg *arg, int error_p)
+step_1_continuation (void *args)
 {
-  int count;
-  int skip_subroutines;
-  int single_inst;
-  int thread;
-      
-  skip_subroutines = arg->data.integer;
-  single_inst      = arg->next->data.integer;
-  count            = arg->next->next->data.integer;
-  thread           = arg->next->next->next->data.integer;
+  struct step_1_continuation_args *a = args;
 
-  if (error_p || !step_multi || !stop_step)
+  if (target_has_execution)
     {
-      /* We either hit an error, or stopped for some reason
-        that is not stepping, or there are no further steps
-        to make.  Cleanup.  */
-      if (!single_inst || skip_subroutines)
-       delete_longjmp_breakpoint (thread);
-      step_multi = 0;
+      struct thread_info *tp;
+
+      tp = inferior_thread ();
+      if (tp->step_multi && tp->stop_step)
+       {
+         /* There are more steps to make, and we did stop due to
+            ending a stepping range.  Do another step.  */
+         step_once (a->skip_subroutines, a->single_inst, a->count - 1, a->thread);
+         return;
+       }
+      tp->step_multi = 0;
     }
-  else
-    step_once (skip_subroutines, single_inst, count - 1, thread);
+
+  /* We either stopped for some reason that is not stepping, or there
+     are no further steps to make.  Cleanup.  */
+  if (!a->single_inst || a->skip_subroutines)
+    delete_longjmp_breakpoint (a->thread);
 }
 
 /* Do just one step operation. If count >1 we will have to set up a
@@ -848,36 +891,40 @@ step_1_continuation (struct continuation_arg *arg, int error_p)
    been completed.*/
 static void 
 step_once (int skip_subroutines, int single_inst, int count, int thread)
-{ 
-  struct continuation_arg *arg1; 
-  struct continuation_arg *arg2;
-  struct continuation_arg *arg3; 
-  struct continuation_arg *arg4;
+{
   struct frame_info *frame;
+  struct step_1_continuation_args *args;
 
   if (count > 0)
     {
+      /* 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 ();
       clear_proceed_status ();
 
       frame = get_current_frame ();
       if (!frame)              /* Avoid coredump here.  Why tho? */
        error (_("No current frame"));
-      step_frame_id = get_frame_id (frame);
+      tp->step_frame_id = get_frame_id (frame);
 
       if (!single_inst)
        {
-         find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
+         find_pc_line_pc_range (stop_pc,
+                                &tp->step_range_start, &tp->step_range_end);
 
          /* If we have no line info, switch to stepi mode.  */
-         if (step_range_end == 0 && step_stop_if_no_debug)
+         if (tp->step_range_end == 0 && step_stop_if_no_debug)
            {
-             step_range_start = step_range_end = 1;
+             tp->step_range_start = tp->step_range_end = 1;
            }
-         else if (step_range_end == 0)
+         else if (tp->step_range_end == 0)
            {
              char *name;
-             if (find_pc_partial_function (stop_pc, &name, &step_range_start,
-                                           &step_range_end) == 0)
+             if (find_pc_partial_function (stop_pc, &name,
+                                           &tp->step_range_start,
+                                           &tp->step_range_end) == 0)
                error (_("Cannot find bounds of current function"));
 
              target_terminal_ours ();
@@ -889,36 +936,26 @@ which has no line number information.\n"), name);
       else
        {
          /* Say we are stepping, but stop after one insn whatever it does.  */
-         step_range_start = step_range_end = 1;
+         tp->step_range_start = tp->step_range_end = 1;
          if (!skip_subroutines)
            /* It is stepi.
               Don't step over function calls, not even to functions lacking
               line numbers.  */
-           step_over_calls = STEP_OVER_NONE;
+           tp->step_over_calls = STEP_OVER_NONE;
        }
 
       if (skip_subroutines)
-       step_over_calls = STEP_OVER_ALL;
+       tp->step_over_calls = STEP_OVER_ALL;
 
-      step_multi = (count > 1);
+      inferior_thread ()->step_multi = (count > 1);
       proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
-      arg1 =
-       (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
-      arg2 =
-       (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
-      arg3 =
-       (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
-      arg4 =
-       (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
-      arg1->next = arg2;
-      arg1->data.integer = skip_subroutines;
-      arg2->next = arg3;
-      arg2->data.integer = single_inst;
-      arg3->next = arg4;
-      arg3->data.integer = count;
-      arg4->next = NULL;
-      arg4->data.integer = thread;
-      add_intermediate_continuation (step_1_continuation, arg1);
+
+      args = xmalloc (sizeof (*args));
+      args->skip_subroutines = skip_subroutines;
+      args->single_inst = single_inst;
+      args->count = count;
+      args->thread = thread;
+      add_intermediate_continuation (step_1_continuation, args, xfree);
     }
 }
 
@@ -936,6 +973,7 @@ jump_command (char *arg, int from_tty)
   int async_exec = 0;
 
   ERROR_NO_INFERIOR;
+  ensure_not_running ();
 
   /* Find out whether we must run in the background. */
   if (arg != NULL)
@@ -979,8 +1017,8 @@ jump_command (char *arg, int from_tty)
   if (sfn != NULL)
     {
       fixup_symbol_section (sfn, 0);
-      if (section_is_overlay (SYMBOL_BFD_SECTION (sfn)) &&
-         !section_is_mapped (SYMBOL_BFD_SECTION (sfn)))
+      if (section_is_overlay (SYMBOL_OBJ_SECTION (sfn)) &&
+         !section_is_mapped (SYMBOL_OBJ_SECTION (sfn)))
        {
          if (!query ("WARNING!!!  Destination is in unmapped overlay!  Jump anyway? "))
            {
@@ -1036,6 +1074,7 @@ signal_command (char *signum_exp, int from_tty)
 
   dont_repeat ();              /* Too dangerous.  */
   ERROR_NO_INFERIOR;
+  ensure_not_running ();
 
   /* Find out whether we must run in the background.  */
   if (signum_exp != NULL)
@@ -1105,6 +1144,7 @@ until_next_command (int from_tty)
   CORE_ADDR pc;
   struct symbol *func;
   struct symtab_and_line sal;
+  struct thread_info *tp = inferior_thread ();
 
   clear_proceed_status ();
 
@@ -1124,21 +1164,21 @@ until_next_command (int from_tty)
       if (msymbol == NULL)
        error (_("Execution is not within a known function."));
 
-      step_range_start = SYMBOL_VALUE_ADDRESS (msymbol);
-      step_range_end = pc;
+      tp->step_range_start = SYMBOL_VALUE_ADDRESS (msymbol);
+      tp->step_range_end = pc;
     }
   else
     {
       sal = find_pc_line (pc, 0);
 
-      step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
-      step_range_end = sal.end;
+      tp->step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
+      tp->step_range_end = sal.end;
     }
 
-  step_over_calls = STEP_OVER_ALL;
-  step_frame_id = get_frame_id (frame);
+  tp->step_over_calls = STEP_OVER_ALL;
+  tp->step_frame_id = get_frame_id (frame);
 
-  step_multi = 0;              /* Only one call to proceed */
+  tp->step_multi = 0;          /* Only one call to proceed */
 
   proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
 }
@@ -1274,39 +1314,56 @@ print_return_value (struct type *func_type, struct type *value_type)
    soon as it detects that the target has stopped. This function is
    called via the cmd_continuation pointer.  */
 
-static void
-finish_command_continuation (struct continuation_arg *arg, int error_p)
+struct finish_command_continuation_args
 {
-  struct symbol *function;
   struct breakpoint *breakpoint;
-  struct cleanup *cleanups;
+  struct symbol *function;
+};
+
+static void
+finish_command_continuation (void *arg)
+{
+  struct finish_command_continuation_args *a = arg;
+
+  bpstat bs = NULL;
 
-  breakpoint = (struct breakpoint *) arg->data.pointer;
-  function = (struct symbol *) arg->next->data.pointer;
+  if (!ptid_equal (inferior_ptid, null_ptid)
+      && target_has_execution
+      && is_stopped (inferior_ptid))
+    bs = inferior_thread ()->stop_bpstat;
 
-  if (!error_p)
+  if (bpstat_find_breakpoint (bs, a->breakpoint) != NULL
+      && a->function != NULL)
     {
-      if (bpstat_find_breakpoint (stop_bpstat, breakpoint) != NULL
-         && function != NULL)
-       {
-         struct type *value_type;
-         
-         value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
-         if (!value_type)
-           internal_error (__FILE__, __LINE__,
-                           _("finish_command: function has no target type"));
-         
-         if (TYPE_CODE (value_type) != TYPE_CODE_VOID)
-           print_return_value (SYMBOL_TYPE (function), value_type); 
-       }
+      struct type *value_type;
 
-      /* We suppress normal call of normal_stop observer and do it here so that
-        that *stopped notification includes the return value.  */
-      observer_notify_normal_stop (stop_bpstat);
+      value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (a->function));
+      if (!value_type)
+       internal_error (__FILE__, __LINE__,
+                       _("finish_command: function has no target type"));
+
+      if (TYPE_CODE (value_type) != TYPE_CODE_VOID)
+       print_return_value (SYMBOL_TYPE (a->function), value_type);
     }
 
+  /* We suppress normal call of normal_stop observer and do it here so
+     that that *stopped notification includes the return value.  */
+  /* NOTE: This is broken in non-stop mode.  There is no guarantee the
+     next stop will be in the same thread that we started doing a
+     finish on.  This suppressing (or some other replacement means)
+     should be a thread property.  */
+  observer_notify_normal_stop (bs);
+  suppress_stop_observer = 0;
+  delete_breakpoint (a->breakpoint);
+}
+
+static void
+finish_command_continuation_free_arg (void *arg)
+{
+  /* NOTE: See finish_command_continuation.  This would go away, if
+     this suppressing is made a thread property.  */
   suppress_stop_observer = 0;
-  delete_breakpoint (breakpoint);
+  xfree (arg);
 }
 
 /* "finish": Set a temporary breakpoint at the place the selected
@@ -1320,7 +1377,8 @@ finish_command (char *arg, int from_tty)
   struct symbol *function;
   struct breakpoint *breakpoint;
   struct cleanup *old_chain;
-  struct continuation_arg *arg1, *arg2, *arg3;
+  struct finish_command_continuation_args *cargs;
+  struct thread_info *tp;
 
   int async_exec = 0;
 
@@ -1350,6 +1408,8 @@ finish_command (char *arg, int from_tty)
   if (frame == 0)
     error (_("\"finish\" not meaningful in the outermost frame."));
 
+  tp = inferior_thread ();
+
   clear_proceed_status ();
 
   sal = find_pc_line (get_frame_pc (frame), 0);
@@ -1371,33 +1431,31 @@ finish_command (char *arg, int from_tty)
       print_stack_frame (get_selected_frame (NULL), 1, LOCATION);
     }
 
-  proceed_to_finish = 1;       /* We want stop_registers, please...  */
+  tp->proceed_to_finish = 1;   /* We want stop_registers, please...  */
   make_cleanup_restore_integer (&suppress_stop_observer);
   suppress_stop_observer = 1;
   proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
 
-  arg1 =
-    (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
-  arg2 =
-    (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
-  arg1->next = arg2;
-  arg2->next = NULL;
-  arg1->data.pointer = breakpoint;
-  arg2->data.pointer = function;
-  add_continuation (finish_command_continuation, arg1);
-  
+  cargs = xmalloc (sizeof (*cargs));
+
+  cargs->breakpoint = breakpoint;
+  cargs->function = function;
+  add_continuation (finish_command_continuation, cargs,
+                   finish_command_continuation_free_arg);
+
   discard_cleanups (old_chain);
   if (!target_can_async_p ())
-    do_all_continuations (0);
+    do_all_continuations ();
 }
 \f
 
 static void
 program_info (char *args, int from_tty)
 {
-  bpstat bs = stop_bpstat;
-  int num;
-  int stat = bpstat_num (&bs, &num);
+  bpstat bs;
+  int num, stat;
+  struct thread_info *tp;
+  ptid_t ptid;
 
   if (!target_has_execution)
     {
@@ -1405,10 +1463,27 @@ program_info (char *args, int from_tty)
       return;
     }
 
+  if (non_stop)
+    ptid = inferior_ptid;
+  else
+    {
+      struct target_waitstatus ws;
+      get_last_target_status (&ptid, &ws);
+    }
+
+  if (ptid_equal (ptid, null_ptid) || is_exited (ptid))
+    error (_("Invalid selected thread."));
+  else if (is_running (ptid))
+    error (_("Selected thread is running."));
+
+  tp = find_thread_pid (ptid);
+  bs = tp->stop_bpstat;
+  stat = bpstat_num (&bs, &num);
+
   target_files_info ();
   printf_filtered (_("Program stopped at %s.\n"),
                   hex_string ((unsigned long) stop_pc));
-  if (stop_step)
+  if (tp->stop_step)
     printf_filtered (_("It stopped after being stepped.\n"));
   else if (stat != 0)
     {
@@ -1426,11 +1501,11 @@ It stopped at a breakpoint that has since been deleted.\n"));
          stat = bpstat_num (&bs, &num);
        }
     }
-  else if (stop_signal != TARGET_SIGNAL_0)
+  else if (tp->stop_signal != TARGET_SIGNAL_0)
     {
       printf_filtered (_("It stopped with signal %s, %s.\n"),
-                      target_signal_to_name (stop_signal),
-                      target_signal_to_string (stop_signal));
+                      target_signal_to_name (tp->stop_signal),
+                      target_signal_to_string (tp->stop_signal));
     }
 
   if (!from_tty)
@@ -1736,7 +1811,7 @@ registers_info (char *addr_exp, int fpregs)
 
       /* A register name?  */
       {
-       int regnum = frame_map_name_to_regnum (frame, start, end - start);
+       int regnum = user_reg_map_name_to_regnum (gdbarch, start, end - start);
        if (regnum >= 0)
          {
            /* User registers lie completely outside of the range of
@@ -1933,18 +2008,26 @@ attach_command_post_wait (char *args, int from_tty, int async_exec)
     }
 }
 
-static void
-attach_command_continuation (struct continuation_arg *arg, int error_p)
+struct attach_command_continuation_args
 {
   char *args;
   int from_tty;
   int async_exec;
+};
 
-  args = (char *) arg->data.pointer;
-  from_tty = arg->next->data.integer;
-  async_exec = arg->next->next->data.integer;
+static void
+attach_command_continuation (void *args)
+{
+  struct attach_command_continuation_args *a = args;
+  attach_command_post_wait (a->args, a->from_tty, a->async_exec);
+}
 
-  attach_command_post_wait (args, from_tty, async_exec);
+static void
+attach_command_continuation_free_args (void *args)
+{
+  struct attach_command_continuation_args *a = args;
+  xfree (a->args);
+  xfree (a);
 }
 
 void
@@ -1968,23 +2051,8 @@ attach_command (char *args, int from_tty)
      this function should probably be moved into target_pre_inferior.  */
   target_pre_inferior (from_tty);
 
-  /* Clear out solib state. Otherwise the solib state of the previous
-     inferior might have survived and is entirely wrong for the new
-     target.  This has been observed on GNU/Linux using glibc 2.3. How
-     to reproduce:
-
-     bash$ ./foo&
-     [1] 4711
-     bash$ ./foo&
-     [1] 4712
-     bash$ gdb ./foo
-     [...]
-     (gdb) attach 4711
-     (gdb) detach
-     (gdb) attach 4712
-     Cannot access memory at address 0xdeadbeef
-  */
-  clear_solib ();
+  if (non_stop && !target_supports_non_stop ())
+    error (_("Cannot attach to this target in non-stop mode"));
 
   if (args)
     {
@@ -2029,21 +2097,14 @@ attach_command (char *args, int from_tty)
       if (target_can_async_p ())
        {
          /* sync_execution mode.  Wait for stop.  */
-         struct continuation_arg *arg1, *arg2, *arg3;
-
-         arg1 =
-           (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
-         arg2 =
-           (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
-         arg3 =
-           (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
-         arg1->next = arg2;
-         arg2->next = arg3;
-         arg3->next = NULL;
-         arg1->data.pointer = args;
-         arg2->data.integer = from_tty;
-         arg3->data.integer = async_exec;
-         add_continuation (attach_command_continuation, arg1);
+         struct attach_command_continuation_args *a;
+
+         a = xmalloc (sizeof (*a));
+         a->args = xstrdup (args);
+         a->from_tty = from_tty;
+         a->async_exec = async_exec;
+         add_continuation (attach_command_continuation, a,
+                           attach_command_continuation_free_args);
          return;
        }
 
@@ -2094,15 +2155,40 @@ disconnect_command (char *args, int from_tty)
     deprecated_detach_hook ();
 }
 
+void 
+interrupt_target_1 (int all_threads)
+{
+  ptid_t ptid;
+  if (all_threads)
+    ptid = minus_one_ptid;
+  else
+    ptid = inferior_ptid;
+  target_stop (ptid);
+}
+
 /* Stop the execution of the target while running in async mode, in
-   the backgound. */
+   the backgound.  In all-stop, stop the whole process.  In non-stop
+   mode, stop the current thread only by default, or stop all threads
+   if the `-a' switch is used.  */
+
+/* interrupt [-a]  */
 void
 interrupt_target_command (char *args, int from_tty)
 {
   if (target_can_async_p ())
     {
+      int all_threads = 0;
+
       dont_repeat ();          /* Not for the faint of heart */
-      target_stop ();
+
+      if (args != NULL
+         && strncmp (args, "-a", sizeof ("-a") - 1) == 0)
+       all_threads = 1;
+
+      if (!non_stop && all_threads)
+       error (_("-a is meaningless in all-stop mode."));
+
+      interrupt_target_1 (all_threads);
     }
 }
 
@@ -2305,11 +2391,16 @@ This command is a combination of tbreak and jump."));
   if (xdb_commands)
     add_com_alias ("g", "go", class_run, 1);
 
-  add_com ("continue", class_run, continue_command, _("\
+  c = add_com ("continue", class_run, continue_command, _("\
 Continue program being debugged, after signal or breakpoint.\n\
 If proceeding from breakpoint, a number N may be used as an argument,\n\
 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
-the breakpoint won't break until the Nth time it is reached)."));
+the breakpoint won't break until the Nth time it is reached).\n\
+\n\
+If non-stop mode is enabled, continue only the current thread,\n\
+otherwise all the threads in the program are continued.  To \n\
+continue all stopped threads in non-stop mode, use the -a option.\n\
+Specifying -a and an ignore count simultaneously is an error."));
   add_com_alias ("c", "cont", class_run, 1);
   add_com_alias ("fg", "cont", class_run, 1);
 
@@ -2333,8 +2424,10 @@ You may specify arguments to give to your program, just as with the\n\
   set_cmd_completer (c, filename_completer);
 
   c = add_com ("interrupt", class_run, interrupt_target_command,
-              _("Interrupt the execution of the debugged program."));
-  set_cmd_async_ok (c);
+              _("Interrupt the execution of the debugged program.\n\
+If non-stop mode is enabled, interrupt only the current thread,\n\
+otherwise all the threads in the program are stopped.  To \n\
+interrupt all running threads in non-stop mode, use the -a option."));
 
   add_info ("registers", nofp_registers_info, _("\
 List of integer registers and their contents, for selected stack frame.\n\
This page took 0.103431 seconds and 4 git commands to generate.