public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 08/24] gdb: allocate so_list with new, deallocate with delete
Date: Tue, 10 Oct 2023 16:40:03 -0400	[thread overview]
Message-ID: <20231010204213.111285-9-simon.marchi@efficios.com> (raw)
In-Reply-To: <20231010204213.111285-1-simon.marchi@efficios.com>

Initialize all fields in the class declaration, change allocations to
use "new", change deallocations to use "delete".  This is needed by a
subsequent patches that use C++ stuff in so_list.

Change-Id: I4b140d9f1ec9ff809554a056f76e3eb2b9e23222
---
 gdb/solib-aix.c    |  2 +-
 gdb/solib-darwin.c |  9 +++++----
 gdb/solib-dsbt.c   |  3 +--
 gdb/solib-frv.c    |  3 +--
 gdb/solib-rocm.c   |  6 ++----
 gdb/solib-svr4.c   | 13 ++++---------
 gdb/solib-target.c |  4 ++--
 gdb/solib.c        |  2 +-
 gdb/solist.h       | 18 +++++++++---------
 9 files changed, 26 insertions(+), 34 deletions(-)

diff --git a/gdb/solib-aix.c b/gdb/solib-aix.c
index cfcc04db1518..515d9d62704a 100644
--- a/gdb/solib-aix.c
+++ b/gdb/solib-aix.c
@@ -473,7 +473,7 @@ solib_aix_current_sos (void)
      to the main executable, not a shared library.  */
   for (ix = 1; ix < library_list->size (); ix++)
     {
-      struct so_list *new_solib = XCNEW (struct so_list);
+      so_list *new_solib = new so_list;
       std::string so_name;
 
       lm_info_aix &info = (*library_list)[ix];
diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
index 5720f997bef7..c2f250ae705c 100644
--- a/gdb/solib-darwin.c
+++ b/gdb/solib-darwin.c
@@ -273,7 +273,7 @@ darwin_current_sos (void)
 	break;
 
       /* Create and fill the new so_list element.  */
-      gdb::unique_xmalloc_ptr<struct so_list> newobj (XCNEW (struct so_list));
+      so_list *newobj = new so_list;
 
       lm_info_darwin *li = new lm_info_darwin;
       newobj->lm_info = li;
@@ -284,10 +284,11 @@ darwin_current_sos (void)
       li->lm_addr = load_addr;
 
       if (head == NULL)
-	head = newobj.get ();
+	head = newobj;
       else
-	tail->next = newobj.get ();
-      tail = newobj.release ();
+	tail->next = newobj;
+
+      tail = newobj;
     }
 
   return head;
diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
index 60a211ee6e6e..dd0c8e47d086 100644
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -584,7 +584,6 @@ dsbt_current_sos (void)
       if (dsbt_index != 0)
 	{
 	  struct int_elf32_dsbt_loadmap *loadmap;
-	  struct so_list *sop;
 	  CORE_ADDR addr;
 
 	  loadmap = fetch_loadmap (map_addr);
@@ -595,7 +594,7 @@ dsbt_current_sos (void)
 	      break;
 	    }
 
-	  sop = XCNEW (struct so_list);
+	  so_list *sop = new so_list;
 	  lm_info_dsbt *li = new lm_info_dsbt;
 	  sop->lm_info = li;
 	  li->map = loadmap;
diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c
index c895eb20e434..f823aca57fa0 100644
--- a/gdb/solib-frv.c
+++ b/gdb/solib-frv.c
@@ -363,7 +363,6 @@ frv_current_sos (void)
       if (got_addr != mgot)
 	{
 	  struct int_elf32_fdpic_loadmap *loadmap;
-	  struct so_list *sop;
 	  CORE_ADDR addr;
 
 	  /* Fetch the load map address.  */
@@ -378,7 +377,7 @@ frv_current_sos (void)
 	      break;
 	    }
 
-	  sop = XCNEW (struct so_list);
+	  so_list *sop = new so_list;
 	  lm_info_frv *li = new lm_info_frv;
 	  sop->lm_info = li;
 	  li->map = loadmap;
