From patchwork Wed Feb 7 09:40:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 25842 Received: (qmail 101762 invoked by alias); 7 Feb 2018 09:40:53 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 101740 invoked by uid 89); 7 Feb 2018 09:40:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=NAMES, HX-Received:10.80.153.150, H*r:sk:static. X-HELO: mail-wm0-f51.google.com Received: from mail-wm0-f51.google.com (HELO mail-wm0-f51.google.com) (74.125.82.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 07 Feb 2018 09:40:51 +0000 Received: by mail-wm0-f51.google.com with SMTP id f3so2027194wmc.1 for ; Wed, 07 Feb 2018 01:40:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=HYX/G0N/7zT3zX4JWIOz5O9Um5aUGxRl8yNi6RwywxU=; b=MfGT6UXmnBjuMmMtSBokonPpIeph0cTE6elo5wcdTfXh2tA0FvCopM6ihdxtuzqn3E /6piI3GSq3OtyIGjGk6MQtl72CvGx9IaieKPfhSPyYorQwk8ADR4asbu0rNkjbapwf3N +cOzgLTpH20pdksw/Kx+xqDNhcOA1gZqWl9AJnqLgxZ4/HXD0BslcgH0pcBtC0uKKscN gvAgW1FQ1Mb2OqlxlJtN0WGv3yFJxaTXsnQ1Bund+37SEGMqpmeOlNHTfkDMwqyvgs16 tPq6ipyqIUTw9+b0gvR/2MlJA07+aRqdEha4vKvgFoiNHA3WU7LnKnK1bCkGzZ1FbdXJ HHKQ== X-Gm-Message-State: APf1xPCCucoxaNEwi7ErULzTy1HmDh70HoQPizmsYEZu3YZ0lxwVj8qk /Jy4DHBN1UmuheqQCVed1MKfAw== X-Google-Smtp-Source: AH8x227OV0hfvfNYz4vg3VU9Nhj83tzryyIfoDghsQhR5MQwWp3i2XxRrX6UxFTSDU8RocsvGv/RUA== X-Received: by 10.80.153.150 with SMTP id m22mr7662367edb.303.1517996448686; Wed, 07 Feb 2018 01:40:48 -0800 (PST) Received: from E107787-LIN.cambridge.arm.com (static.42.136.251.148.clients.your-server.de. [148.251.136.42]) by smtp.gmail.com with ESMTPSA id k12sm905952edl.86.2018.02.07.01.40.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Feb 2018 01:40:48 -0800 (PST) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Cc: tom@tromey.com Subject: [PATCH] New class allocate_on_obstack Date: Wed, 7 Feb 2018 09:40:44 +0000 Message-Id: <1517996444-8605-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes 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. Regression tested on x86_64-linux. gdb: 2018-02-06 Yao Qi * block.c (block_namespace_info): Inherit allocate_on_obstack. (block_initialize_namespace): Use new. * dwarf2read.c (dwarf2_per_objfile): Inherit allocate_on_obstack. (dwarf2_free_objfile): Use delete. * gdbtypes.c (type_pair): Inherit allocate_on_obstack. (copy_type_recursive): Use new. * gdb_obstack.h (allocate_on_obstack): New. --- gdb/block.c | 12 ++++-------- gdb/dwarf2read.c | 14 +++++--------- gdb/gdb_obstack.h | 20 ++++++++++++++++++++ gdb/gdbtypes.c | 18 +++++++++++------- 4 files changed, 40 insertions(+), 24 deletions(-) diff --git a/gdb/block.c b/gdb/block.c index 57da7ba..f26d169 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -31,10 +31,10 @@ C++ files, namely using declarations and the current namespace in scope. */ -struct block_namespace_info +struct block_namespace_info : public allocate_on_obstack { - const char *scope; - struct using_direct *using_decl; + const char *scope = nullptr; + struct using_direct *using_decl = nullptr; }; static void block_initialize_namespace (struct block *block, @@ -350,11 +350,7 @@ static void block_initialize_namespace (struct block *block, struct obstack *obstack) { if (BLOCK_NAMESPACE (block) == NULL) - { - BLOCK_NAMESPACE (block) = XOBNEW (obstack, struct block_namespace_info); - BLOCK_NAMESPACE (block)->scope = NULL; - BLOCK_NAMESPACE (block)->using_decl = NULL; - } + BLOCK_NAMESPACE (block) = new (obstack) struct block_namespace_info (); } /* Return the static block associated to BLOCK. Return NULL if block diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index d651725..c38eb4e 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 @@ -2490,10 +2490,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 @@ -25191,10 +25190,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..f91e61a 100644 --- a/gdb/gdb_obstack.h +++ b/gdb/gdb_obstack.h @@ -78,4 +78,24 @@ struct auto_obstack : obstack { obstack_free (this, obstack_base (this)); } }; +/* Objects are allocated on obstack instead of heap. */ + +struct allocate_on_obstack +{ + allocate_on_obstack () = default; + + void* operator new (size_t size, struct obstack *obstack) + { + return obstack_alloc (obstack, size); + } + + void* operator new[] (size_t size, struct obstack *obstack) + { + return obstack_alloc (obstack, size); + } + + void operator delete (void* memory) {} + void operator delete[] (void* memory) {} +}; + #endif diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 79bb659..b3a0379 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -4699,9 +4699,13 @@ recursive_dump_type (struct type *type, int spaces) /* Trivial helpers for the libiberty hash table, for mapping one type to another. */ -struct type_pair +struct type_pair : public allocate_on_obstack { - struct type *old, *newobj; + type_pair (struct type *old_, struct type *newobj_) + : old (old_), newobj (newobj_) + {} + + struct type * const old, * const newobj; }; static hashval_t @@ -4769,7 +4773,6 @@ copy_type_recursive (struct objfile *objfile, struct type *type, htab_t copied_types) { - struct type_pair *stored, pair; void **slot; struct type *new_type; @@ -4780,7 +4783,8 @@ copy_type_recursive (struct objfile *objfile, if it did, the type might disappear unexpectedly. */ gdb_assert (TYPE_OBJFILE (type) == objfile); - pair.old = type; + struct type_pair pair (type, nullptr); + slot = htab_find_slot (copied_types, &pair, INSERT); if (*slot != NULL) return ((struct type_pair *) *slot)->newobj; @@ -4789,9 +4793,9 @@ copy_type_recursive (struct objfile *objfile, /* We must add the new type to the hash table immediately, in case we encounter this type again during a recursive call below. */ - stored = XOBNEW (&objfile->objfile_obstack, struct type_pair); - stored->old = type; - stored->newobj = new_type; + struct type_pair *stored + = new (&objfile->objfile_obstack) struct type_pair (type, new_type); + *slot = stored; /* Copy the common fields of types. For the main type, we simply