Do not reopen temporary files
[deliverable/binutils-gdb.git] / gdb / infrun.c
index 4828720f9232d460323df3522b27b50cb21188bf..9473d1f20f62fd35e77dce071c8fd82f9488aa87 100644 (file)
@@ -1189,12 +1189,14 @@ follow_exec (ptid_t ptid, char *exec_file_target)
       /* The user wants to keep the old inferior and program spaces
         around.  Create a new fresh one, and switch to it.  */
 
-      /* Do exit processing for the original inferior before adding
-        the new inferior so we don't have two active inferiors with
-        the same ptid, which can confuse find_inferior_ptid.  */
+      /* Do exit processing for the original inferior before setting the new
+        inferior's pid.  Having two inferiors with the same pid would confuse
+        find_inferior_p(t)id.  Transfer the terminal state and info from the
+         old to the new inferior.  */
+      inf = add_inferior_with_spaces ();
+      swap_terminal_info (inf, current_inferior ());
       exit_inferior_silent (current_inferior ());
 
-      inf = add_inferior_with_spaces ();
       inf->pid = pid;
       target_follow_exec (inf, exec_file_target);
 
@@ -4747,7 +4749,7 @@ handle_no_resumed (struct execution_control_state *ecs)
       if (inf->pid == 0)
        continue;
 
