public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Tom Tromey <tromey@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] Change address_space to use new and delete
Date: Thu, 28 Jul 2022 20:44:01 +0000 (GMT)	[thread overview]
Message-ID: <20220728204401.9D4FE3858D33@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b382c16682acc33d2e81e5604c9dbd408be376d2

commit b382c16682acc33d2e81e5604c9dbd408be376d2
Author: Tom Tromey <tom@tromey.com>
Date:   Sun Oct 18 10:47:48 2020 -0600

    Change address_space to use new and delete
    
    This changes address_space to use new and delete, and makes some other
    small C++-ification changes as well, like changing address_space_num
    to be a method.
    
    This patch was needed for the subsequent patch to rewrite the registry
    system.

Diff:
---
 gdb/infrun.c              |  6 +++---
 gdb/progspace.c           | 38 ++++++++++++--------------------------
 gdb/progspace.h           | 22 ++++++++++++++--------
 gdb/scoped-mock-context.h |  2 +-
 gdb/target-debug.h        |  2 +-
 5 files changed, 31 insertions(+), 39 deletions(-)

diff --git a/gdb/infrun.c b/gdb/infrun.c
index 543cccc5311..033699bc3f7 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -501,7 +501,7 @@ holding the child stopped.  Try \"set detach-on-fork\" or \
 	    }
 	  else
 	    {
-	      child_inf->aspace = new_address_space ();
+	      child_inf->aspace = new address_space ();
 	      child_inf->pspace = new program_space (child_inf->aspace);
 	      child_inf->removable = 1;
 	      clone_program_space (child_inf->pspace, parent_inf->pspace);
@@ -573,7 +573,7 @@ holding the child stopped.  Try \"set detach-on-fork\" or \
 
 	  child_inf->aspace = parent_inf->aspace;
 	  child_inf->pspace = parent_inf->pspace;
-	  parent_inf->aspace = new_address_space ();
+	  parent_inf->aspace = new address_space ();
 	  parent_inf->pspace = new program_space (parent_inf->aspace);
 	  clone_program_space (parent_inf->pspace, child_inf->pspace);
 
@@ -583,7 +583,7 @@ holding the child stopped.  Try \"set detach-on-fork\" or \
 	}
       else
 	{
-	  child_inf->aspace = new_address_space ();
+	  child_inf->aspace = new address_space ();
 	  child_inf->pspace = new program_space (child_inf->aspace);
 	  child_inf->removable = 1;
 	  child_inf->symfile_flags = SYMFILE_NO_READ;
diff --git a/gdb/progspace.c b/gdb/progspace.c
index 8735343fabc..c2e2da5a7dc 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -57,16 +57,10 @@ DEFINE_REGISTRY (address_space, REGISTRY_ACCESS_FIELD)
 
 /* Create a new address space object, and add it to the list.  */
 
-struct address_space *
-new_address_space (void)
+address_space::address_space ()
+  : m_num (++highest_address_space_num)
 {
-  struct address_space *aspace;
-
-  aspace = XCNEW (struct address_space);
-  aspace->num = ++highest_address_space_num;
-  address_space_alloc_data (aspace);
-
-  return aspace;
+  address_space_alloc_data (this);
 }
 
 /* Maybe create a new address space object, and add it to the list, or
@@ -84,20 +78,12 @@ maybe_new_address_space (void)
       return program_spaces[0]->aspace;
     }
 
-  return new_address_space ();
-}
-
-static void
-free_address_space (struct address_space *aspace)
-{
-  address_space_free_data (aspace);
-  xfree (aspace);
+  return new address_space ();
 }
 
-int
-address_space_num (struct address_space *aspace)
+address_space::~address_space ()
 {
-  return aspace->num;
+  address_space_free_data (this);
 }
 
 /* Start counting over from scratch.  */
@@ -153,7 +139,7 @@ program_space::~program_space ()
      locations for this pspace which we're tearing down.  */
   clear_symtab_users (SYMFILE_DEFER_BP_RESET);
   if (!gdbarch_has_shared_address_space (target_gdbarch ()))
-    free_address_space (this->aspace);
+    delete this->aspace;
     /* Discard any data modules have associated with the PSPACE.  */
   program_space_free_data (this);
 }
@@ -411,17 +397,17 @@ update_address_spaces (void)
 
   if (shared_aspace)
     {
-      struct address_space *aspace = new_address_space ();
+      struct address_space *aspace = new address_space ();
 
-      free_address_space (current_program_space->aspace);
+      delete current_program_space->aspace;
       for (struct program_space *pspace : program_spaces)
 	pspace->aspace = aspace;
     }
   else
     for (struct program_space *pspace : program_spaces)
       {
-	free_address_space (pspace->aspace);
-	pspace->aspace = new_address_space ();
+	delete pspace->aspace;
+	pspace->aspace = new address_space ();
       }
 
   for (inferior *inf : all_inferiors ())
@@ -459,5 +445,5 @@ initialize_progspace (void)
      modules have done that.  Do this before
      initialize_current_architecture, because that accesses the ebfd
      of current_program_space.  */
-  current_program_space = new program_space (new_address_space ());
+  current_program_space = new program_space (new address_space ());
 }
diff --git a/gdb/progspace.h b/gdb/progspace.h
index 662e569488e..8531da4a095 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -385,10 +385,22 @@ private:
    associating caches to each address space.  */
 struct address_space
 {
-  int num;
+  /* Create a new address space object, and add it to the list.  */
+  address_space ();
+  ~address_space ();
+  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_FIELDS;
+  REGISTRY_FIELDS {};
+
+private:
+  int m_num;
 };
 
 /* The list of all program spaces.  There's always at least one.  */
@@ -430,17 +442,11 @@ private:
   program_space *m_saved_pspace;
 };
 
-/* Create a new address space object, and add it to the list.  */
-extern struct address_space *new_address_space (void);
-
 /* 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.  */
 extern struct address_space *maybe_new_address_space (void);
 
-/* Returns the integer address space id of ASPACE.  */
-extern int address_space_num (struct address_space *aspace);
-
 /* Update all program spaces matching to address spaces.  The user may
    have created several program spaces, and loaded executables into
    them before connecting to the target interface that will create the
diff --git a/gdb/scoped-mock-context.h b/gdb/scoped-mock-context.h
index b91d43b1716..a9895303015 100644
--- a/gdb/scoped-mock-context.h
+++ b/gdb/scoped-mock-context.h
@@ -38,7 +38,7 @@ struct scoped_mock_context
 
   Target mock_target;
   ptid_t mock_ptid {1, 1};
-  program_space mock_pspace {new_address_space ()};
+  program_space mock_pspace {new address_space ()};
   inferior mock_inferior {mock_ptid.pid ()};
   thread_info mock_thread {&mock_inferior, mock_ptid};
 
diff --git a/gdb/target-debug.h b/gdb/target-debug.h
index c2b1db1ce8e..ab89c0a5185 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_struct_address_space_p(X)	\
-  target_debug_do_print (plongest (address_space_num (X)))
+  target_debug_do_print (plongest ((X)->num ()))
 #define target_debug_print_struct_bp_target_info_p(X)	\
   target_debug_do_print (core_addr_to_string ((X)->placed_address))
 #define target_debug_print_struct_expression_p(X)	\


                 reply	other threads:[~2022-07-28 20:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220728204401.9D4FE3858D33@sourceware.org \
    --to=tromey@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).