Don't write to inferior_ptid in gnu-nat.c
authorPedro Alves <palves@redhat.com>
Thu, 18 Jun 2020 20:28:28 +0000 (21:28 +0100)
committerPedro Alves <palves@redhat.com>
Thu, 18 Jun 2020 22:11:23 +0000 (23:11 +0100)
Untested.

gdb/ChangeLog:
2020-06-18  Pedro Alves  <palves@redhat.com>

* gnu-nat.c (gnu_nat_target::create_inferior): Switch to the added
thread.
(gnu_nat_target::attach): Don't write to inferior_ptid directly.
Instead use switch_to_thread.
(gnu_nat_target::detach): Use switch_to_no_thread
instead of writing to inferior_ptid directly.  Used passed-in
inferior instead of looking up the inferior by pid.

gdb/ChangeLog
gdb/gnu-nat.c

index eff2fa2093e85ddfdcf3d16a901e45ab8b02cfd5..88db3be38c8947d1f4bfdaef432a1ed0ac4549f5 100644 (file)
@@ -1,3 +1,13 @@
+2020-06-18  Pedro Alves  <palves@redhat.com>
+
+       * gnu-nat.c (gnu_nat_target::create_inferior): Switch to the added
+       thread.
+       (gnu_nat_target::attach): Don't write to inferior_ptid directly.
+       Instead use switch_to_thread.
+       (gnu_nat_target::detach): Use switch_to_no_thread
+       instead of writing to inferior_ptid directly.  Used passed-in
+       inferior instead of looking up the inferior by pid.
+
 2020-06-18  Pedro Alves  <palves@redhat.com>
 
        * go32-nat.c (go32_nat_target::create_inferior): Don't write to
index 44adda5fe1244c343879360f2e62dabb39441d86..3cee06dc4db7c812e0de646fbe462229070fd3fc 100644 (file)
@@ -2121,7 +2121,8 @@ gnu_nat_target::create_inferior (const char *exec_file,
   /* We have something that executes now.  We'll be running through
      the shell at this point (if startup-with-shell is true), but the
      pid shouldn't change.  */
-  add_thread_silent (this, ptid_t (pid));
+  thread_info *thr = add_thread_silent (this, ptid_t (pid));
+  switch_to_thread (thr);
 
   /* Attach to the now stopped child, which is actually a shell...  */
   inf_debug (inf, "attaching to child: %d", pid);
@@ -2196,7 +2197,9 @@ gnu_nat_target::attach (const char *args, int from_tty)
 
   inf_update_procs (inf);
 
-  inferior_ptid = ptid_t (pid, inf_pick_first_thread (), 0);
+  thread_info *thr
+    = find_thread_ptid (this, ptid_t (pid, inf_pick_first_thread ()));
+  switch_to_thread (thr);
 
   /* We have to initialize the terminal settings now, since the code
      below might try to restore them.  */
@@ -2225,8 +2228,6 @@ gnu_nat_target::attach (const char *args, int from_tty)
 void
 gnu_nat_target::detach (inferior *inf, int from_tty)
 {
-  int pid;
-
   if (from_tty)
     {
       const char *exec_file = get_exec_file (0);
@@ -2238,12 +2239,10 @@ gnu_nat_target::detach (inferior *inf, int from_tty)
        printf_unfiltered ("Detaching from pid %d\n", gnu_current_inf->pid);
     }
 
-  pid = gnu_current_inf->pid;
-
   inf_detach (gnu_current_inf);
 
-  inferior_ptid = null_ptid;
-  detach_inferior (find_inferior_pid (this, pid));
+  switch_to_no_thread ();
+  detach_inferior (inf);
 
   maybe_unpush_target ();
 }