public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Yao Qi <qiyaoltc@gmail.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 4/7] Class-fy partial_die_info
Date: Fri, 26 Jan 2018 17:25:00 -0000	[thread overview]
Message-ID: <86lggkcz1x.fsf@gmail.com> (raw)
In-Reply-To: <87vafphpw6.fsf@tromey.com> (Tom Tromey's message of "Thu, 25 Jan	2018 09:19:53 -0700")

Tom Tromey <tom@tromey.com> writes:

> I wonder if it would make sense to have an "operator new" implementation
> that allocates directly on an obstack.  It could use

Yes, we can have an "operator new",

> std::is_trivially_destructible to enforce the rule that objects on an
> obstack can't really be destroyed.  This would eliminate the separate
> XOBNEW, which is maybe a potential source of errors; and would also make
> it harder to accidentally add a destructor to objects allocated this way

but why dtor must be trivial?  We can have "operator new" and "operator
delete", the former allocate spaces on obstack and the latter doesn't
de-allocate space.  It doesn't matter dtor is trivial or not.  I may
miss something here.

Further, I think IWBN to have a  class which has new/delete operator,
and other classes can inherit it.  What do you think the patch below?

-- 
Yao (齐尧)
From 9f20b2690cd1c83a3bdcd41ea59f07dfef0da522 Mon Sep 17 00:00:00 2001
From: Yao Qi <yao.qi@linaro.org>
Date: Fri, 26 Jan 2018 11:57:34 +0000
Subject: [PATCH] New class allocate_on_obstack

This patch adds a new class allocate_on_obstack, and let dwarf2_per_objfile
inherit it, so that dwarf2_per_objfile is automatically allocated on
obstack, and "delete dwarf2_per_objfile" doesn't de-allocate any space.

gdb:

2018-01-26  Yao Qi  <yao.qi@linaro.org>

	* dwarf2read.c (dwarf2_per_objfile): Inherit allocate_on_obstack.
	(dwarf2_free_objfile): Use delete.
	* gdb_obstack.h (allocate_on_obstack): New.

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 96026a8..5c45bdf 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -380,7 +380,7 @@ struct tu_stats
 /* Collection of data recorded per objfile.
    This hangs off of dwarf2_objfile_data_key.  */
 
-struct dwarf2_per_objfile
+struct dwarf2_per_objfile : public allocate_on_obstack
 {
   /* Construct a dwarf2_per_objfile for OBJFILE.  NAMES points to the
      dwarf2 section names, or is NULL if the standard ELF names are
@@ -2467,10 +2467,9 @@ dwarf2_has_info (struct objfile *objfile,
   if (dwarf2_per_objfile == NULL)
     {
       /* Initialize per-objfile state.  */
-      struct dwarf2_per_objfile *data
-	= XOBNEW (&objfile->objfile_obstack, struct dwarf2_per_objfile);
-
-      dwarf2_per_objfile = new (data) struct dwarf2_per_objfile (objfile, names);
+      dwarf2_per_objfile
+	= new (&objfile->objfile_obstack) struct dwarf2_per_objfile (objfile,
+								     names);
       set_dwarf2_per_objfile (objfile, dwarf2_per_objfile);
     }
   return (!dwarf2_per_objfile->info.is_virtual
@@ -25168,10 +25167,7 @@ dwarf2_free_objfile (struct objfile *objfile)
   struct dwarf2_per_objfile *dwarf2_per_objfile
     = get_dwarf2_per_objfile (objfile);
 
-  if (dwarf2_per_objfile == NULL)
-    return;
-
-  dwarf2_per_objfile->~dwarf2_per_objfile ();
+  delete dwarf2_per_objfile;
 }
 
 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
diff --git a/gdb/gdb_obstack.h b/gdb/gdb_obstack.h
index 12a90c3..b239ce6 100644
--- a/gdb/gdb_obstack.h
+++ b/gdb/gdb_obstack.h
@@ -78,4 +78,18 @@ struct auto_obstack : obstack
   { obstack_free (this, obstack_base (this)); }
 };
 
+/* Objects are allocated on obstack instead of heap.  */
+
+struct allocate_on_obstack
+{
+  void* operator new (size_t size, struct obstack *obstack)
+  {
+    return obstack_alloc (obstack, size);
+  }
+
+  void operator delete (void* memory)
+  {
+  }
+};
+
 #endif

  reply	other threads:[~2018-01-26 17:25 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-25  9:38 [PATCH 0/7] " Yao Qi
2018-01-25  9:38 ` [PATCH 6/7] Move fixup_partial_die to partial_die_info::fixup Yao Qi
2018-01-25 12:59   ` Pedro Alves
2018-01-25 14:45     ` Yao Qi
2018-01-25  9:38 ` [PATCH 5/7] Remove one argument abbrev_len in read_partial_die Yao Qi
2018-01-29  1:30   ` Simon Marchi
2018-01-25  9:38 ` [PATCH 1/7] Re-write partial_die_info allocation in load_partial_dies Yao Qi
2018-01-25  9:38 ` [PATCH 7/7] Move read_partial_die to partial_die_info::read Yao Qi
2018-01-29  1:58   ` Simon Marchi
2018-01-25  9:38 ` [PATCH 4/7] Class-fy partial_die_info Yao Qi
2018-01-25 16:19   ` Tom Tromey
2018-01-26 17:25     ` Yao Qi [this message]
2018-01-26 20:55       ` Tom Tromey
2018-01-29  1:15   ` Simon Marchi
2018-01-30 10:49     ` Yao Qi
2018-01-30 15:11       ` Pedro Alves
2018-01-30 11:39     ` Pedro Alves
2018-01-31  3:46       ` Simon Marchi
2018-01-31 11:55         ` Yao Qi
2018-01-31 15:33         ` Pedro Alves
2018-01-25  9:38 ` [PATCH 2/7] Don't check abbrev is NULL in read_partial_die Yao Qi
2018-01-25  9:38 ` [PATCH 3/7] Change find_partial_die_in_comp_unit to dwarf2_cu::find_partial_die Yao Qi
2018-01-25 12:05 ` [PATCH 0/7] Class-fy partial_die_info Joel Brobecker
2018-01-25 14:03   ` Yao Qi
2018-02-22 15:36 [PATCH 0/7 v2] " Yao Qi
2018-02-22 15:36 ` [PATCH 4/7] " Yao Qi

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=86lggkcz1x.fsf@gmail.com \
    --to=qiyaoltc@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /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).