gdb: remove address space numbers

Message ID 20231117210138.10925-1-simon.marchi@efficios.com
State New
Headers
Series gdb: remove address space numbers |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed

Commit Message

Simon Marchi Nov. 17, 2023, 9:01 p.m. UTC
  highest_address_space_num is reset when connecting to a remote target
(init_address_spaces is called by update_address_spaces, which is called
by remote_target::start_remote_1).  This can result in potentially
non-unique address space numbers if, let's say, you connect to a remote
target while already debugging something natively.  The address space
number concept is not used, except when printing an address space in
target-debug.h.  A fix would be to make the highest_address_space_num
counter per-process target, or just never reset the counter.  But since
it's not useful, I think it's better just to remove it, and rely on the
pointer value if we need a unique identifier, since that simplifies the
code.

Change-Id: I643f3a070e29c7bc12a2e874219b522a1ddad252
---
 gdb/progspace.c    | 24 ------------------------
 gdb/progspace.h    | 12 +-----------
 gdb/target-debug.h |  2 +-
 3 files changed, 2 insertions(+), 36 deletions(-)


base-commit: 413366203156a0483d06a97b3f02b64ba6a215cc
  

Patch

diff --git a/gdb/progspace.c b/gdb/progspace.c
index 839707e9d71f..517677ad1a7a 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -39,18 +39,6 @@  std::vector<struct program_space *> program_spaces;
 /* Pointer to the current program space.  */
 struct program_space *current_program_space;
 
-/* The last address space number assigned.  */
-static int highest_address_space_num;
-
-
-
-/* Create a new address space object, and add it to the list.  */
-
-address_space::address_space ()
-  : m_num (++highest_address_space_num)
-{
-}
-
 /* Maybe create a new address space object, and add it to the list, or
    return a pointer to an existing address space, in case inferiors
    share an address space on this target system.  */
@@ -70,16 +58,6 @@  maybe_new_address_space (void)
   return new address_space ();
 }
 
-/* Start counting over from scratch.  */
-
-static void
-init_address_spaces (void)
-{
-  highest_address_space_num = 0;
-}
-
-
-
 /* Remove a program space from the program spaces list.  */
 
 static void
@@ -407,8 +385,6 @@  update_address_spaces (void)
   int shared_aspace
     = gdbarch_has_shared_address_space (current_inferior ()->arch ());
 
-  init_address_spaces ();
-
   if (shared_aspace)
     {
       struct address_space *aspace = new address_space ();
diff --git a/gdb/progspace.h b/gdb/progspace.h
index a22e427400e9..0e3cefd66400 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -386,21 +386,11 @@  struct program_space
    associating caches to each address space.  */
 struct address_space
 {
-  /* Create a new address space object, and add it to the list.  */
-  address_space ();
+  address_space () = default;
   DISABLE_COPY_AND_ASSIGN (address_space);
 
-  /* Returns the integer address space id of this address space.  */
-  int num () const
-  {
-    return m_num;
-  }
-
   /* Per aspace data-pointers required by other GDB modules.  */
   registry<address_space> registry_fields;
-
-private:
-  int m_num;
 };
 
 /* The list of all program spaces.  There's always at least one.  */
diff --git a/gdb/target-debug.h b/gdb/target-debug.h
index 431f99ed3b1d..15977c0901d6 100644
--- a/gdb/target-debug.h
+++ b/gdb/target-debug.h
@@ -89,7 +89,7 @@ 
 #define target_debug_print_LONGEST_p(X)		\
   target_debug_do_print (phex (*(X), 0))
 #define target_debug_print_address_space_p(X)	\
-  target_debug_do_print (plongest ((X)->num ()))
+  target_debug_do_print (host_address_to_string (X))
 #define target_debug_print_bp_target_info_p(X)	\
   target_debug_do_print (core_addr_to_string ((X)->placed_address))
 #define target_debug_print_expression_p(X)	\