-      thread_info *thread = any_live_thread_of_inferior (inf);
+      thread = any_live_thread_of_inferior (inf);
       if (thread == NULL)
        {
          if (debug_infrun)
@@ -5662,13 +5664,13 @@ handle_signal_stop (struct execution_control_state *ecs)
   if (debug_infrun)
     {
       struct regcache *regcache = get_thread_regcache (ecs->event_thread);
-      struct gdbarch *gdbarch = regcache->arch ();
+      struct gdbarch *reg_gdbarch = regcache->arch ();
       scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
 
       inferior_ptid = ecs->ptid;
 
       fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = %s\n",
-                         paddress (gdbarch,
+                         paddress (reg_gdbarch,
                                    ecs->event_thread->suspend.stop_pc));
       if (target_stopped_by_watchpoint ())
        {
@@ -5679,7 +5681,7 @@ handle_signal_stop (struct execution_control_state *ecs)
          if (target_stopped_data_address (current_top_target (), &addr))
             fprintf_unfiltered (gdb_stdlog,
                                 "infrun: stopped data address = %s\n",
-                                paddress (gdbarch, addr));
+                                paddress (reg_gdbarch, addr));
           else
             fprintf_unfiltered (gdb_stdlog,
                                 "infrun: (no data address available)\n");
@@ -8095,6 +8097,13 @@ maybe_remove_breakpoints (void)
 
 struct stop_context
 {
+  stop_context ();
+  ~stop_context ();
+
+  DISABLE_COPY_AND_ASSIGN (stop_context);
+
+  bool changed () const;
+
   /* The stop ID.  */
   ULONGEST stop_id;
 
@@ -8110,59 +8119,50 @@ struct stop_context
   int inf_num;
 };
 
-/* Returns a new stop context.  If stopped for a thread event, this
+/* Initializes a new stop context.  If stopped for a thread event, this
    takes a strong reference to the thread.  */
 
-static struct stop_context *
-save_stop_context (void)
+stop_context::stop_context ()
 {
-  struct stop_context *sc = XNEW (struct stop_context);
-
-  sc->stop_id = get_stop_id ();
-  sc->ptid = inferior_ptid;
-  sc->inf_num = current_inferior ()->num;
+  stop_id = get_stop_id ();
+  ptid = inferior_ptid;
+  inf_num = current_inferior ()->num;
 
   if (inferior_ptid != null_ptid)
     {
       /* Take a strong reference so that the thread can't be deleted
         yet.  */
-      sc->thread = inferior_thread ();
-      sc->thread->incref ();
+      thread = inferior_thread ();
+      thread->incref ();
     }
   else
-    sc->thread = NULL;
-
-  return sc;
+    thread = NULL;
 }
 
 /* Release a stop context previously created with save_stop_context.
    Releases the strong reference to the thread as well. */
 
-static void
-release_stop_context_cleanup (void *arg)
+stop_context::~stop_context ()
 {
-  struct stop_context *sc = (struct stop_context *) arg;
-
-  if (sc->thread != NULL)
-    sc->thread->decref ();
-  xfree (sc);
+  if (thread != NULL)
+    thread->decref ();
 }
 
 /* Return true if the current context no longer matches the saved stop
    context.  */
 
-static int
-stop_context_changed (struct stop_context *prev)
-{
-  if (prev->ptid != inferior_ptid)
-    return 1;
-  if (prev->inf_num != current_inferior ()->num)
-    return 1;
-  if (prev->thread != NULL && prev->thread->state != THREAD_STOPPED)
-    return 1;
-  if (get_stop_id () != prev->stop_id)
-    return 1;
-  return 0;
+bool
+stop_context::changed () const
+{
+  if (ptid != inferior_ptid)
+    return true;
+  if (inf_num != current_inferior ()->num)
+    return true;
+  if (thread != NULL && thread->state != THREAD_STOPPED)
+    return true;
+  if (get_stop_id () != stop_id)
+    return true;
+  return false;
 }
 
 /* See infrun.h.  */
@@ -8305,9 +8305,7 @@ normal_stop (void)
      of stop_command's pre-hook not existing).  */
   if (stop_command != NULL)
     {
-      struct stop_context *saved_context = save_stop_context ();
-      struct cleanup *old_chain
-       = make_cleanup (release_stop_context_cleanup, saved_context);
+      stop_context saved_context;
 
       TRY
        {
@@ -8325,12 +8323,8 @@ normal_stop (void)
         gone.  Likewise if the command switches thread or inferior --
         the observers would print a stop for the wrong
         thread/inferior.  */
-      if (stop_context_changed (saved_context))
-       {
-         do_cleanups (old_chain);
-         return 1;
-       }
-      do_cleanups (old_chain);
+      if (saved_context.changed ())
+       return 1;
     }
 
   /* Notify observers about the stop.  This is where the interpreters
@@ -8469,7 +8463,7 @@ static void
 handle_command (const char *args, int from_tty)
 {
   int digits, wordlen;
-  int sigfirst, signum, siglast;
+  int sigfirst, siglast;
   enum gdb_signal oursig;
   int allsigs;
   int nsigs;
@@ -8564,9 +8558,7 @@ handle_command (const char *args, int from_tty)
          if (sigfirst > siglast)
            {
              /* Bet he didn't figure we'd think of this case...  */
-             signum = sigfirst;
-             sigfirst = siglast;
-             siglast = signum;
+             std::swap (sigfirst, siglast);
            }
        }
       else
@@ -8586,7 +8578,7 @@ handle_command (const char *args, int from_tty)
       /* If any signal numbers or symbol names were found, set flags for
          which signals to apply actions to.  */
 
-      for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
+      for (int signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
        {
          switch ((enum gdb_signal) signum)
            {
@@ -8619,7 +8611,7 @@ Are you sure you want to change it? "),
        }
     }
 
-  for (signum = 0; signum < nsigs; signum++)
+  for (int signum = 0; signum < nsigs; signum++)
     if (sigs[signum])
       {
        signal_cache_update (-1);
@@ -8821,10 +8813,9 @@ struct infcall_suspend_state
   gdb::unique_xmalloc_ptr<gdb_byte> siginfo_data;
 };
 
-struct infcall_suspend_state *
-save_infcall_suspend_state (void)
+infcall_suspend_state_up
+save_infcall_suspend_state ()
 {
-  struct infcall_suspend_state *inf_state;
   struct thread_info *tp = inferior_thread ();
   struct regcache *regcache = get_current_regcache ();
   struct gdbarch *gdbarch = regcache->arch ();
@@ -8845,7 +8836,7 @@ save_infcall_suspend_state (void)
        }
     }
 
-  inf_state = new struct infcall_suspend_state;
+  infcall_suspend_state_up inf_state (new struct infcall_suspend_state);
 
   if (siginfo_data)
     {
@@ -8925,10 +8916,10 @@ struct infcall_control_state
 /* Save all of the information associated with the inferior<==>gdb
    connection.  */
 
-struct infcall_control_state *
-save_infcall_control_state (void)
+infcall_control_state_up
+save_infcall_control_state ()
 {
-  struct infcall_control_state *inf_status = new struct infcall_control_state;
+  infcall_control_state_up inf_status (new struct infcall_control_state);
   struct thread_info *tp = inferior_thread ();
   struct inferior *inf = current_inferior ();
 
This page took 0.027472 seconds and 4 git commands to generate.