[16/28] Don't write to inferior_ptid in darwin-nat.c

Message ID 20200414175434.8047-17-palves@redhat.com
State New
Headers show
Series
  • Decouple inferior_ptid/inferior_thread(); dup ptids in thread list (PR/25412)
Related show

Commit Message

Rogerio Alves via Gdb-patches April 14, 2020, 5:54 p.m.
Untested.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* darwin-nat.c (darwin_nat_target::decode_message): Don't write to
	inferior_ptid.
	(darwin_nat_target::stop_inferior, darwin_nat_target::kill): Avoid
	inferior_ptid.
	(darwin_attach_pid): Use switch_to_no_thread instead of writing to
	inferior_ptid directly.
	(darwin_nat_target::init_thread_list): Switch to thread, instead
	of writing to inferior_ptid.
	(darwin_nat_target::attach): Don't write to inferior_ptid.
	(darwin_nat_target::get_ada_task_ptid): Avoid inferior_ptid.
---
 gdb/darwin-nat.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

-- 
2.14.5

Comments

Simon Marchi April 16, 2020, 1:33 a.m. | #1
On 2020-04-14 1:54 p.m., Pedro Alves via Gdb-patches wrote:
> Untested.

> 

> gdb/ChangeLog:

> yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

> 

> 	* darwin-nat.c (darwin_nat_target::decode_message): Don't write to

> 	inferior_ptid.

> 	(darwin_nat_target::stop_inferior, darwin_nat_target::kill): Avoid

> 	inferior_ptid.

> 	(darwin_attach_pid): Use switch_to_no_thread instead of writing to

> 	inferior_ptid directly.

> 	(darwin_nat_target::init_thread_list): Switch to thread, instead

> 	of writing to inferior_ptid.

> 	(darwin_nat_target::attach): Don't write to inferior_ptid.

> 	(darwin_nat_target::get_ada_task_ptid): Avoid inferior_ptid.

> ---

>  gdb/darwin-nat.c | 16 +++++++---------

>  1 file changed, 7 insertions(+), 9 deletions(-)


I tried to build it, here's a small patch to fix some typos.  It would be good to
check the other patches that you were not able to build for that pid_t/ptid_t typo.


diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c
index aacd40ba6f..367db9c1fe 100644
--- a/gdb/darwin-nat.c
+++ b/gdb/darwin-nat.c
@@ -1431,7 +1431,7 @@ darwin_nat_target::stop_inferior (inferior *inf)
   /* Wait until the process is really stopped.  */
   while (1)
     {
-      ptid = wait_1 (pid_t (inf->pid), &wstatus);
+      ptid = wait_1 (ptid_t (inf->pid), &wstatus);
       if (wstatus.kind == TARGET_WAITKIND_STOPPED
 	  && wstatus.value.sig == GDB_SIGNAL_STOP)
 	break;
@@ -1556,13 +1556,13 @@ darwin_nat_target::kill ()

       darwin_resume_inferior (inf);

-      ptid = wait_1 (pid_t (inf->pid), &wstatus);
+      ptid = wait_1 (ptid_t (inf->pid), &wstatus);
     }
   else if (errno != ESRCH)
     warning (_("Failed to kill inferior: kill (%d, 9) returned [%s]"),
 	     inf->pid, safe_strerror (errno));

-  target_mourn_inferior (pid_t (inf->pid));
+  target_mourn_inferior (ptid_t (inf->pid));
 }

 static void
Rogerio Alves via Gdb-patches April 16, 2020, 7:23 p.m. | #2
On 4/16/20 2:33 AM, Simon Marchi wrote:
> On 2020-04-14 1:54 p.m., Pedro Alves via Gdb-patches wrote:

>> Untested.

>>

>> gdb/ChangeLog:

>> yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

>>

>> 	* darwin-nat.c (darwin_nat_target::decode_message): Don't write to

>> 	inferior_ptid.

>> 	(darwin_nat_target::stop_inferior, darwin_nat_target::kill): Avoid

