[23/28] Don't write to inferior_ptid in remote-sim.c

Message ID 20200414175434.8047-24-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.
gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* remote-sim.c (gdbsim_target::create_inferior): Switch to thread
	after creating it, instead of writing to inferior_ptid.
	(gdbsim_target::wait): Don't write to inferior_ptid.
---
 gdb/remote-sim.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

-- 
2.14.5

Comments

Simon Marchi April 16, 2020, 12:53 a.m. | #1
On 2020-04-14 1:54 p.m., Pedro Alves via Gdb-patches wrote:
> gdb/ChangeLog:

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

> 

> 	* remote-sim.c (gdbsim_target::create_inferior): Switch to thread

> 	after creating it, instead of writing to inferior_ptid.

> 	(gdbsim_target::wait): Don't write to inferior_ptid.


I noticed there's 2 "remote-sim.c" patches in this series.  If there's no reason for them
to be separate, I think they should be merged.  Otherwise, they should be given different
subjects.

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

>> gdb/ChangeLog:

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

>>

>> 	* remote-sim.c (gdbsim_target::create_inferior): Switch to thread

>> 	after creating it, instead of writing to inferior_ptid.

>> 	(gdbsim_target::wait): Don't write to inferior_ptid.

> 

> I noticed there's 2 "remote-sim.c" patches in this series.  If there's no reason for them

> to be separate, I think they should be merged.  Otherwise, they should be given different

> subjects.

> 


Whoops, thanks for noticing.  There's no reason for them to be separate.
Just wrote them in different passes and didn't notice it.

Here's what they look like merged as one.

From 36fd318f59ba41310d0820953a37743fc989c927 Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>

Date: Thu, 16 Apr 2020 15:54:13 +0100
Subject: [PATCH] Don't write to inferior_ptid in remote-sim.c

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

	* remote-sim.c (gdbsim_target::create_inferior): Switch to thread
	after creating it, instead of writing to inferior_ptid.
	(gdbsim_target_open): Use switch_to_no_thread instead of writing
	to inferior_ptid directly.
	(gdbsim_target::wait): Don't write to inferior_ptid.
---
 gdb/remote-sim.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
index 347dfd7013..9af6486bca 100644
--- a/gdb/remote-sim.c
+++ b/gdb/remote-sim.c
@@ -653,9 +653,10 @@ gdbsim_target::create_inferior (const char *exec_file,
       != SIM_RC_OK)
     error (_("Unable to create sim inferior."));
 
-  inferior_ptid = sim_data->remote_sim_ptid;
-  inferior_appeared (current_inferior (), inferior_ptid.pid ());
-  add_thread_silent (this, inferior_ptid);
+  inferior_appeared (current_inferior (),
+		     sim_data->remote_sim_ptid.pid ());
+  thread_info *thr = add_thread_silent (this, sim_data->remote_sim_ptid);
+  switch_to_thread (thr);
 
   insert_breakpoints ();	/* Needed to get correct instruction
 				   in cache.  */
@@ -761,7 +762,7 @@ gdbsim_target_open (const char *args, int from_tty)
 
   /* There's nothing running after "target sim" or "load"; not until
      "run".  */
-  inferior_ptid = null_ptid;
+  switch_to_no_thread ();
 
   gdbsim_is_open = 1;
 }
@@ -945,7 +946,6 @@ gdbsim_target::wait (ptid_t ptid, struct target_waitstatus *status, int options)
       if (sim_data == NULL)
 	error (_("Unable to wait for pid %d.  Inferior not found."),
 	       ptid.pid ());
-      inferior_ptid = ptid;
     }
 
   if (remote_debug)

-- 
2.14.5

Patch

diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
index da1ee96519..9af6486bca 100644
--- a/gdb/remote-sim.c
+++ b/gdb/remote-sim.c
@@ -653,9 +653,10 @@  gdbsim_target::create_inferior (const char *exec_file,
       != SIM_RC_OK)
     error (_("Unable to create sim inferior."));
 
-  inferior_ptid = sim_data->remote_sim_ptid;
-  inferior_appeared (current_inferior (), inferior_ptid.pid ());
-  add_thread_silent (this, inferior_ptid);
+  inferior_appeared (current_inferior (),
+		     sim_data->remote_sim_ptid.pid ());
+  thread_info *thr = add_thread_silent (this, sim_data->remote_sim_ptid);
+  switch_to_thread (thr);
 
   insert_breakpoints ();	/* Needed to get correct instruction
 				   in cache.  */
@@ -945,7 +946,6 @@  gdbsim_target::wait (ptid_t ptid, struct target_waitstatus *status, int options)
       if (sim_data == NULL)
 	error (_("Unable to wait for pid %d.  Inferior not found."),
 	       ptid.pid ());
-      inferior_ptid = ptid;
     }
 
   if (remote_debug)