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
This commit is contained in:
Simon Marchi
2023-11-17 19:55:58 +00:00
parent 4a2530397b
commit 7438771288
25 changed files with 113 additions and 252 deletions

View File

@@ -2472,6 +2472,17 @@ stop_wait_callback (struct lwp_info *lp)
return 0;
}
/* Get the inferior associated to LWP. Must be called with an LWP that has
an associated inferior. Always return non-nullptr. */
static inferior *
lwp_inferior (const lwp_info *lwp)
{
inferior *inf = find_inferior_ptid (linux_target, lwp->ptid);
gdb_assert (inf != nullptr);
return inf;
}
/* Return non-zero if LP has a wait status pending. Discard the
pending event and resume the LWP if the event that originally
caused the stop became uninteresting. */
@@ -2507,7 +2518,7 @@ status_callback (struct lwp_info *lp)
}
#if !USE_SIGTRAP_SIGINFO
else if (!breakpoint_inserted_here_p (regcache->aspace (), pc))
else if (!breakpoint_inserted_here_p (lwp_inferior (lp)->aspace, pc))
{
linux_nat_debug_printf ("previous breakpoint of %s, at %s gone",
lp->ptid.to_string ().c_str (),
@@ -2607,7 +2618,7 @@ save_stop_reason (struct lwp_info *lp)
if (!linux_target->low_status_is_event (lp->status))
return;
inferior *inf = find_inferior_ptid (linux_target, lp->ptid);
inferior *inf = lwp_inferior (lp);
if (inf->starting_up)
return;
@@ -2662,15 +2673,14 @@ save_stop_reason (struct lwp_info *lp)
}
#else
if ((!lp->step || lp->stop_pc == sw_bp_pc)
&& software_breakpoint_inserted_here_p (regcache->aspace (),
sw_bp_pc))
&& software_breakpoint_inserted_here_p (inf->aspace, sw_bp_pc))
{
/* The LWP was either continued, or stepped a software
breakpoint instruction. */
lp->stop_reason = TARGET_STOPPED_BY_SW_BREAKPOINT;
}
if (hardware_breakpoint_inserted_here_p (regcache->aspace (), pc))
if (hardware_breakpoint_inserted_here_p (inf->aspace, pc))
lp->stop_reason = TARGET_STOPPED_BY_HW_BREAKPOINT;
if (lp->stop_reason == TARGET_STOPPED_BY_NO_REASON)
@@ -3417,7 +3427,7 @@ linux_nat_wait_1 (ptid_t ptid, struct target_waitstatus *ourstatus,
static int
resume_stopped_resumed_lwps (struct lwp_info *lp, const ptid_t wait_ptid)
{
inferior *inf = find_inferior_ptid (linux_target, lp->ptid);
inferior *inf = lwp_inferior (lp);
if (!lp->stopped)
{
@@ -3453,7 +3463,7 @@ resume_stopped_resumed_lwps (struct lwp_info *lp, const ptid_t wait_ptid)
immediately, and we're not waiting for this LWP. */
if (!lp->ptid.matches (wait_ptid))
{
if (breakpoint_inserted_here_p (regcache->aspace (), pc))
if (breakpoint_inserted_here_p (inf->aspace, pc))
leave_stopped = 1;
}
@@ -4383,38 +4393,6 @@ linux_nat_target::stop (ptid_t ptid)
iterate_over_lwps (ptid, linux_nat_stop_lwp);
}
/* When requests are passed down from the linux-nat layer to the
single threaded inf-ptrace layer, ptids of (lwpid,0,0) form are
used. The address space pointer is stored in the inferior object,
but the common code that is passed such ptid can't tell whether
lwpid is a "main" process id or not (it assumes so). We reverse
look up the "main" process id from the lwp here. */
struct address_space *
linux_nat_target::thread_address_space (ptid_t ptid)
{
struct lwp_info *lwp;
struct inferior *inf;
int pid;
if (ptid.lwp () == 0)
{
/* An (lwpid,0,0) ptid. Look up the lwp object to get at the
tgid. */
lwp = find_lwp_pid (ptid);
pid = lwp->ptid.pid ();
}
else
{
/* A (pid,lwpid,0) ptid. */
pid = ptid.pid ();
}
inf = find_inferior_pid (this, pid);
gdb_assert (inf != NULL);
return inf->aspace;
}
/* Return the cached value of the processor core for thread PTID. */
int