Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH v2 1/3] Don't allocate mapped_index on the objfile obstack
Date: Sat, 28 Apr 2018 03:31:00 -0000	[thread overview]
Message-ID: <20180428033121.20163-2-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20180428033121.20163-1-simon.marchi@polymtl.ca>

To make things simpler, allocate it with new and manage its lifetime
using a unique_ptr (just like mapped_debug_names).  We can also
std::move the temporary local_map in the permanent map.

gdb/ChangeLog;

	* dwarf2read.h (struct dwarf2_per_objfile) <index_table>: Change
	type to std::unique_ptr.
	* dwarf2read.c (dwarf2_per_objfile::~dwarf2_per_objfile): Don't
	manually destroy mapped_index.
	(dwarf2_read_index): Adjust for unique_ptr, use std::move.
	(dw2_symtab_iter_init): Adjust for unique_ptr.
---
 gdb/dwarf2read.c | 14 ++++----------
 gdb/dwarf2read.h |  2 +-
 2 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 9eb98b2eab8e..b3bcb43a519b 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -2153,9 +2153,6 @@ dwarf2_per_objfile::~dwarf2_per_objfile ()
   if (dwz_file != NULL && dwz_file->dwz_bfd)
     gdb_bfd_unref (dwz_file->dwz_bfd);
 
-  if (index_table != NULL)
-    index_table->~mapped_index ();
-
   /* Everything else should be on the objfile obstack.  */
 }
 
@@ -3541,7 +3538,7 @@ to use the section anyway."),
 static int
 dwarf2_read_index (struct dwarf2_per_objfile *dwarf2_per_objfile)
 {
-  struct mapped_index local_map, *map;
+  struct mapped_index local_map;
   const gdb_byte *cu_list, *types_list, *dwz_list = NULL;
   offset_type cu_list_elements, types_list_elements, dwz_list_elements = 0;
   struct dwz_file *dwz;
@@ -3601,11 +3598,8 @@ dwarf2_read_index (struct dwarf2_per_objfile *dwarf2_per_objfile)
 
   create_addrmap_from_index (dwarf2_per_objfile, &local_map);
 
-  map = XOBNEW (&objfile->objfile_obstack, struct mapped_index);
-  map = new (map) mapped_index ();
-  *map = local_map;
-
-  dwarf2_per_objfile->index_table = map;
+  dwarf2_per_objfile->index_table.reset (new mapped_index);
+  *dwarf2_per_objfile->index_table = std::move (local_map);
   dwarf2_per_objfile->using_index = 1;
   dwarf2_per_objfile->quick_file_names_table =
     create_quick_file_names_table (dwarf2_per_objfile->all_comp_units.size ());
@@ -3920,7 +3914,7 @@ dw2_symtab_iter_init (struct dw2_symtab_iterator *iter,
   iter->next = 0;
   iter->global_seen = 0;
 
-  mapped_index *index = dwarf2_per_objfile->index_table;
+  mapped_index *index = dwarf2_per_objfile->index_table.get ();
 
   /* index is NULL if OBJF_READNOW.  */
   if (index != NULL && find_slot_in_mapped_hash (index, name, &iter->vec))
diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h
index 8e6c41dc09ef..f36d039e7bea 100644
--- a/gdb/dwarf2read.h
+++ b/gdb/dwarf2read.h
@@ -209,7 +209,7 @@ public:
   bool using_index = false;
 
   /* The mapped index, or NULL if .gdb_index is missing or not being used.  */
-  mapped_index *index_table = NULL;
+  std::unique_ptr<mapped_index> index_table;
 
   /* The mapped index, or NULL if .debug_names is missing or not being used.  */
   std::unique_ptr<mapped_debug_names> debug_names_table;
-- 
2.17.0


  parent reply	other threads:[~2018-04-28  3:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-28  3:31 [PATCH v2 0/3] Poison obstack functions Simon Marchi
2018-04-28  3:31 ` [PATCH v2 2/3] Introduce obstack_new, poison other "typed" " Simon Marchi
2018-04-28  3:31 ` Simon Marchi [this message]
2018-04-28  3:31 ` [PATCH v2 3/3] Use XOBNEW/XOBNEWVEC/OBSTACK_ZALLOC when possible Simon Marchi
2018-05-21  3:00 ` [PATCH v2 0/3] Poison obstack functions Simon Marchi
2018-05-21  3:23   ` Simon Marchi
2018-05-21  8:53     ` [pushed] Fix copy-pasto, allocate objfile_per_bfd_storage with obstack_new 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=20180428033121.20163-2-simon.marchi@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --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