>> 	inferior_ptid.

>> 	(darwin_attach_pid): Use switch_to_no_thread instead of writing to

>> 	inferior_ptid directly.

>> 	(darwin_nat_target::init_thread_list): Switch to thread, instead

>> 	of writing to inferior_ptid.

>> 	(darwin_nat_target::attach): Don't write to inferior_ptid.

>> 	(darwin_nat_target::get_ada_task_ptid): Avoid inferior_ptid.

>> ---

>>  gdb/darwin-nat.c | 16 +++++++---------

>>  1 file changed, 7 insertions(+), 9 deletions(-)

> 

> I tried to build it, here's a small patch to fix some typos.  It would be good to

> check the other patches that you were not able to build for that pid_t/ptid_t typo.


Thanks, I merged that fix locally.

I diffed the whole series and didn't find any other case.

Pedro Alves

Patch

diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c
index 3bd8d8ce00..aacd40ba6f 100644
--- a/gdb/darwin-nat.c
+++ b/gdb/darwin-nat.c
@@ -1141,8 +1141,7 @@  darwin_nat_target::decode_message (mach_msg_header_t *hdr,
 	      /* Looks necessary on Leopard and harmless...  */
 	      wait4 (inf->pid, &wstatus, 0, NULL);
 
-	      inferior_ptid = ptid_t (inf->pid, 0, 0);
-	      return inferior_ptid;
+	      return ptid_t (inf->pid);
 	    }
 	  else
 	    {
@@ -1432,7 +1431,7 @@  darwin_nat_target::stop_inferior (inferior *inf)
   /* Wait until the process is really stopped.  */
   while (1)
     {
-      ptid = wait_1 (inferior_ptid, &wstatus);
+      ptid = wait_1 (pid_t (inf->pid), &wstatus);
       if (wstatus.kind == TARGET_WAITKIND_STOPPED
 	  && wstatus.value.sig == GDB_SIGNAL_STOP)
 	break;
@@ -1557,13 +1556,13 @@  darwin_nat_target::kill ()
 
       darwin_resume_inferior (inf);
 
-      ptid = wait_1 (inferior_ptid, &wstatus);
+      ptid = wait_1 (pid_t (inf->pid), &wstatus);
     }
   else if (errno != ESRCH)
     warning (_("Failed to kill inferior: kill (%d, 9) returned [%s]"),
 	     inf->pid, safe_strerror (errno));
 
-  target_mourn_inferior (inferior_ptid);
+  target_mourn_inferior (pid_t (inf->pid));
 }
 
 static void
@@ -1683,7 +1682,7 @@  darwin_attach_pid (struct inferior *inf)
   catch (const gdb_exception &ex)
     {
       exit_inferior (inf);
-      inferior_ptid = null_ptid;
+      switch_to_no_thread ();
 
       throw;
     }
@@ -1722,7 +1721,7 @@  darwin_nat_target::init_thread_list (inferior *inf)
   struct thread_info *first_thread
     = thread_info_from_private_thread_info (first_pti);
 
-  inferior_ptid = first_thread->ptid;
+  switch_to_thread (first_thread);
 }
 
 /* The child must synchronize with gdb: gdb must set the exception port
@@ -2057,7 +2056,6 @@  darwin_nat_target::attach (const char *args, int from_tty)
     error (_("Can't attach to process %d: %s (%d)"),
            pid, safe_strerror (errno), errno);
 
-  inferior_ptid = ptid_t (pid);
   inf = current_inferior ();
   inferior_appeared (inf, pid);
   inf->attach_flag = 1;
@@ -2469,7 +2467,7 @@  darwin_nat_target::get_ada_task_ptid (long lwp, long thread)
                  names_count * sizeof (mach_port_t));
 
   if (res)
-    return ptid_t (inferior_ptid.pid (), 0, res);
+    return ptid_t (current_inferior ()->pid, 0, res);
   else
     return null_ptid;
 }