diff --git a/gdb/solib-rocm.c b/gdb/solib-rocm.c
index 65dd1c06271f..e46d272b3339 100644
--- a/gdb/solib-rocm.c
+++ b/gdb/solib-rocm.c
@@ -217,9 +217,7 @@ rocm_solib_copy_list (const so_list *src)
 
   while (src != nullptr)
     {
-      struct so_list *newobj;
-
-      newobj = XNEW (struct so_list);
+      so_list *newobj = new so_list;
       memcpy (newobj, src, sizeof (struct so_list));
 
       lm_info_svr4 *src_li = (lm_info_svr4 *) src->lm_info;
@@ -738,7 +736,7 @@ rocm_update_solib_list ()
       if (status != AMD_DBGAPI_STATUS_SUCCESS)
 	continue;
 
-      struct so_list *so = XCNEW (struct so_list);
+      so_list *so = new so_list;
       lm_info_svr4 *li = new lm_info_svr4;
       li->l_addr = l_addr;
       so->lm_info = li;
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index b32848944cad..6fae926d5e62 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -1021,9 +1021,7 @@ svr4_copy_library_list (struct so_list *src)
 
   while (src != NULL)
     {
-      struct so_list *newobj;
-
-      newobj = XNEW (struct so_list);
+      so_list *newobj = new so_list;
       memcpy (newobj, src, sizeof (struct so_list));
 
       lm_info_svr4 *src_li = (lm_info_svr4 *) src->lm_info;
@@ -1061,9 +1059,8 @@ library_list_start_library (struct gdb_xml_parser *parser,
     = (ULONGEST *) xml_find_attribute (attributes, "l_addr")->value.get ();
   ULONGEST *l_ldp
     = (ULONGEST *) xml_find_attribute (attributes, "l_ld")->value.get ();
-  struct so_list *new_elem;
 
-  new_elem = XCNEW (struct so_list);
+  so_list *new_elem = new so_list;
   lm_info_svr4 *li = new lm_info_svr4;
   new_elem->lm_info = li;
   li->lm_addr = *lmp;
@@ -1246,12 +1243,10 @@ svr4_current_sos_via_xfer_libraries (struct svr4_library_list *list,
 static struct so_list *
 svr4_default_sos (svr4_info *info)
 {
-  struct so_list *newobj;
-
   if (!info->debug_loader_offset_p)
     return NULL;
 
-  newobj = XCNEW (struct so_list);
+  so_list *newobj = new so_list;
   lm_info_svr4 *li = new lm_info_svr4;
   newobj->lm_info = li;
 
@@ -1283,7 +1278,7 @@ svr4_read_so_list (svr4_info *info, CORE_ADDR lm, CORE_ADDR prev_lm,
 
   for (; lm != 0; prev_lm = lm, lm = next_lm)
     {
-      so_list_up newobj (XCNEW (struct so_list));
+      so_list_up newobj (new so_list);
 
       lm_info_svr4 *li = lm_info_read (lm).release ();
       newobj->lm_info = li;
diff --git a/gdb/solib-target.c b/gdb/solib-target.c
index b8b6dd644018..d2459b5dc81b 100644
--- a/gdb/solib-target.c
+++ b/gdb/solib-target.c
@@ -230,7 +230,7 @@ solib_target_parse_libraries (const char *library)
 static struct so_list *
 solib_target_current_sos (void)
 {
-  struct so_list *new_solib, *start = NULL, *last = NULL;
+  so_list *start = NULL, *last = NULL;
 
   /* Fetch the list of shared libraries.  */
   gdb::optional<gdb::char_vector> library_document
@@ -249,7 +249,7 @@ solib_target_current_sos (void)
   /* Build a struct so_list for each entry on the list.  */
   for (auto &&info : library_list)
     {
-      new_solib = XCNEW (struct so_list);
+      so_list *new_solib = new so_list;
       strncpy (new_solib->so_name, info->name.c_str (),
 	       SO_NAME_MAX_PATH_SIZE - 1);
       new_solib->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
diff --git a/gdb/solib.c b/gdb/solib.c
index 32f9aa7397c0..816dacb31829 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -677,7 +677,7 @@ free_so (so_list &so)
   clear_so (so);
   ops->free_so (so);
 
-  xfree (&so);
+  delete &so;
 }
 
 
diff --git a/gdb/solist.h b/gdb/solist.h
index 5d648900d29d..8b80ed4a6cc7 100644
--- a/gdb/solist.h
+++ b/gdb/solist.h
@@ -37,23 +37,23 @@ struct so_list
      dynamic linker's tables in the inferior, and are initialized by
      current_sos.  */
 
-  struct so_list *next;	/* next structure in linked list */
+  struct so_list *next = nullptr;	/* next structure in linked list */
 
   /* A pointer to target specific link map information.  Often this
      will be a copy of struct link_map from the user process, but
      it need not be; it can be any collection of data needed to
      traverse the dynamic linker's data structures.  */
-  lm_info_base *lm_info;
+  lm_info_base *lm_info = nullptr;
 
   /* Shared object file name, exactly as it appears in the
      inferior's link map.  This may be a relative path, or something
      which needs to be looked up in LD_LIBRARY_PATH, etc.  We use it
      to tell which entries in the inferior's dynamic linker's link
      map we've already loaded.  */
-  char so_original_name[SO_NAME_MAX_PATH_SIZE];
+  char so_original_name[SO_NAME_MAX_PATH_SIZE] {};
 
   /* Shared object file name, expanded to something GDB can open.  */
-  char so_name[SO_NAME_MAX_PATH_SIZE];
+  char so_name[SO_NAME_MAX_PATH_SIZE] {};
 
   /* The following fields of the structure are built from
      information gathered from the shared object file itself, and
@@ -61,15 +61,15 @@ struct so_list
 
      current_sos must initialize these fields to 0.  */
 
-  bfd *abfd;
-  char symbols_loaded;	/* flag: symbols read in yet?  */
+  bfd *abfd = nullptr;
+  char symbols_loaded = 0;	/* flag: symbols read in yet?  */
 
   /* objfile with symbols for a loaded library.  Target memory is read from
      ABFD.  OBJFILE may be NULL either before symbols have been loaded, if
      the file cannot be found or after the command "nosharedlibrary".  */
-  struct objfile *objfile;
+  struct objfile *objfile = nullptr;
 
-  target_section_table *sections;
+  target_section_table *sections = nullptr;
 
   /* Record the range of addresses belonging to this shared library.
      There may not be just one (e.g. if two segments are relocated
@@ -77,7 +77,7 @@ struct so_list
      the MI command "-file-list-shared-libraries".  The latter has a format
      that supports outputting multiple segments once the related code
      supports them.  */
-  CORE_ADDR addr_low, addr_high;
+  CORE_ADDR addr_low = 0, addr_high = 0;
 };
 
 struct target_so_ops
-- 
2.42.0


  parent reply	other threads:[~2023-10-10 20:44 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-10 20:39 [PATCH 00/24] C++ification of struct so_list Simon Marchi
2023-10-10 20:39 ` [PATCH 01/24] gdb: remove empty clear_solib functions Simon Marchi
2023-10-10 20:39 ` [PATCH 02/24] gdb: add program_space parameter to target_so_ops::clear_solib Simon Marchi
2023-10-17 14:57   ` Pedro Alves
2023-10-17 15:19     ` Simon Marchi
2023-10-10 20:39 ` [PATCH 03/24] gdb: make interps_notify work with references Simon Marchi
2023-10-11  8:48   ` Lancelot SIX
2023-10-11 14:18     ` Simon Marchi
2023-10-10 20:39 ` [PATCH 04/24] gdb: replace some so_list parameters to use references Simon Marchi
2023-10-19 11:07   ` [PATCH 4/24] " Lancelot SIX
2023-10-19 14:49     ` Simon Marchi
2023-10-19 15:20       ` Lancelot SIX
2023-10-19 16:07         ` Simon Marchi
2023-10-10 20:40 ` [PATCH 05/24] gdbsupport: use "reference" and "pointer" type aliases in intrusive_list Simon Marchi
2023-10-10 20:40 ` [PATCH 06/24] gdbsupport: make intrusive_list's disposer accept a reference Simon Marchi
2023-10-12 19:05   ` Pedro Alves
2023-10-14 20:12     ` Simon Marchi
2023-10-10 20:40 ` [PATCH 07/24] gdb: make get_cbfd_soname_build_id static Simon Marchi
2023-10-10 20:40 ` Simon Marchi [this message]
2023-10-10 20:40 ` [PATCH 09/24] gdb: rename lm_info_base to lm_info Simon Marchi
2023-10-10 20:40 ` [PATCH 10/24] gdb: remove target_so_ops::free_so Simon Marchi
2023-10-10 20:40 ` [PATCH 11/24] gdb: use gdb::checked_static_cast when casting lm_info Simon Marchi
2023-10-10 20:40 ` [PATCH 12/24] gdb: make solib-svr4 not use so_list internally Simon Marchi
2023-10-13 17:52   ` Lancelot SIX
2023-10-14 19:59     ` Simon Marchi
2023-10-19 11:08   ` Lancelot SIX
2023-10-19 14:50     ` Simon Marchi
2023-10-10 20:40 ` [PATCH 13/24] gdb: make solib-rocm " Simon Marchi
2023-10-13 18:35   ` Lancelot SIX
2023-10-14 20:00     ` Simon Marchi
2023-10-17 15:23   ` Pedro Alves
2023-10-17 15:32     ` Simon Marchi
2023-10-10 20:40 ` [PATCH 14/24] gdb: remove lm_info_vector typedef Simon Marchi
2023-10-10 20:40 ` [PATCH 15/24] gdb: make so_list::lm_info a unique_ptr Simon Marchi
2023-10-10 20:40 ` [PATCH 16/24] gdb: make clear_so a method of struct so_list Simon Marchi
2023-10-19 11:08   ` Lancelot SIX
2023-10-19 14:52     ` Simon Marchi
2023-10-10 20:40 ` [PATCH 17/24] gdb: remove target_section_table typedef Simon Marchi
2023-10-10 20:40 ` [PATCH 18/24] gdb: make so_list::sections not a pointer Simon Marchi
2023-10-10 20:40 ` [PATCH 19/24] gdb: make so_list::abfd a gdb_bfd_ref_ptr Simon Marchi
2023-10-10 20:40 ` [PATCH 20/24] gdb: make so_list::{so_original_name,so_name} std::strings Simon Marchi
2023-10-13 22:28   ` [PATCH 20/24] gdb: make so_list::{so_original_name, so_name} std::strings Lancelot SIX
2023-10-14 20:01     ` Simon Marchi
2023-10-19 11:08   ` [PATCH 20/24] gdb: make so_list::{so_original_name,so_name} std::strings Lancelot SIX
2023-10-19 14:55     ` Simon Marchi
2023-10-10 20:40 ` [PATCH 21/24] gdb: link so_list using intrusive_list Simon Marchi
2023-10-17 19:14   ` Pedro Alves
2023-10-17 19:38     ` Simon Marchi
2023-10-10 20:40 ` [PATCH 22/24] gdb: don't call so_list::clear in free_so Simon Marchi
2023-10-10 20:40 ` [PATCH 23/24] gdb: remove free_so function Simon Marchi
2023-10-10 20:49 ` [PATCH 24/24] gdb: rename struct so_list to so Simon Marchi
2023-10-17 19:20 ` [PATCH 00/24] C++ification of struct so_list Pedro Alves
2023-10-17 19:53   ` Simon Marchi
2023-10-20 14:40     ` Pedro Alves
2023-10-19 11:09 ` [PATCH 0/24] " Lancelot SIX
2023-10-19 14:57   ` Simon Marchi

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=20231010204213.111285-9-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@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).