From patchwork Tue Feb 25 13:09:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 38302 Received: (qmail 114164 invoked by alias); 25 Feb 2020 13:09:47 -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 114086 invoked by uid 89); 25 Feb 2020 13:09:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.1 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.1 spammy=Everything, info_ptr, pst, PST X-HELO: gateway33.websitewelcome.com Received: from gateway33.websitewelcome.com (HELO gateway33.websitewelcome.com) (192.185.146.80) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 25 Feb 2020 13:09:36 +0000 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway33.websitewelcome.com (Postfix) with ESMTP id 8EB132B0F3F for ; Tue, 25 Feb 2020 07:09:34 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 6ZxujWeVuSl8q6ZxujBWl3; Tue, 25 Feb 2020 07:09:34 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=uMnRyfbJAmRNuajrQ4421gJzG6ryFOHZkemiqAzqhTs=; b=sg0uzMS/nbKGoHXWq1aPVHu/MB Y2ZxOGzfPBeXquuULcyUpjRrYA8s8ePF6UD7kb037l2y1YRRUoLgjZQy/eCERU/RE05RhKmLqpo2E sAhFR3uRxi62XzZHcQLdfuzrJ; Received: from 75-166-123-50.hlrn.qwest.net ([75.166.123.50]:55352 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1j6Zxu-001C8N-A4; Tue, 25 Feb 2020 06:09:34 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/2] Specialize partial_symtab for DWARF include files Date: Tue, 25 Feb 2020 06:09:32 -0700 Message-Id: <20200225130932.6861-3-tom@tromey.com> In-Reply-To: <20200225130932.6861-1-tom@tromey.com> References: <20200225130932.6861-1-tom@tromey.com> Include files are represented by a partial symtab, but don't expand to anything. From dwarf2_psymtab::expand_psymtab: if (per_cu == NULL) { /* It's an include file, no symbols to read for it. Everything is in the parent symtab. */ readin = true; return; } This patch introduces a new specialization of partial_symtab to handle this case. In addition to being slightly smaller, I believe an include file is the only situation where a DWARF psymtab can result in a null compunit_symtab. This adds an assert to that effect as well. This change will simplify one of the psymtab sharing patches. gdb/ChangeLog 2020-02-25 Tom Tromey * dwarf2/read.c (struct dwarf2_include_psymtab): New. (dwarf2_create_include_psymtab): Use dwarf2_include_psymtab. (dwarf2_psymtab::expand_psymtab, dwarf2_psymtab::readin_p) (dwarf2_psymtab::get_compunit_symtab): Remove null checks for per_cu_data. --- gdb/ChangeLog | 8 +++++++ gdb/dwarf2/read.c | 61 ++++++++++++++++++++++++++++++++--------------- 2 files changed, 50 insertions(+), 19 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 8c40ddb727a..d22a53deb25 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -5894,6 +5894,45 @@ read_abbrev_offset (struct dwarf2_per_objfile *dwarf2_per_objfile, return (sect_offset) read_offset (abfd, info_ptr, offset_size); } +/* A partial symtab that is used only for include files. */ +struct dwarf2_include_psymtab : public partial_symtab +{ + dwarf2_include_psymtab (const char *filename, struct objfile *objfile) + : partial_symtab (filename, objfile) + { + } + + void read_symtab (struct objfile *objfile) override + { + expand_psymtab (objfile); + } + + void expand_psymtab (struct objfile *objfile) override + { + if (m_readin) + return; + /* It's an include file, no symbols to read for it. + Everything is in the parent symtab. */ + read_dependencies (objfile); + m_readin = true; + } + + bool readin_p () const override + { + return m_readin; + } + + struct compunit_symtab *get_compunit_symtab () const + override + { + return nullptr; + } + +private: + + bool m_readin = false; +}; + /* Allocate a new partial symtab for file named NAME and mark this new partial symtab as being an include of PST. */ @@ -5901,7 +5940,7 @@ static void dwarf2_create_include_psymtab (const char *name, dwarf2_psymtab *pst, struct objfile *objfile) { - dwarf2_psymtab *subpst = new dwarf2_psymtab (name, objfile); + dwarf2_include_psymtab *subpst = new dwarf2_include_psymtab (name, objfile); if (!IS_ABSOLUTE_PATH (subpst->filename)) { @@ -5912,11 +5951,6 @@ dwarf2_create_include_psymtab (const char *name, dwarf2_psymtab *pst, subpst->dependencies = objfile->partial_symtabs->allocate_dependencies (1); subpst->dependencies[0] = pst; subpst->number_of_dependencies = 1; - - /* No private part is necessary for include psymtabs. This property - can be used to differentiate between such include psymtabs and - the regular ones. */ - subpst->per_cu_data = nullptr; } /* Read the Line Number Program data and extract the list of files @@ -8827,24 +8861,13 @@ process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile) void dwarf2_psymtab::expand_psymtab (struct objfile *objfile) { - struct dwarf2_per_cu_data *per_cu; - if (readin) return; read_dependencies (objfile); - per_cu = per_cu_data; - - if (per_cu == NULL) - { - /* It's an include file, no symbols to read for it. - Everything is in the parent symtab. */ - readin = true; - return; - } - - dw2_do_instantiate_symtab (per_cu, false); + dw2_do_instantiate_symtab (per_cu_data, false); + gdb_assert (get_compunit_symtab () != nullptr); } /* Trivial hash function for die_info: the hash value of a DIE