sim: don't rely on inferior_ptid in gdbsim_target::wait

Message ID 20200119035557.5975-1-simon.marchi@polymtl.ca
State New
Headers show
Series
  • sim: don't rely on inferior_ptid in gdbsim_target::wait
Related show

Commit Message

Simon Marchi Jan. 19, 2020, 3:55 a.m.
When running a program with the simulator target, I get:

    /home/simark/src/binutils-gdb/gdb/inferior.c:279: internal-error: inferior* find_inferior_pid(process_stratum_target*, int): Assertion `pid != 0' failed.

This can be reproduced by building a GDB for --target=arm-none-gnueabi,
and running with

    $ ./gdb -nx --data-directory=data-directory a.out -ex "target sim" -ex load -ex "b main" -ex r

Where a.out is any program with a main.

The problem is that gdbsim_target::wait assumes that inferior_ptid has
the value of the thread it wants to report an event for.

Actually, it's the target's responsibility to come up with the ptid of
the thread the event is for.  In the sim target, that ptid is stored in
sim_inferior_data::remote_sim_ptid, so return that instead of
inferior_ptid.

ChangeLog:

	* remote-sim.c (gdbsim_target::wait): Return
	sim_data->remote_sim_ptid instead of inferior_ptid.
---
 gdb/remote-sim.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.24.1

Comments

Andrew Burgess Jan. 19, 2020, 9:12 p.m. | #1
* Simon Marchi <simon.marchi@polymtl.ca> [2020-01-18 22:55:57 -0500]:

> When running a program with the simulator target, I get:

> 

>     /home/simark/src/binutils-gdb/gdb/inferior.c:279: internal-error: inferior* find_inferior_pid(process_stratum_target*, int): Assertion `pid != 0' failed.

> 

> This can be reproduced by building a GDB for --target=arm-none-gnueabi,

> and running with

> 

>     $ ./gdb -nx --data-directory=data-directory a.out -ex "target sim" -ex load -ex "b main" -ex r

> 

> Where a.out is any program with a main.

> 

> The problem is that gdbsim_target::wait assumes that inferior_ptid has

> the value of the thread it wants to report an event for.

> 

> Actually, it's the target's responsibility to come up with the ptid of

> the thread the event is for.  In the sim target, that ptid is stored in

> sim_inferior_data::remote_sim_ptid, so return that instead of

> inferior_ptid.

> 

> ChangeLog:

> 

> 	* remote-sim.c (gdbsim_target::wait): Return

> 	sim_data->remote_sim_ptid instead of inferior_ptid.


This makes sense.  LGTM.

Thanks,
Andrew


> ---

>  gdb/remote-sim.c | 2 +-

>  1 file changed, 1 insertion(+), 1 deletion(-)

> 

> diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c

> index fb05786d4e28..d43648bd5171 100644

> --- a/gdb/remote-sim.c

> +++ b/gdb/remote-sim.c

> @@ -1016,7 +1016,7 @@ gdbsim_target::wait (ptid_t ptid, struct target_waitstatus *status, int options)

>        break;

>      }

>  

> -  return inferior_ptid;

> +  return sim_data->remote_sim_ptid;

>  }

>  

>  /* Get ready to modify the registers array.  On machines which store

> -- 

> 2.24.1

>
Simon Marchi Jan. 20, 2020, 12:48 a.m. | #2
On 2020-01-19 4:12 p.m., Andrew Burgess wrote:
> * Simon Marchi <simon.marchi@polymtl.ca> [2020-01-18 22:55:57 -0500]:

> 

>> When running a program with the simulator target, I get:

>>

>>     /home/simark/src/binutils-gdb/gdb/inferior.c:279: internal-error: inferior* find_inferior_pid(process_stratum_target*, int): Assertion `pid != 0' failed.

>>

>> This can be reproduced by building a GDB for --target=arm-none-gnueabi,

>> and running with

>>

>>     $ ./gdb -nx --data-directory=data-directory a.out -ex "target sim" -ex load -ex "b main" -ex r

>>

>> Where a.out is any program with a main.

>>

>> The problem is that gdbsim_target::wait assumes that inferior_ptid has

>> the value of the thread it wants to report an event for.

>>

>> Actually, it's the target's responsibility to come up with the ptid of

>> the thread the event is for.  In the sim target, that ptid is stored in

>> sim_inferior_data::remote_sim_ptid, so return that instead of

>> inferior_ptid.

>>

>> ChangeLog:

>>

>> 	* remote-sim.c (gdbsim_target::wait): Return

>> 	sim_data->remote_sim_ptid instead of inferior_ptid.

> 

> This makes sense.  LGTM.

> 

> Thanks,

> Andrew


Thanks, I pushed it.

Simon
Pedro Alves Jan. 20, 2020, 3:13 p.m. | #3
On 1/20/20 12:48 AM, Simon Marchi wrote:
> On 2020-01-19 4:12 p.m., Andrew Burgess wrote:

>> * Simon Marchi <simon.marchi@polymtl.ca> [2020-01-18 22:55:57 -0500]:

>>

>>> When running a program with the simulator target, I get:

>>>

>>>     /home/simark/src/binutils-gdb/gdb/inferior.c:279: internal-error: inferior* find_inferior_pid(process_stratum_target*, int): Assertion `pid != 0' failed.

>>>

>>> This can be reproduced by building a GDB for --target=arm-none-gnueabi,

>>> and running with

>>>

>>>     $ ./gdb -nx --data-directory=data-directory a.out -ex "target sim" -ex load -ex "b main" -ex r

>>>

>>> Where a.out is any program with a main.

>>>

>>> The problem is that gdbsim_target::wait assumes that inferior_ptid has

>>> the value of the thread it wants to report an event for.

>>>

>>> Actually, it's the target's responsibility to come up with the ptid of

>>> the thread the event is for.  In the sim target, that ptid is stored in

>>> sim_inferior_data::remote_sim_ptid, so return that instead of

>>> inferior_ptid.

>>>

>>> ChangeLog:

>>>

>>> 	* remote-sim.c (gdbsim_target::wait): Return

>>> 	sim_data->remote_sim_ptid instead of inferior_ptid.

>>

>> This makes sense.  LGTM.

>>

>> Thanks,

>> Andrew

> 

> Thanks, I pushed it.


Thanks for doing this.  This was a recent assertion I added with
the multi-target work.  It's possibly (and likely) that other ports
will need similar adjustments, but it's hard to tell with actually
running into the issue.

Thanks,
Pedro Alves
Simon Marchi Jan. 20, 2020, 3:27 p.m. | #4
On 2020-01-20 10:13 a.m., Pedro Alves wrote:
> Thanks for doing this.  This was a recent assertion I added with

> the multi-target work.  It's possibly (and likely) that other ports

> will need similar adjustments, but it's hard to tell with actually

> running into the issue.


For the record, this commit [1] helped me understand that this was expected, and
that not using inferior_ptid was indeed the right fix.

[1] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=e7af6c702da7a77529afdeffbbe6e13639beb441

Simon

Patch

diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
index fb05786d4e28..d43648bd5171 100644
--- a/gdb/remote-sim.c
+++ b/gdb/remote-sim.c
@@ -1016,7 +1016,7 @@  gdbsim_target::wait (ptid_t ptid, struct target_waitstatus *status, int options)
       break;
     }
 
-  return inferior_ptid;
+  return sim_data->remote_sim_ptid;
 }
 
 /* Get ready to modify the registers array.  On machines which store