]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: remove regcache's address space
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 17 Nov 2023 19:55:58 +0000 (19:55 +0000)
committerSimon Marchi <simon.marchi@efficios.com>
Fri, 17 Nov 2023 20:01:35 +0000 (20:01 +0000)
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

25 files changed:
gdb/aarch64-fbsd-tdep.c
gdb/amd64-fbsd-tdep.c
gdb/arm-fbsd-tdep.c
gdb/darwin-nat.c
gdb/displaced-stepping.c
gdb/frame.c
gdb/gcore-elf.c
gdb/i386-fbsd-tdep.c
gdb/infrun.c
gdb/linux-nat.c
gdb/linux-nat.h
gdb/ppc-fbsd-tdep.c
gdb/proc-service.c
gdb/process-stratum-target.c
gdb/process-stratum-target.h
gdb/record-full.c
gdb/regcache.c
gdb/regcache.h
gdb/remote.c
gdb/riscv-fbsd-tdep.c
gdb/sol-thread.c
gdb/solib-svr4.c
gdb/target-delegates.c
gdb/target.c
gdb/target.h

index 1102eb0d13b870083023445dad89dcf2b453a26a..681149b1c6ce975d0d90d2a6e5f887a27bd1093f 100644 (file)
@@ -215,8 +215,7 @@ aarch64_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
   aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   struct regcache *regcache;
 
-  regcache = get_thread_arch_regcache (current_inferior ()->process_target (),
-                                      ptid, gdbarch);
+  regcache = get_thread_arch_regcache (current_inferior (), ptid, gdbarch);
 
   target_fetch_registers (regcache, tdep->tls_regnum_base);
 
