diff mbox

[1/2] Fix regcache::cooked_read_test selftest for mep

Message ID 20191203062031.2844278-1-simon.marchi@polymtl.ca
State New
Headers show

Commit Message

Simon Marchi Dec. 3, 2019, 6:20 a.m. UTC
When running the regcache::cooked_read_test selftest in an all targets
build, I get the following internal error:

    /home/simark/src/binutils-gdb/gdb/thread.c:95: internal-error: thread_info* inferior_thread(): Assertion `tp' failed.

The stack trace is the followiing:

    #9  0x000055fe25584a52 in internal_error (file=0x55fe27a25fe0 "/home/simark/src/binutils-gdb/gdb/thread.c", line=95, fmt=0x55fe27a25c80 "%s: Assertion `%s' failed.")
        at /home/simark/src/binutils-gdb/gdb/gdbsupport/errors.c:55
    #10 0x000055fe260674bc in inferior_thread () at /home/simark/src/binutils-gdb/gdb/thread.c:95
    #11 0x000055fe25c62f0f in get_current_regcache () at /home/simark/src/binutils-gdb/gdb/regcache.c:372
    #12 0x000055fe2594fcf1 in current_options () at /home/simark/src/binutils-gdb/gdb/mep-tdep.c:873
    #13 0x000055fe2594ff08 in mep_register_name (gdbarch=0x62100056f510, regnr=152) at /home/simark/src/binutils-gdb/gdb/mep-tdep.c:958
    #14 0x000055fe25950112 in mep_register_reggroup_p (gdbarch=0x62100056f510, regnum=152, group=0x55fe2924d540 <save_group>) at /home/simark/src/binutils-gdb/gdb/mep-tdep.c:1029
    #15 0x000055fe2555ad87 in gdbarch_register_reggroup_p (gdbarch=0x62100056f510, regnum=152, reggroup=0x55fe2924d540 <save_group>) at /home/simark/src/binutils-gdb/gdb/gdbarch.c:3622
    #16 0x000055fe25c61d45 in reg_buffer::save(gdb::function_view<register_status (int, unsigned char*)>) (this=0x7ffc61a0ed90, cooked_read=...)
        at /home/simark/src/binutils-gdb/gdb/regcache.c:247
    #17 0x000055fe2552ac60 in readonly_detached_regcache::readonly_detached_regcache(gdbarch*, gdb::function_view<register_status (int, unsigned char*)>) (this=0x7ffc61a0ed90,
        gdbarch=0x62100056f510, cooked_read=...) at /home/simark/src/binutils-gdb/gdb/regcache.h:444
    #18 0x000055fe25c61867 in readonly_detached_regcache::readonly_detached_regcache (this=0x7ffc61a0ed90, src=...) at /home/simark/src/binutils-gdb/gdb/regcache.c:212
    #19 0x000055fe25c6a5ca in selftests::cooked_read_test (gdbarch=0x62100056f510) at /home/simark/src/binutils-gdb/gdb/regcache.c:1613

The problems is that mep's code ends up calling inferior_thread, which
calls find_thread_ptid.  find_thread_ptid searches for a thread by ptid
in the thread list of the inferior that is expected to contain that

However, the thread list of the mock inferior set up in cooked_read_test
is never initialized.  So find_thread_ptid doesn't find the thread,
which is an unexpected situation for inferior_thread.

This is failing since this commit:

	Per-inferior thread list, thread ranges/iterators, down with ALL_THREADS, etc.

Fix it by putting the mock thread in the thread list of the mock
inferior in cooked_read_test.


	* regcache.c (cooked_read_test): Initialize thread list of
 gdb/regcache.c | 1 +
 1 file changed, 1 insertion(+)


Tom Tromey Dec. 4, 2019, 5:49 p.m. UTC | #1
>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:

Simon> gdb/ChangeLog:

Simon> 	* regcache.c (cooked_read_test): Initialize thread list of
Simon> 	mock_inferior.

Seems fine.

Simon Marchi Dec. 4, 2019, 6:48 p.m. UTC | #2
On 2019-12-04 12:49 p.m., Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:
> Simon> gdb/ChangeLog:
> Simon> 	* regcache.c (cooked_read_test): Initialize thread list of
> Simon> 	mock_inferior.
> Seems fine.
> Thanks.
> Tom

Thanks, I pushed both patches.
diff mbox


diff --git a/gdb/regcache.c b/gdb/regcache.c
index 2e8b52ee751e..f0f7730f3e4c 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -1535,6 +1535,7 @@  cooked_read_test (struct gdbarch *gdbarch)
   mock_inferior.gdbarch = gdbarch;
   mock_inferior.aspace = &mock_aspace;
   thread_info mock_thread (&mock_inferior, mock_ptid);
+  mock_inferior.thread_list = &mock_thread;
   /* Add the mock inferior to the inferior list so that look ups by
      target+ptid can find it.  */