From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 71672 invoked by alias); 10 May 2018 22:25:25 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 42151 invoked by uid 89); 10 May 2018 22:24:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.8 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=readers, waste, violate X-HELO: gateway34.websitewelcome.com Received: from gateway34.websitewelcome.com (HELO gateway34.websitewelcome.com) (192.185.149.105) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 10 May 2018 22:24:23 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway34.websitewelcome.com (Postfix) with ESMTP id 1A734261A624 for ; Thu, 10 May 2018 17:24:10 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id Gtysfw931BcCXGtysftsJE; Thu, 10 May 2018 17:24:10 -0500 X-Authority-Reason: nr=8 Received: from 97-122-176-117.hlrn.qwest.net ([97.122.176.117]:54520 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1fGtyr-001ijL-RP; Thu, 10 May 2018 17:24:09 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 15/15] Move psymtabs to their own obstack Date: Thu, 10 May 2018 22:25:00 -0000 Message-Id: <20180510222357.27332-16-tom@tromey.com> In-Reply-To: <20180510222357.27332-1-tom@tromey.com> References: <20180510222357.27332-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1fGtyr-001ijL-RP X-Source-Sender: 97-122-176-117.hlrn.qwest.net (bapiya.Home) [97.122.176.117]:54520 X-Source-Auth: tom+tromey.com X-Email-Count: 16 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-SW-Source: 2018-05/txt/msg00284.txt.bz2 Previously, the psymtab obstack was just a pointer to the objfile obstack. This patch changes psymtabs to use their own obstack, instead. A gdb::optional is used to avoid unnecessary allocation when the obstack is not needed. After this patch, the psymtab code lifetime model is that, in the core psymtab code, objects allocated on the psymtab obstack may point to other such objects, or to objects on the per-BFD obstack -- but never to the objfile obstack. Note however that this invariant is only obeyed the core psymtab code. Symbol readers are free to work however they like; and in particular, even after this patch, in practice all symbol readers violate this invariant via the read_symtab_private field. gdb/ChangeLog 2018-05-10 Tom Tromey * psymtab.h (psymtab_storage::obstack): Update. (psymtab_storage::m_obstack): Use gdb::optional. (class psymtab_storage): Update comment. * psymtab.c (psymtab_storage::psymtab_storage): Update. --- gdb/ChangeLog | 7 +++++++ gdb/psymtab.c | 3 +-- gdb/psymtab.h | 23 +++++++++++++++++++---- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/gdb/psymtab.c b/gdb/psymtab.c index f109e9f1ee..afdeeafc02 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -68,8 +68,7 @@ static struct compunit_symtab *psymtab_to_symtab (struct objfile *objfile, psymtab_storage::psymtab_storage (struct objfile *objfile) - : psymbol_cache (psymbol_bcache_init ()), - m_obstack (&objfile->objfile_obstack) + : psymbol_cache (psymbol_bcache_init ()) { } diff --git a/gdb/psymtab.h b/gdb/psymtab.h index c4b6f3b9ad..134edfc540 100644 --- a/gdb/psymtab.h +++ b/gdb/psymtab.h @@ -31,7 +31,19 @@ struct partial_symtab; struct psymbol_bcache; /* An instance of this class manages the partial symbol tables and - partial symbols for a given objfile. */ + partial symbols for a given objfile. + + The core psymtab functions -- those in psymtab.c -- arrange for all + psymtab- and psymbol-related allocations to happen either in the + psymtab_storage object (either on its obstack or in other memory + managed by this class), or on the per-BFD object. In particular + the core psymtab code will not make links from the psymtab_storage + object back to the objfile (or objfile_obstack). + + However, it is up to each symbol reader to maintain this invariant + itself, if it wants to reuse psymtabs across multiple objfiles. + The main issue here is ensuring that read_symtab_private does not + point into objfile_obstack. */ class psymtab_storage { @@ -58,7 +70,9 @@ public: struct obstack *obstack () { - return m_obstack; + if (!m_obstack.has_value ()) + m_obstack.emplace (); + return &*m_obstack; } struct partial_symtab **allocate_dependencies (int number) @@ -103,9 +117,10 @@ private: struct partial_symtab *free_psymtabs = nullptr; - /* The obstack where allocations are made. */ + /* The obstack where allocations are made. This is lazily allocated + so that we don't waste memory when there are no psymtabs. */ - struct obstack *m_obstack; + gdb::optional m_obstack; }; -- 2.13.6