diff options
author | Pedro Alves <palves@redhat.com> | 2020-06-23 15:18:41 +0100 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2020-06-23 18:57:03 +0100 |
commit | 236ef0346d88efffd1ca1da1a5d80724cb145660 (patch) | |
tree | 476ad3f4157021679bdb39747e460371c2d45283 /gdb/gdbarch-selftests.c | |
parent | bb8d126033bc7982808323da80ac8649e27bb3eb (diff) | |
download | gdb-236ef0346d88efffd1ca1da1a5d80724cb145660.zip gdb-236ef0346d88efffd1ca1da1a5d80724cb145660.tar.gz gdb-236ef0346d88efffd1ca1da1a5d80724cb145660.tar.bz2 |
Fix "maint selftest" regression, add struct scoped_mock_context
This commit:
commit 3922b302645fda04da42a5279399578ae2f6206c
Author: Pedro Alves <palves@redhat.com>
AuthorDate: Thu Jun 18 21:28:37 2020 +0100
Decouple inferior_ptid/inferior_thread(); dup ptids in thread list (PR 25412)
caused a regression for gdb.gdb/unittest.exp when GDB is configured
with --enable-targets=all. The failure is:
gdb/thread.c:95: internal-error: thread_info* inferior_thread(): Assertion `current_thread_ != nullptr' failed.
The problem is in this line in regcache.c:cooked_read_test:
/* Switch to the mock thread. */
scoped_restore restore_inferior_ptid
= make_scoped_restore (&inferior_ptid, mock_ptid);
Both gdbarch-selftest.c and regcache.c set up a similar mock context,
but the series the patch above belongs to only updated the
gdbarch-selftest.c context to not write to inferior_ptid directly, and
missed updating regcache.c's.
Instead of copying the fix over to regcache.c, share the mock context
setup code in a new RAII class, based on gdbarch-selftest.c's version.
Also remove the "target already pushed" error from regcache.c, like it
had been removed from gdbarch-selftest.c in the multi-target series.
That check is unnecessary because each inferior now has its own target
stack, and the unit test pushes a target on a separate (mock)
inferior, not the current inferior on entry.
gdb/ChangeLog:
2020-06-23 Pedro Alves <palves@redhat.com>
* gdbarch-selftests.c: Don't include inferior.h, gdbthread.h or
progspace-and-thread.h. Include scoped-mock-context.h instead.
(register_to_value_test): Use scoped_mock_context.
* regcache.c: Include "scoped-mock-context.h".
(cooked_read_test): Don't error out if a target is already pushed.
Use scoped_mock_context. Adjust.
* scoped-mock-context.h: New file.
Diffstat (limited to 'gdb/gdbarch-selftests.c')
-rw-r--r-- | gdb/gdbarch-selftests.c | 39 |
1 files changed, 2 insertions, 37 deletions
diff --git a/gdb/gdbarch-selftests.c b/gdb/gdbarch-selftests.c index 91aa9d8..4f9adbd 100644 --- a/gdb/gdbarch-selftests.c +++ b/gdb/gdbarch-selftests.c @@ -20,14 +20,12 @@ #include "defs.h" #include "gdbsupport/selftest.h" #include "selftest-arch.h" -#include "inferior.h" -#include "gdbthread.h" #include "target.h" #include "test-target.h" #include "target-float.h" #include "gdbsupport/def-vector.h" #include "gdbarch.h" -#include "progspace-and-thread.h" +#include "scoped-mock-context.h" namespace selftests { @@ -71,40 +69,7 @@ register_to_value_test (struct gdbarch *gdbarch) builtin->builtin_char32, }; - /* Create a mock environment. An inferior with a thread, with a - process_stratum target pushed. */ - - test_target_ops mock_target; - ptid_t mock_ptid (1, 1); - program_space mock_pspace (new_address_space ()); - inferior mock_inferior (mock_ptid.pid ()); - mock_inferior.gdbarch = gdbarch; - mock_inferior.aspace = mock_pspace.aspace; - mock_inferior.pspace = &mock_pspace; - thread_info mock_thread (&mock_inferior, mock_ptid); - - scoped_restore_current_pspace_and_thread restore_pspace_thread; - - scoped_restore restore_thread_list - = make_scoped_restore (&mock_inferior.thread_list, &mock_thread); - - /* Add the mock inferior to the inferior list so that look ups by - target+ptid can find it. */ - scoped_restore restore_inferior_list - = make_scoped_restore (&inferior_list, &mock_inferior); - - /* Switch to the mock inferior. */ - switch_to_inferior_no_thread (&mock_inferior); - - /* Push the process_stratum target so we can mock accessing - registers. */ - push_target (&mock_target); - - /* Pop it again on exit (return/exception). */ - SCOPE_EXIT { pop_all_targets_at_and_above (process_stratum); }; - - /* Switch to the mock thread. */ - switch_to_thread (&mock_thread); + scoped_mock_context<test_target_ops> mockctx (gdbarch); struct frame_info *frame = get_current_frame (); const int num_regs = gdbarch_num_cooked_regs (gdbarch); |