index 2b633cd479cc6187394e8dce9000701134bbfd70..5b0896fcd417a9a4d5206a8216b7c31d14b2c777 100644 (file)
@@ -288,10 +288,8 @@ static CORE_ADDR
 amd64fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
                                    CORE_ADDR lm_addr, CORE_ADDR offset)
 {
-  struct regcache *regcache;
-
-  regcache = get_thread_arch_regcache (current_inferior ()->process_target (),
-                                      ptid, gdbarch);
+  regcache *regcache
+    = get_thread_arch_regcache (current_inferior (), ptid, gdbarch);
 
   target_fetch_registers (regcache, AMD64_FSBASE_REGNUM);
 
index b6aa42a4fd056bf65262ec77ecac0be23e575d11..90273a3f5ef8d5924abfebdd22481904b5c6d41c 100644 (file)
@@ -271,10 +271,8 @@ arm_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
                                   CORE_ADDR lm_addr, CORE_ADDR offset)
 {
   arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
-  struct regcache *regcache;
-
-  regcache = get_thread_arch_regcache (current_inferior ()->process_target (),
-                                      ptid, gdbarch);
+  regcache *regcache
+    = get_thread_arch_regcache (current_inferior (), ptid, gdbarch);
 
   target_fetch_registers (regcache, tdep->tls_regnum);
 
index 588e9e2a34578d35741a928491d14aab17322bb7..0de476b022bbc493dad1d97b1f041f3221c134d0 100644 (file)
@@ -1151,7 +1151,7 @@ darwin_nat_target::decode_message (mach_msg_header_t *hdr,
 }
 
 int
-darwin_nat_target::cancel_breakpoint (ptid_t ptid)
+darwin_nat_target::cancel_breakpoint (inferior *inf, ptid_t ptid)
 {
   /* Arrange for a breakpoint to be hit again later.  We will handle
      the current event, eventually we will resume this thread, and this
@@ -1166,7 +1166,7 @@ darwin_nat_target::cancel_breakpoint (ptid_t ptid)
   CORE_ADDR pc;
 
   pc = regcache_read_pc (regcache) - gdbarch_decr_pc_after_break (gdbarch);
-  if (breakpoint_inserted_here_p (regcache->aspace (), pc))
+  if (breakpoint_inserted_here_p (inf->aspace, pc))
     {
       inferior_debug (4, "cancel_breakpoint for thread 0x%lx\n",
                      (unsigned long) ptid.tid ());
@@ -1286,7 +1286,8 @@ darwin_nat_target::wait_1 (ptid_t ptid, struct target_waitstatus *status)
          && thread->event.ex_type == EXC_BREAKPOINT)
        {
          if (thread->single_step
-             || cancel_breakpoint (ptid_t (inf->pid, 0, thread->gdb_port)))
+             || cancel_breakpoint (inf,
+                                   ptid_t (inf->pid, 0, thread->gdb_port)))
            {
              gdb_assert (thread->msg_state == DARWIN_MESSAGE);
              darwin_send_reply (inf, thread);
index 6d5e6cddb9b36b7246f813a498a4fa26f15a3ad3..9d45013e62cee9fb8b8f4a4ef09f0f59dc8060e2 100644 (file)
@@ -53,7 +53,6 @@ displaced_step_buffers::prepare (thread_info *thread, CORE_ADDR &displaced_pc)
     gdb_assert (buf.current_thread != thread);
 
   regcache *regcache = get_thread_regcache (thread);
-  const address_space *aspace = regcache->aspace ();
   gdbarch *arch = regcache->arch ();
   ULONGEST len = gdbarch_displaced_step_buffer_length (arch);
 
@@ -64,7 +63,7 @@ displaced_step_buffers::prepare (thread_info *thread, CORE_ADDR &displaced_pc)
 
   for (displaced_step_buffer &candidate : m_buffers)
     {
-      bool bp_in_range = breakpoint_in_range_p (aspace, candidate.addr, len);
+      bool bp_in_range = breakpoint_in_range_p (thread->inf->aspace, candidate.addr, len);
       bool is_free = candidate.current_thread == nullptr;
 
       if (!bp_in_range)
index 4a46ccb9abc0485b2c2b160aa52d858641b113d2..dfd92991d99a03f7a30beb653176ae72333c3bf7 100644 (file)
@@ -1620,14 +1620,15 @@ put_frame_register_bytes (frame_info_ptr frame, int regnum,
    CODE_ADDR.  */
 
 static frame_info_ptr
-create_sentinel_frame (struct program_space *pspace, struct regcache *regcache,
-                      CORE_ADDR stack_addr, CORE_ADDR code_addr)
+create_sentinel_frame (program_space *pspace, address_space *aspace,
+                      regcache *regcache, CORE_ADDR stack_addr,
+                      CORE_ADDR code_addr)
 {
   frame_info *frame = FRAME_OBSTACK_ZALLOC (struct frame_info);
 
   frame->level = -1;
   frame->pspace = pspace;
-  frame->aspace = regcache->aspace ();
+  frame->aspace = aspace;
   /* Explicitly initialize the sentinel frame's cache.  Provide it
      with the underlying regcache.  In the future additional
      information, such as the frame's thread will be added.  */
@@ -1688,8 +1689,8 @@ get_current_frame (void)
 
   if (sentinel_frame == NULL)
     sentinel_frame =
-      create_sentinel_frame (current_program_space, get_current_regcache (),
-                            0, 0).get ();
+      create_sentinel_frame (current_program_space, current_inferior ()->aspace,
+                            get_current_regcache (), 0, 0).get ();
 
   /* Set the current frame before computing the frame id, to avoid
      recursion inside compute_frame_id, in case the frame's
@@ -2022,6 +2023,7 @@ create_new_frame (frame_id id)
   frame_info *fi = FRAME_OBSTACK_ZALLOC (struct frame_info);
 
   fi->next = create_sentinel_frame (current_program_space,
+                                   current_inferior ()->aspace,
                                    get_current_regcache (),
                                    id.stack_addr, id.code_addr).get ();
 
index 0142db82670d9a2e6449ca334c0df103ceddf2a9..8b4177cfe257d853ce17f8818c9a2a774c383a3a 100644 (file)
@@ -128,9 +128,8 @@ gcore_elf_build_thread_register_notes
   (struct gdbarch *gdbarch, struct thread_info *info, gdb_signal stop_signal,
    bfd *obfd, gdb::unique_xmalloc_ptr<char> *note_data, int *note_size)
 {
-  struct regcache *regcache
-    = get_thread_arch_regcache (info->inf->process_target (),
-                               info->ptid, gdbarch);
+  regcache *regcache
+    = get_thread_arch_regcache (info->inf, info->ptid, gdbarch);
   target_fetch_registers (regcache, -1);
   gcore_elf_collect_thread_registers (regcache, info->ptid, obfd,
                                      note_data, note_size, stop_signal);
index f8c2758c2b0c0aca87b5db2a8b398d612a1622b0..58d06e3676704e60e321a168039b4933ce4dd487 100644 (file)
@@ -354,10 +354,8 @@ static CORE_ADDR
 i386fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
                                   CORE_ADDR lm_addr, CORE_ADDR offset)
 {
-  struct regcache *regcache;
-
-  regcache = get_thread_arch_regcache (current_inferior ()->process_target (),
-                                      ptid, gdbarch);
+  regcache *regcache
+    = get_thread_arch_regcache (current_inferior (), ptid, gdbarch);
 
   target_fetch_registers (regcache, I386_GSBASE_REGNUM);
 
index 62b306ff347935f4926faf03f98db9017cdced32..785a4e198ec2bb969baa48dbb3260c234a5950b8 100644 (file)
@@ -2079,10 +2079,8 @@ displaced_step_finish (thread_info *event_thread,
         point.  */
 
       struct regcache *child_regcache
-       = get_thread_arch_aspace_regcache (parent_inf,
-                                          event_status.child_ptid (),
-                                          gdbarch,
-                                          parent_inf->aspace);
+       = get_thread_arch_regcache (parent_inf, event_status.child_ptid (),
+                                   gdbarch);
       /* Read PC value of parent.  */
       CORE_ADDR parent_pc = regcache_read_pc (regcache);
 
@@ -2626,7 +2624,6 @@ resume_1 (enum gdb_signal sig)
   struct regcache *regcache = get_current_regcache ();
   struct gdbarch *gdbarch = regcache->arch ();
   struct thread_info *tp = inferior_thread ();
-  const address_space *aspace = regcache->aspace ();
   ptid_t resume_ptid;
   /* This represents the user's step vs continue request.  When
      deciding whether "set scheduler-locking step" applies, it's the
@@ -2705,6 +2702,8 @@ resume_1 (enum gdb_signal sig)
                       inferior_ptid.to_string ().c_str (),
                       paddress (gdbarch, pc));
 
+  const address_space *aspace = tp->inf->aspace;
+
   /* Normally, by the time we reach `resume', the breakpoints are either
      removed or inserted, as appropriate.  The exception is if we're sitting
      at a permanent breakpoint; we need to step over it, but permanent
@@ -2819,8 +2818,8 @@ resume_1 (enum gdb_signal sig)
          if (target_is_non_stop_p ())
            stop_all_threads ("displaced stepping falling back on inline stepping");
 
-         set_step_over_info (regcache->aspace (),
-                             regcache_read_pc (regcache), 0, tp->global_num);
+         set_step_over_info (aspace, regcache_read_pc (regcache), 0,
+                             tp->global_num);
 
          step = maybe_software_singlestep (gdbarch);
 
@@ -3147,7 +3146,7 @@ thread_still_needs_step_over_bp (struct thread_info *tp)
     {
       struct regcache *regcache = get_thread_regcache (tp);
 
-      if (breakpoint_here_p (regcache->aspace (),
+      if (breakpoint_here_p (tp->inf->aspace,
                             regcache_read_pc (regcache))
          == ordinary_breakpoint_here)
        return true;
@@ -3590,7 +3589,6 @@ proceed (CORE_ADDR addr, enum gdb_signal siggnal)
 
   regcache = get_current_regcache ();
   gdbarch = regcache->arch ();
-  const address_space *aspace = regcache->aspace ();
 
   pc = regcache_read_pc_protected (regcache);
 
@@ -3612,6 +3610,8 @@ proceed (CORE_ADDR addr, enum gdb_signal siggnal)
 
   if (addr == (CORE_ADDR) -1)
     {
+      const address_space *aspace = cur_thr->inf->aspace;
+
       if (cur_thr->stop_pc_p ()
          && pc == cur_thr->stop_pc ()
          && breakpoint_here_p (aspace, pc) == ordinary_breakpoint_here
@@ -4040,7 +4040,7 @@ do_target_wait_1 (inferior *inf, ptid_t ptid,
                               paddress (gdbarch, pc));
          discard = 1;
        }
-      else if (!breakpoint_inserted_here_p (regcache->aspace (), pc))
+      else if (!breakpoint_inserted_here_p (tp->inf->aspace, pc))
        {
          infrun_debug_printf ("previous breakpoint of %s, at %s gone",
                               tp->ptid.to_string ().c_str (),
@@ -4937,7 +4937,7 @@ adjust_pc_after_break (struct thread_info *thread,
   if (decr_pc == 0)
     return;
 
-  const address_space *aspace = regcache->aspace ();
+  const address_space *aspace = thread->inf->aspace;
 
   /* Find the location where (if we've hit a breakpoint) the
      breakpoint would be.  */
@@ -5089,7 +5089,7 @@ handle_syscall_event (struct execution_control_state *ecs)
       infrun_debug_printf ("syscall number=%d", syscall_number);
 
       ecs->event_thread->control.stop_bpstat
-       = bpstat_stop_status_nowatch (regcache->aspace (),
+       = bpstat_stop_status_nowatch (ecs->event_thread->inf->aspace,
                                      ecs->event_thread->stop_pc (),
                                      ecs->event_thread, ecs->ws);
 
@@ -5288,7 +5288,7 @@ save_waitstatus (struct thread_info *tp, const target_waitstatus &ws)
       && ws.sig () == GDB_SIGNAL_TRAP)
     {
       struct regcache *regcache = get_thread_regcache (tp);
-      const address_space *aspace = regcache->aspace ();
+      const address_space *aspace = tp->inf->aspace;
       CORE_ADDR pc = regcache_read_pc (regcache);
 
       adjust_pc_after_break (tp, tp->pending_waitstatus ());
@@ -6085,7 +6085,7 @@ handle_inferior_event (struct execution_control_state *ecs)
     {
       struct regcache *regcache = get_thread_regcache (ecs->event_thread);
 
-      if (breakpoint_inserted_here_p (regcache->aspace (),
+      if (breakpoint_inserted_here_p (ecs->event_thread->inf->aspace,
                                      regcache_read_pc (regcache)))
        {
          infrun_debug_printf ("Treating signal as SIGTRAP");
@@ -6118,7 +6118,7 @@ handle_inferior_event (struct execution_control_state *ecs)
 
            ecs->event_thread->set_stop_pc (regcache_read_pc (regcache));
            ecs->event_thread->control.stop_bpstat
-             = bpstat_stop_status_nowatch (regcache->aspace (),
+             = bpstat_stop_status_nowatch (ecs->event_thread->inf->aspace,
                                            ecs->event_thread->stop_pc (),
                                            ecs->event_thread, ecs->ws);
 
@@ -6312,7 +6312,7 @@ handle_inferior_event (struct execution_control_state *ecs)
        (regcache_read_pc (get_thread_regcache (ecs->event_thread)));
 
       ecs->event_thread->control.stop_bpstat
-       = bpstat_stop_status_nowatch (get_current_regcache ()->aspace (),
+       = bpstat_stop_status_nowatch (ecs->event_thread->inf->aspace,
                                      ecs->event_thread->stop_pc (),
                                      ecs->event_thread, ecs->ws);
 
@@ -6458,7 +6458,7 @@ handle_inferior_event (struct execution_control_state *ecs)
        (regcache_read_pc (get_thread_regcache (ecs->event_thread)));
 
       ecs->event_thread->control.stop_bpstat
-       = bpstat_stop_status_nowatch (get_current_regcache ()->aspace (),
+       = bpstat_stop_status_nowatch (ecs->event_thread->inf->aspace,
                                      ecs->event_thread->stop_pc (),
                                      ecs->event_thread, ecs->ws);
 
@@ -6884,7 +6884,7 @@ handle_signal_stop (struct execution_control_state *ecs)
       CORE_ADDR pc;
 
       regcache = get_thread_regcache (ecs->event_thread);
-      const address_space *aspace = regcache->aspace ();
+      const address_space *aspace = ecs->event_thread->inf->aspace;
 
       pc = regcache_read_pc (regcache);
 
@@ -6968,8 +6968,7 @@ handle_signal_stop (struct execution_control_state *ecs)
      inline function call sites).  */
   if (ecs->event_thread->control.step_range_end != 1)
     {
-      const address_space *aspace
-       = get_thread_regcache (ecs->event_thread)->aspace ();
+      const address_space *aspace = ecs->event_thread->inf->aspace;
 
       /* skip_inline_frames is expensive, so we avoid it if we can
         determine that the address is one where functions cannot have
@@ -7047,7 +7046,7 @@ handle_signal_stop (struct execution_control_state *ecs)
   /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
      handles this event.  */
   ecs->event_thread->control.stop_bpstat
-    = bpstat_stop_status (get_current_regcache ()->aspace (),
+    = bpstat_stop_status (ecs->event_thread->inf->aspace,
                          ecs->event_thread->stop_pc (),
                          ecs->event_thread, ecs->ws, stop_chain);
 
@@ -8931,7 +8930,7 @@ keep_going_pass_signal (struct execution_control_state *ecs)
       if (remove_bp
          && (remove_wps || !use_displaced_stepping (ecs->event_thread)))
        {
-         set_step_over_info (regcache->aspace (),
+         set_step_over_info (ecs->event_thread->inf->aspace,
                              regcache_read_pc (regcache), remove_wps,
                              ecs->event_thread->global_num);
        }
index 8951b34e192109c41e5cac930717c3798bed5280..d3e9560c2fc53de9b7c5687c943c1fc2e9fe8749 100644 (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
index cf236160b4a64b936afe6087b2c5ffb670c4da44..cce8bb3ddcc568d1169aade4c778e7131dbc8e94 100644 (file)
@@ -68,8 +68,6 @@ public:
 
   const char *thread_name (struct thread_info *) override;
 
-  struct address_space *thread_address_space (ptid_t) override;
-
   bool stopped_by_watchpoint () override;
 
   bool stopped_data_address (CORE_ADDR *) override;
index 4355b6483fea064defac96da0678c072190cc01c..2238a22afd90ecf1db7e7f13702a297878a9cf68 100644 (file)
@@ -288,11 +288,9 @@ ppcfbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
                                  CORE_ADDR lm_addr, CORE_ADDR offset)
 {
   ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
-  struct regcache *regcache;
   int tp_offset, tp_regnum;
-
-  regcache = get_thread_arch_regcache (current_inferior ()->process_target (),
-                                      ptid, gdbarch);
+  regcache *regcache
+    = get_thread_arch_regcache (current_inferior (), ptid, gdbarch);
 
   if (tdep->wordsize == 4)
     {
index e41278dbe6a8d64a714a6fe588126920b3677c30..48f3dec5587143862a9f8a520201f5bc9f604066 100644 (file)
@@ -135,8 +135,7 @@ static struct regcache *
 get_ps_regcache (struct ps_prochandle *ph, lwpid_t lwpid)
 {
   inferior *inf = ph->thread->inf;
-  return get_thread_arch_regcache (inf->process_target (),
-                                  ptid_t (inf->pid, lwpid),
+  return get_thread_arch_regcache (inf, ptid_t (inf->pid, lwpid),
                                   inf->arch ());
 }
 
index 173c3ecad1345a3f4b94fcfea765c8daa2539b22..017d26e28df1b97e5c903e74263a506d4e737f2d 100644 (file)
@@ -26,20 +26,6 @@ process_stratum_target::~process_stratum_target ()
 {
 }
 
-struct address_space *
-process_stratum_target::thread_address_space (ptid_t ptid)
-{
-  /* Fall-back to the "main" address space of the inferior.  */
-  inferior *inf = find_inferior_ptid (this, ptid);
-
-  if (inf == NULL || inf->aspace == NULL)
-    internal_error (_("Can't determine the current "
-                     "address space of thread %s\n"),
-                   target_pid_to_str (ptid).c_str ());
-
-  return inf->aspace;
-}
-
 struct gdbarch *
 process_stratum_target::thread_architecture (ptid_t ptid)
 {
index f4968ec47019135d00aed67ee6ea62d274bfb068..f35b59978f8200c0cf76e2a6c9bef43b634acf9c 100644 (file)
@@ -51,10 +51,6 @@ public:
   bool supports_non_stop () override { return false; }
   bool supports_disable_randomization () override { return false; }
 
-  /* This default implementation returns the inferior's address
-     space.  */
-  struct address_space *thread_address_space (ptid_t ptid) override;
-
   /* This default implementation always returns the current inferior's
      gdbarch.  */
   struct gdbarch *thread_architecture (ptid_t ptid) override;
index 2ee08e6d54fb9c9d7d66b0230363a94c0e3d7abb..1cea869e88bb1c7162f15aa8c6acc89e3f44646b 100644 (file)
@@ -884,7 +884,7 @@ record_full_exec_insn (struct regcache *regcache,
                       not doing the change at all if the watchpoint
                       traps.  */
                    if (hardware_watchpoint_inserted_in_range
-                       (regcache->aspace (),
+                       (current_inferior ()->aspace,
                         entry->u.mem.addr, entry->u.mem.len))
                      record_full_stop_reason = TARGET_STOPPED_BY_WATCHPOINT;
                  }
@@ -1218,7 +1218,7 @@ record_full_wait_1 (struct target_ops *ops,
                                    ret);
                  regcache = get_current_regcache ();
                  tmp_pc = regcache_read_pc (regcache);
-                 const struct address_space *aspace = regcache->aspace ();
+                 const address_space *aspace = current_inferior ()->aspace;
 
                  if (target_stopped_by_watchpoint ())
                    {
@@ -1288,7 +1288,7 @@ record_full_wait_1 (struct target_ops *ops,
                        record_full_resume_ptid);
       struct regcache *regcache = get_current_regcache ();
       struct gdbarch *gdbarch = regcache->arch ();
-      const struct address_space *aspace = regcache->aspace ();
+      const address_space *aspace = current_inferior ()->aspace;
       int continue_flag = 1;
       int first_record_full_end = 1;
 
index 2e48c025809148e1779ff469b167ec7ea8387577..48a926ed44832d626ab435c7cce1275ca5d34bfe 100644 (file)
@@ -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",
index 57ddac465f09ed220337dd0af97d6253a2a4b979..f73f08a44ab7beb8008b0cb8706cf716bb7ccc56 100644 (file)
@@ -26,7 +26,6 @@
 struct regcache;
 struct regset;
 struct gdbarch;
-struct address_space;
 class thread_info;
 struct process_stratum_target;
 struct inferior;
@@ -38,11 +37,8 @@ extern struct regcache *get_thread_regcache (process_stratum_target *target,
 /* Get the regcache of THREAD.  */
 extern struct regcache *get_thread_regcache (thread_info *thread);
 
-extern struct regcache *get_thread_arch_regcache
-  (process_stratum_target *targ, ptid_t, struct gdbarch *);
-extern struct regcache *get_thread_arch_aspace_regcache
-  (inferior *inf_for_target_calls, ptid_t,
-   struct gdbarch *, struct address_space *);
+extern regcache *get_thread_arch_regcache (inferior *inf_for_target_calls,
+                                          ptid_t ptid, gdbarch *arch);
 
 extern enum register_status
   regcache_raw_read_signed (struct regcache *regcache,
@@ -339,12 +335,6 @@ class regcache : public detached_regcache
 public:
   DISABLE_COPY_AND_ASSIGN (regcache);
 
-  /* Return REGCACHE's address space.  */
-  const address_space *aspace () const
-  {
-    return m_aspace;
-  }
-
   /* Restore 'this' regcache.  The set of registers restored into
      the regcache determined by the restore_reggroup.
      Writes to regcache will go through to the target.  SRC is a
@@ -422,8 +412,7 @@ public:
   void debug_print_register (const char *func, int regno);
 
 protected:
-  regcache (inferior *inf_for_target_calls, gdbarch *gdbarch,
-           const address_space *aspace);
+  regcache (inferior *inf_for_target_calls, gdbarch *gdbarch);
 
 private:
 
@@ -445,10 +434,6 @@ private:
   enum register_status write_part (int regnum, int offset, int len,
                                   const gdb_byte *in, bool is_raw);
 
-  /* The address space of this register cache (for registers where it
-     makes sense, like PC or SP).  */
-  const address_space * const m_aspace;
-
   /* The inferior to switch to, to make target calls.
 
      This may not be the inferior of thread M_PTID.  For instance, this
@@ -462,10 +447,8 @@ private:
      it connected to?  */
   ptid_t m_ptid;
 
-  friend struct regcache *
-  get_thread_arch_aspace_regcache (inferior *inf_for_target_calls, ptid_t ptid,
-                                  struct gdbarch *gdbarch,
-                                  struct address_space *aspace);
+  friend regcache *get_thread_arch_regcache (inferior *inf_for_target_calls,
+                                            ptid_t ptid, gdbarch *gdbarch);
 };
 
 using regcache_up = std::unique_ptr<regcache>;
index ce5addade6f7c7bd3e49078ed299e319bd97c211..501270041d84d397c61e7a90528db475b8cfc132 100644 (file)
@@ -8421,6 +8421,8 @@ remote_target::process_stop_reply (struct stop_reply *stop_reply,
       && status->kind () != TARGET_WAITKIND_SIGNALLED
       && status->kind () != TARGET_WAITKIND_NO_RESUMED)
     {
+      remote_notice_new_inferior (ptid, false);
+
       /* Expedited registers.  */
       if (!stop_reply->regcache.empty ())
        {
@@ -8429,8 +8431,9 @@ remote_target::process_stop_reply (struct stop_reply *stop_reply,
             already).  */
          gdb_assert (status->kind () != TARGET_WAITKIND_THREAD_EXITED);
 
-         struct regcache *regcache
-           = get_thread_arch_regcache (this, ptid, stop_reply->arch);
+         regcache *regcache
+           = get_thread_arch_regcache (find_inferior_ptid (this, ptid), ptid,
+                                       stop_reply->arch);
 
          for (cached_reg_t &reg : stop_reply->regcache)
            {
@@ -8441,7 +8444,6 @@ remote_target::process_stop_reply (struct stop_reply *stop_reply,
          stop_reply->regcache.clear ();
        }
 
-      remote_notice_new_inferior (ptid, false);
       remote_thread_info *remote_thr = get_remote_thread_info (this, ptid);
       remote_thr->core = stop_reply->core;
       remote_thr->stop_reason = stop_reply->stop_reason;
index 8ae4a1953bcc2694bb4d9d17b6de8032996b31e1..9050cf425ec10e3f6578520689591554f7f68e5e 100644 (file)
@@ -166,10 +166,8 @@ static CORE_ADDR
 riscv_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
                                     CORE_ADDR lm_addr, CORE_ADDR offset)
 {
-  struct regcache *regcache;
-
-  regcache = get_thread_arch_regcache (current_inferior ()->process_target (),
-                                      ptid, gdbarch);
+  regcache *regcache
+    = get_thread_arch_regcache (current_inferior (), ptid, gdbarch);
 
   target_fetch_registers (regcache, RISCV_TP_REGNUM);
 
index 537acdb57548341955eea5e618140d2c784e54e8..61331f9d40fc90d36a33e265879c538be2cc772b 100644 (file)
@@ -845,9 +845,8 @@ ps_err_e
 ps_lgetregs (struct ps_prochandle *ph, lwpid_t lwpid, prgregset_t gregset)
 {
   ptid_t ptid = ptid_t (current_inferior ()->pid, lwpid, 0);
-  struct regcache *regcache
-    = get_thread_arch_regcache (current_inferior ()->process_target (),
-                               ptid, current_inferior ()->arch ());
+  regcache *regcache = get_thread_arch_regcache (current_inferior (), ptid,
+                                                current_inferior ()->arch ());
 
   target_fetch_registers (regcache, -1);
   fill_gregset (regcache, (gdb_gregset_t *) gregset, -1);
@@ -862,9 +861,8 @@ ps_lsetregs (struct ps_prochandle *ph, lwpid_t lwpid,
             const prgregset_t gregset)
 {
   ptid_t ptid = ptid_t (current_inferior ()->pid, lwpid, 0);
-  struct regcache *regcache
-    = get_thread_arch_regcache (current_inferior ()->process_target (),
-                               ptid, current_inferior ()->arch ());
+  regcache *regcache = get_thread_arch_regcache (current_inferior (), ptid,
+                                                current_inferior ()->arch ());
 
   supply_gregset (regcache, (const gdb_gregset_t *) gregset);
   target_store_registers (regcache, -1);
@@ -915,9 +913,8 @@ ps_lgetfpregs (struct ps_prochandle *ph, lwpid_t lwpid,
               prfpregset_t *fpregset)
 {
   ptid_t ptid = ptid_t (current_inferior ()->pid, lwpid, 0);
-  struct regcache *regcache
-    = get_thread_arch_regcache (current_inferior ()->process_target (),
-                               ptid, current_inferior ()->arch ());
+  regcache *regcache = get_thread_arch_regcache (current_inferior (), ptid,
+                                                current_inferior ()->arch ());
 
   target_fetch_registers (regcache, -1);
   fill_fpregset (regcache, (gdb_fpregset_t *) fpregset, -1);
@@ -932,9 +929,8 @@ ps_lsetfpregs (struct ps_prochandle *ph, lwpid_t lwpid,
               const prfpregset_t * fpregset)
 {
   ptid_t ptid = ptid_t (current_inferior ()->pid, lwpid, 0);
-  struct regcache *regcache
-    = get_thread_arch_regcache (current_inferior ()->process_target (),
-                               ptid, current_inferior ()->arch ());
+  regcache *regcache = get_thread_arch_regcache (current_inferior (), ptid,
+                                                current_inferior ()->arch ());
 
   supply_fpregset (regcache, (const gdb_fpregset_t *) fpregset);
   target_store_registers (regcache, -1);
index e21190a30f159cc696fcd1320f76c7c3026acc44..b02e8094ac6b25d54524c0a98ca2f7354e95dd16 100644 (file)
@@ -2399,9 +2399,8 @@ enable_break (struct svr4_info *info, int from_tty)
         most cases.  */
       if (!load_addr_found)
        {
-         struct regcache *regcache
-           = get_thread_arch_regcache (current_inferior ()->process_target (),
-                                       inferior_ptid,
+         regcache *regcache
+           = get_thread_arch_regcache (current_inferior (), inferior_ptid,
                                        current_inferior ()->arch ());
 
          load_addr = (regcache_read_pc (regcache)
index a27b66df10001e7b034e1817043f5d80139f1028..4c499fac55c422322a5e6c46895eadf996f925fb 100644 (file)
@@ -134,7 +134,6 @@ struct dummy_target : public target_ops
   void dumpcore (const char *arg0) override;
   bool can_run_breakpoint_commands () override;
   struct gdbarch *thread_architecture (ptid_t arg0) override;
-  struct address_space *thread_address_space (ptid_t arg0) override;
   bool filesystem_is_local () override;
   void trace_init () override;
   void download_tracepoint (struct bp_location *arg0) override;
@@ -311,7 +310,6 @@ struct debug_target : public target_ops
   void dumpcore (const char *arg0) override;
   bool can_run_breakpoint_commands () override;
   struct gdbarch *thread_architecture (ptid_t arg0) override;
-  struct address_space *thread_address_space (ptid_t arg0) override;
   bool filesystem_is_local () override;
   void trace_init () override;
   void download_tracepoint (struct bp_location *arg0) override;
@@ -3014,32 +3012,6 @@ debug_target::thread_architecture (ptid_t arg0)
   return result;
 }
 
-struct address_space *
-target_ops::thread_address_space (ptid_t arg0)
-{
-  return this->beneath ()->thread_address_space (arg0);
-}
-
-struct address_space *
-dummy_target::thread_address_space (ptid_t arg0)
-{
-  return NULL;
-}
-
-struct address_space *
-debug_target::thread_address_space (ptid_t arg0)
-{
-  gdb_printf (gdb_stdlog, "-> %s->thread_address_space (...)\n", this->beneath ()->shortname ());
-  struct address_space * result
-    = this->beneath ()->thread_address_space (arg0);
-  gdb_printf (gdb_stdlog, "<- %s->thread_address_space (", this->beneath ()->shortname ());
-  target_debug_print_ptid_t (arg0);
-  gdb_puts (") = ", gdb_stdlog);
-  target_debug_print_address_space_p (result);
-  gdb_puts ("\n", gdb_stdlog);
-  return result;
-}
-
 bool
 target_ops::filesystem_is_local ()
 {
index a6ca7fc4f0779f705bddb54952a9ef621de74aa1..a93740bbbddd227a4ebe4665c229dd3a373c4ec3 100644 (file)
@@ -2999,19 +2999,6 @@ target_get_osdata (const char *type)
   return target_read_stralloc (t, TARGET_OBJECT_OSDATA, type);
 }
 
-/* Determine the current address space of thread PTID.  */
-
-struct address_space *
-target_thread_address_space (ptid_t ptid)
-{
-  struct address_space *aspace;
-
-  aspace = current_inferior ()->top_target ()->thread_address_space (ptid);
-  gdb_assert (aspace != NULL);
-
-  return aspace;
-}
-
 /* See target.h.  */
 
 target_ops *
index 558be4637554b477929e7e1c67da2b06a100b48b..fca0bbbf66e29c137cbb89751841105138c78653 100644 (file)
@@ -949,10 +949,6 @@ struct target_ops
     virtual struct gdbarch *thread_architecture (ptid_t)
       TARGET_DEFAULT_RETURN (NULL);
 
-    /* Determine current address space of thread PTID.  */
-    virtual struct address_space *thread_address_space (ptid_t)
-      TARGET_DEFAULT_RETURN (NULL);
-
     /* Target file operations.  */
 
     /* Return true if the filesystem seen by the current inferior
@@ -1544,10 +1540,6 @@ extern void target_store_registers (struct regcache *regcache, int regs);
 
 extern void target_prepare_to_store (regcache *regcache);
 
-/* Determine current address space of thread PTID.  */
-
-struct address_space *target_thread_address_space (ptid_t);
-
 /* Implement the "info proc" command.  This returns one if the request
    was handled, and zero otherwise.  It can also throw an exception if
    an error was encountered while attempting to handle the