From patchwork Thu Feb 20 00:45:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 38251 Received: (qmail 40887 invoked by alias); 20 Feb 2020 00:46:08 -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 40879 invoked by uid 89); 20 Feb 2020 00:46:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.4 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=expense, DW_TAG_typedef, dw_tag_typedef X-HELO: gateway23.websitewelcome.com Received: from gateway23.websitewelcome.com (HELO gateway23.websitewelcome.com) (192.185.50.129) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 20 Feb 2020 00:46:06 +0000 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway23.websitewelcome.com (Postfix) with ESMTP id A31624C8 for ; Wed, 19 Feb 2020 18:45:56 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 4ZyWjomZFAGTX4ZyWjzURj; Wed, 19 Feb 2020 18:45:56 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=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: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=/Ftokd1HPEIxFaUU/NEnR4T8GAsRJkwqF7YgsX6hz8w=; b=KafSJjkw270gOm2J/PQGomnm9R 1gbQ0PBUUSzl9HZ5HY6Kyie6H7+sN2OG5XAUy8NTIifY6AdkgKpbt7BeHRYTl4b+elBG/FpvGv3Js SNOfhIUGCPDdkdiBUSHg+fNHt; Received: from 75-166-123-50.hlrn.qwest.net ([75.166.123.50]:57210 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1j4ZyW-003foN-FK; Wed, 19 Feb 2020 17:45:56 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFC] Add ability to skip demangling partial symbols Date: Wed, 19 Feb 2020 17:45:54 -0700 Message-Id: <20200220004554.24976-1-tom@tromey.com> Since the "physname" patches (many years ago now), the DWARF reader essentially computes the mangled itself while reading psymbols, and passes this to add_psymbol_to_list. This function then calls compute_and_set_names -- which tries to demangle the name again. However, this is just extra work that, if it ever succeeds, can only do so by accident. It would be good to fix the physname patches to do the right thing. That is, store the mangled form, and arrange to set both forms when creating the partial symbol (without re-demangling). However, given that it has been many years and this hasn't happened, it seemed to me that it would be ok to at least exploit the efficiency gain here, by avoiding demangling. That is what this patch implements. In my build this speeds up "file ./gdb" from: Command execution time: 6.090913 (cpu), 5.925363 (wall) to: Command execution time: 5.306672 (cpu), 5.138870 (wall) gdb/ChangeLog 2020-02-19 Tom Tromey * psymtab.c (add_psymbol_to_bcache, add_psymbol_to_list): Add "no_demangle" parameter. * psympriv.h (add_psymbol_to_list): Add "no_demangle" parameter. * dwarf2/read.c (add_partial_symbol, load_partial_dies): Update calls to add_psymbol_to_list. --- gdb/ChangeLog | 8 ++++++++ gdb/dwarf2/read.c | 24 ++++++++++++------------ gdb/psympriv.h | 9 +++++++-- gdb/psymtab.c | 26 ++++++++++++++++++++++---- 4 files changed, 49 insertions(+), 18 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 4d767a59af7..34be28ebc2f 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -8164,7 +8164,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) SECT_OFF_TEXT (objfile), psymbol_placement::GLOBAL, addr, - cu->language, objfile); + cu->language, objfile, true); } else { @@ -8173,7 +8173,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) VAR_DOMAIN, LOC_BLOCK, SECT_OFF_TEXT (objfile), psymbol_placement::STATIC, - addr, cu->language, objfile); + addr, cu->language, objfile, true); } if (pdi->main_subprogram && actual_name != NULL) @@ -8185,7 +8185,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) -1, (pdi->is_external ? psymbol_placement::GLOBAL : psymbol_placement::STATIC), - 0, cu->language, objfile); + 0, cu->language, objfile, true); break; case DW_TAG_variable: if (pdi->d.locdesc) @@ -8221,7 +8221,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) VAR_DOMAIN, LOC_STATIC, SECT_OFF_TEXT (objfile), psymbol_placement::GLOBAL, - addr, cu->language, objfile); + addr, cu->language, objfile, true); } else { @@ -8238,7 +8238,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) SECT_OFF_TEXT (objfile), psymbol_placement::STATIC, has_loc ? addr : 0, - cu->language, objfile); + cu->language, objfile, true); } break; case DW_TAG_typedef: @@ -8248,7 +8248,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) built_actual_name != NULL, VAR_DOMAIN, LOC_TYPEDEF, -1, psymbol_placement::STATIC, - 0, cu->language, objfile); + 0, cu->language, objfile, true); break; case DW_TAG_imported_declaration: case DW_TAG_namespace: @@ -8256,7 +8256,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) built_actual_name != NULL, VAR_DOMAIN, LOC_TYPEDEF, -1, psymbol_placement::GLOBAL, - 0, cu->language, objfile); + 0, cu->language, objfile, true); break; case DW_TAG_module: /* With Fortran 77 there might be a "BLOCK DATA" module @@ -8267,7 +8267,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) built_actual_name != NULL, MODULE_DOMAIN, LOC_TYPEDEF, -1, psymbol_placement::GLOBAL, - 0, cu->language, objfile); + 0, cu->language, objfile, true); break; case DW_TAG_class_type: case DW_TAG_interface_type: @@ -8290,7 +8290,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) cu->language == language_cplus ? psymbol_placement::GLOBAL : psymbol_placement::STATIC, - 0, cu->language, objfile); + 0, cu->language, objfile, true); break; case DW_TAG_enumerator: @@ -8300,7 +8300,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) cu->language == language_cplus ? psymbol_placement::GLOBAL : psymbol_placement::STATIC, - 0, cu->language, objfile); + 0, cu->language, objfile, true); break; default: break; @@ -17758,7 +17758,7 @@ load_partial_dies (const struct die_reader_specs *reader, add_psymbol_to_list (pdi.name, false, VAR_DOMAIN, LOC_TYPEDEF, -1, psymbol_placement::STATIC, - 0, cu->language, objfile); + 0, cu->language, objfile, true); info_ptr = locate_pdi_sibling (reader, &pdi, info_ptr); continue; } @@ -17794,7 +17794,7 @@ load_partial_dies (const struct die_reader_specs *reader, cu->language == language_cplus ? psymbol_placement::GLOBAL : psymbol_placement::STATIC, - 0, cu->language, objfile); + 0, cu->language, objfile, true); info_ptr = locate_pdi_sibling (reader, &pdi, info_ptr); continue; diff --git a/gdb/psympriv.h b/gdb/psympriv.h index 1b1f57cf764..7fa2010743b 100644 --- a/gdb/psympriv.h +++ b/gdb/psympriv.h @@ -404,7 +404,11 @@ enum class psymbol_placement an address, zero is passed. LANGUAGE is the language from which the symbol originates. This will - influence, amongst other things, how the symbol name is demangled. */ + influence, amongst other things, how the symbol name is demangled. + + NO_DEMANGLE can be used to indicate that NAME has already been + demangled. Some symbol readers compute the demangled name, and + this avoids the extra expense of an attempted demangling. */ extern void add_psymbol_to_list (gdb::string_view name, bool copy_name, domain_enum domain, @@ -413,7 +417,8 @@ extern void add_psymbol_to_list (gdb::string_view name, psymbol_placement where, CORE_ADDR coreaddr, enum language language, - struct objfile *objfile); + struct objfile *objfile, + bool no_demangle = false); /* Initialize storage for partial symbols. If partial symbol storage has already been initialized, this does nothing. TOTAL_SYMBOLS is diff --git a/gdb/psymtab.c b/gdb/psymtab.c index 56576b3bcec..07cae9ce8e8 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -1570,7 +1570,7 @@ add_psymbol_to_bcache (gdb::string_view name, bool copy_name, short section, CORE_ADDR coreaddr, enum language language, struct objfile *objfile, - int *added) + bool no_demangle, int *added) { struct partial_symbol psymbol; memset (&psymbol, 0, sizeof (psymbol)); @@ -1580,7 +1580,23 @@ add_psymbol_to_bcache (gdb::string_view name, bool copy_name, psymbol.domain = domain; psymbol.aclass = theclass; psymbol.ginfo.set_language (language, objfile->partial_symtabs->obstack ()); - psymbol.ginfo.compute_and_set_names (name, copy_name, objfile->per_bfd); + + if (no_demangle) + { + /* NAME is already demangled. */ + const char *stored_name; + if (copy_name) + stored_name = ((const char *) objfile->per_bfd->filename_cache + .insert (name.data (), name.size ())); + else + stored_name = name.data (); + + psymbol.ginfo.m_name = stored_name; + symbol_set_demangled_name (&psymbol.ginfo, nullptr, + &objfile->per_bfd->storage_obstack); + } + else + psymbol.ginfo.compute_and_set_names (name, copy_name, objfile->per_bfd); /* Stash the partial symbol away in the cache. */ return ((struct partial_symbol *) @@ -1608,7 +1624,8 @@ add_psymbol_to_list (gdb::string_view name, bool copy_name, short section, psymbol_placement where, CORE_ADDR coreaddr, - enum language language, struct objfile *objfile) + enum language language, struct objfile *objfile, + bool no_demangle) { struct partial_symbol *psym; @@ -1616,7 +1633,8 @@ add_psymbol_to_list (gdb::string_view name, bool copy_name, /* Stash the partial symbol away in the cache. */ psym = add_psymbol_to_bcache (name, copy_name, domain, theclass, - section, coreaddr, language, objfile, &added); + section, coreaddr, language, objfile, + no_demangle, &added); /* Do not duplicate global partial symbols. */ if (where == psymbol_placement::GLOBAL && !added)