diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2023-11-17 19:55:58 +0000 |
---|---|---|
committer | Simon Marchi <simon.marchi@efficios.com> | 2023-11-17 20:01:35 +0000 |
commit | 7438771288f1acd5ab25277188a75ce9e48e256c (patch) | |
tree | 7f261a382ee420c2a26d6ed2f0f9305fb5285359 /gdb/regcache.c | |
parent | 4a2530397b87c66bd45b21cf20e2cc12bf26879f (diff) | |
download | gdb-7438771288f1acd5ab25277188a75ce9e48e256c.zip gdb-7438771288f1acd5ab25277188a75ce9e48e256c.tar.gz gdb-7438771288f1acd5ab25277188a75ce9e48e256c.tar.bz2 |
gdb: remove regcache's address space
While looking at the regcache code, I noticed that the address space
(passed to regcache when constructing it, and available through
regcache::aspace) wasn't relevant for the regcache itself. Callers of
regcache::aspace use that method because it appears to be a convenient
way of getting the address space for a thread, if you already have the
regcache. But there is always another way to get the address space, as
the callers pretty much always know which thread they are dealing with.
The regcache code itself doesn't use the address space.
This patch removes anything related to address_space from the regcache
code, and updates callers to get it from the thread in context. This
removes a bit of unnecessary complexity from the regcache code.
The current get_thread_arch_regcache function gets an address_space for
the given thread using the target_thread_address_space function (which
calls the target_ops::thread_address_space method). This suggest that
there might have been the intention of supporting per-thread address
spaces. But digging through the history, I did not find any such case.
Maybe this method was just added because we needed a way to get an
address space from a ptid (because constructing a regcache required an
address space), and this seemed like the right way to do it, I don't
know.
The only implementations of thread_address_space and
process_stratum_target::thread_address_space and
linux_nat_target::thread_address_space, which essentially just return
the inferior's address space. And thread_address_space is only used in
the current get_thread_arch_regcache, which gets removed. So, I think
that the thread_address_space target method can be removed, and we can
assume that it's fine to use the inferior's address space everywhere.
Callers of regcache::aspace are updated to get the address space from
the relevant inferior, either using some context they already know
about, or in last resort using the current global context.
So, to summarize:
- remove everything in regcache related to address spaces
- in particular, remove get_thread_arch_regcache, and rename
get_thread_arch_aspace_regcache to get_thread_arch_regcache
- remove target_ops::thread_address_space, and
target_thread_address_space
- adjust all users of regcache::aspace to get the address space another
way
Change-Id: I04fd41b22c83fe486522af7851c75bcfb31c88c7
Diffstat (limited to 'gdb/regcache.c')
-rw-r--r-- | gdb/regcache.c | 68 |
1 files changed, 26 insertions, 42 deletions
diff --git a/gdb/regcache.c b/gdb/regcache.c index 2e48c02..48a926e 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -208,11 +208,10 @@ reg_buffer::reg_buffer (gdbarch *gdbarch, bool has_pseudo) } } -regcache::regcache (inferior *inf_for_target_calls, gdbarch *gdbarch, - const address_space *aspace_) +regcache::regcache (inferior *inf_for_target_calls, gdbarch *gdbarch) /* The register buffers. A read/write register cache can only hold [0 .. gdbarch_num_regs). */ - : detached_regcache (gdbarch, false), m_aspace (aspace_), + : detached_regcache (gdbarch, false), m_inf_for_target_calls (inf_for_target_calls) { m_ptid = minus_one_ptid; @@ -348,10 +347,9 @@ using target_pid_ptid_regcache_map target when appropriate. */ static target_pid_ptid_regcache_map regcaches; -struct regcache * -get_thread_arch_aspace_regcache (inferior *inf_for_target_calls, - ptid_t ptid, gdbarch *arch, - struct address_space *aspace) +regcache * +get_thread_arch_regcache (inferior *inf_for_target_calls, ptid_t ptid, + gdbarch *arch) { gdb_assert (inf_for_target_calls != nullptr); @@ -373,7 +371,7 @@ get_thread_arch_aspace_regcache (inferior *inf_for_target_calls, } /* It does not exist, create it. */ - regcache *new_regcache = new regcache (inf_for_target_calls, arch, aspace); + regcache *new_regcache = new regcache (inf_for_target_calls, arch); new_regcache->set_ptid (ptid); /* Work around a problem with g++ 4.8 (PR96537): Call the regcache_up constructor explicitly instead of implicitly. */ @@ -382,18 +380,6 @@ get_thread_arch_aspace_regcache (inferior *inf_for_target_calls, return new_regcache; } -struct regcache * -get_thread_arch_regcache (process_stratum_target *target, ptid_t ptid, - struct gdbarch *gdbarch) -{ - scoped_restore_current_inferior restore_current_inferior; - inferior *inf = find_inferior_ptid (target, ptid); - set_current_inferior (inf); - address_space *aspace = target_thread_address_space (ptid); - - return get_thread_arch_aspace_regcache (inf, ptid, gdbarch, aspace); -} - static process_stratum_target *current_thread_target; static ptid_t current_thread_ptid; static struct gdbarch *current_thread_arch; @@ -401,6 +387,8 @@ static struct gdbarch *current_thread_arch; struct regcache * get_thread_regcache (process_stratum_target *target, ptid_t ptid) { + inferior *inf = find_inferior_ptid (target, ptid); + if (!current_thread_arch || target != current_thread_target || current_thread_ptid != ptid) @@ -411,11 +399,11 @@ get_thread_regcache (process_stratum_target *target, ptid_t ptid) current_thread_target = target; scoped_restore_current_inferior restore_current_inferior; - set_current_inferior (find_inferior_ptid (target, ptid)); + set_current_inferior (inf); current_thread_arch = target_thread_architecture (ptid); } - return get_thread_arch_regcache (target, ptid, current_thread_arch); + return get_thread_arch_regcache (inf, ptid, current_thread_arch); } /* See regcache.h. */ @@ -1618,24 +1606,22 @@ regcache_count (process_stratum_target *target, ptid_t ptid) return 0; }; -/* Wrapper around get_thread_arch_aspace_regcache that does some self checks. */ +/* Wrapper around get_thread_arch_regcache that does some self checks. */ static void -get_thread_arch_aspace_regcache_and_check (inferior *inf_for_target_calls, - ptid_t ptid) +get_thread_arch_regcache_and_check (inferior *inf_for_target_calls, + ptid_t ptid) { /* We currently only test with a single gdbarch. Any gdbarch will do, so use the current inferior's gdbarch. Also use the current inferior's address space. */ gdbarch *arch = inf_for_target_calls->arch (); - address_space *aspace = inf_for_target_calls->aspace; - regcache *regcache = get_thread_arch_aspace_regcache (inf_for_target_calls, - ptid, arch, aspace); + regcache *regcache + = get_thread_arch_regcache (inf_for_target_calls, ptid, arch); SELF_CHECK (regcache != NULL); SELF_CHECK (regcache->ptid () == ptid); SELF_CHECK (regcache->arch () == arch); - SELF_CHECK (regcache->aspace () == aspace); } /* The data that the regcaches selftests must hold onto for the duration of the @@ -1683,12 +1669,12 @@ populate_regcaches_for_test () { for (long lwp : { 1, 2, 3 }) { - get_thread_arch_aspace_regcache_and_check + get_thread_arch_regcache_and_check (&data->test_ctx_1.mock_inferior, ptid_t (pid, lwp)); expected_regcache_size++; SELF_CHECK (regcaches_size () == expected_regcache_size); - get_thread_arch_aspace_regcache_and_check + get_thread_arch_regcache_and_check (&data->test_ctx_2.mock_inferior, ptid_t (pid, lwp)); expected_regcache_size++; SELF_CHECK (regcaches_size () == expected_regcache_size); @@ -1699,16 +1685,16 @@ populate_regcaches_for_test () } static void -get_thread_arch_aspace_regcache_test () +get_thread_arch_regcache_test () { /* populate_regcaches_for_test already tests most of the - get_thread_arch_aspace_regcache functionality. */ + get_thread_arch_regcache functionality. */ regcache_test_data_up data = populate_regcaches_for_test (); size_t regcaches_size_before = regcaches_size (); /* Test that getting an existing regcache doesn't create a new one. */ - get_thread_arch_aspace_regcache_and_check (&data->test_ctx_1.mock_inferior, - ptid_t (2, 2)); + get_thread_arch_regcache_and_check (&data->test_ctx_1.mock_inferior, + ptid_t (2, 2)); SELF_CHECK (regcaches_size () == regcaches_size_before); } @@ -1835,7 +1821,7 @@ class readwrite_regcache : public regcache public: readwrite_regcache (inferior *inf_for_target_calls, struct gdbarch *gdbarch) - : regcache (inf_for_target_calls, gdbarch, nullptr) + : regcache (inf_for_target_calls, gdbarch) {} }; @@ -2116,10 +2102,8 @@ regcache_thread_ptid_changed () gdb_assert (regcaches.empty ()); /* Populate the regcaches container. */ - get_thread_arch_aspace_regcache (&target1.mock_inferior, old_ptid, arch, - nullptr); - get_thread_arch_aspace_regcache (&target2.mock_inferior, old_ptid, arch, - nullptr); + get_thread_arch_regcache (&target1.mock_inferior, old_ptid, arch); + get_thread_arch_regcache (&target2.mock_inferior, old_ptid, arch); gdb_assert (regcaches.size () == 2); gdb_assert (regcache_count (&target1.mock_target, old_ptid) == 1); @@ -2163,8 +2147,8 @@ _initialize_regcache () deprecate_cmd (c, "maintenance flush register-cache"); #if GDB_SELF_TEST - selftests::register_test ("get_thread_arch_aspace_regcache", - selftests::get_thread_arch_aspace_regcache_test); + selftests::register_test ("get_thread_arch_regcache", + selftests::get_thread_arch_regcache_test); selftests::register_test ("registers_changed_ptid_all", selftests::registers_changed_ptid_all_test); selftests::register_test ("registers_changed_ptid_target", |