From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTP id 31894387703A for ; Fri, 20 Mar 2020 20:49:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 31894387703A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 135A556164; Fri, 20 Mar 2020 16:49:37 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id WD2-Ps+aBycf; Fri, 20 Mar 2020 16:49:37 -0400 (EDT) Received: from murgatroyd.Home (97-118-117-21.hlrn.qwest.net [97.118.117.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id C411D56162; Fri, 20 Mar 2020 16:49:36 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/2] Avoid some copying in psymtab.c Date: Fri, 20 Mar 2020 14:49:34 -0600 Message-Id: <20200320204935.19509-2-tromey@adacore.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200320204935.19509-1-tromey@adacore.com> References: <20200320204935.19509-1-tromey@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Mar 2020 20:49:38 -0000 I noticed that psymtab.c was always copying the search string in psymtab_search_name, even when it wasn't necessary. This patch replaces this function with a class which holds the allocated search name, if necessary. Once I had done that, I noticed that lookup_partial_symbol was creating a lookup_name_info. However, this function called in loops, causing even more excess allocation. This patch further fixes this by hosting the creation of the lookup_name_info into the callers. gdb/ChangeLog 2020-03-20 Tom Tromey * psymtab.c (class psymtab_search_name): New class. (psymtab_search_name): Remove function. (psym_lookup_symbol): Create search name and lookup name here. (lookup_partial_symbol): Remove "name" parameter; add lookup_name. (psym_expand_symtabs_for_function): Update. --- gdb/ChangeLog | 9 +++++ gdb/psymtab.c | 94 ++++++++++++++++++++++++++++----------------------- 2 files changed, 61 insertions(+), 42 deletions(-) diff --git a/gdb/psymtab.c b/gdb/psymtab.c index f77f6d5108f..34b9741e966 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -39,7 +39,8 @@ static struct partial_symbol *lookup_partial_symbol (struct objfile *, struct partial_symtab *, - const char *, int, + const lookup_name_info &, + int, domain_enum); static const char *psymtab_to_fullname (struct partial_symtab *ps); @@ -469,6 +470,38 @@ find_pc_sect_psymbol (struct objfile *objfile, return best; } +/* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do + not contain any method/function instance information (since this would + force reading type information while reading psymtabs). Therefore, + if NAME contains overload information, it must be stripped before searching + psymtabs. */ + +class psymtab_search_name +{ +public: + explicit psymtab_search_name (const char *name) + : m_name (name) + { + if (current_language->la_language == language_cplus && strchr (name, '(')) + m_search_name = cp_remove_params (name); + } + + /* Return the search name. */ + const char *get () const + { + if (m_search_name == nullptr) + return m_name; + return m_search_name.get (); + } + +private: + + /* The original name. */ + const char *m_name; + /* The search name, if one was needed. */ + gdb::unique_xmalloc_ptr m_search_name; +}; + /* Psymtab version of lookup_symbol. See its definition in the definition of quick_symbol_functions in symfile.h. */ @@ -482,9 +515,14 @@ psym_lookup_symbol (struct objfile *objfile, lookup_name_info lookup_name (name, symbol_name_match_type::FULL); + psymtab_search_name search_name (name); + lookup_name_info psym_lookup_name (search_name.get (), + symbol_name_match_type::FULL); + for (partial_symtab *ps : require_partial_symbols (objfile, true)) { - if (!ps->readin_p () && lookup_partial_symbol (objfile, ps, name, + if (!ps->readin_p () && lookup_partial_symbol (objfile, ps, + psym_lookup_name, psymtab_index, domain)) { struct symbol *sym, *with_opaque = NULL; @@ -612,42 +650,14 @@ match_partial_symbol (struct objfile *objfile, return NULL; } -/* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do - not contain any method/function instance information (since this would - force reading type information while reading psymtabs). Therefore, - if NAME contains overload information, it must be stripped before searching - psymtabs. */ - -static gdb::unique_xmalloc_ptr -psymtab_search_name (const char *name) -{ - switch (current_language->la_language) - { - case language_cplus: - { - if (strchr (name, '(')) - { - gdb::unique_xmalloc_ptr ret = cp_remove_params (name); - - if (ret) - return ret; - } - } - break; - - default: - break; - } - - return make_unique_xstrdup (name); -} - -/* Look, in partial_symtab PST, for symbol whose natural name is NAME. - Check the global symbols if GLOBAL, the static symbols if not. */ +/* Look, in partial_symtab PST, for symbol whose natural name is + LOOKUP_NAME. Check the global symbols if GLOBAL, the static + symbols if not. */ static struct partial_symbol * lookup_partial_symbol (struct objfile *objfile, - struct partial_symtab *pst, const char *name, + struct partial_symtab *pst, + const lookup_name_info &lookup_name, int global, domain_enum domain) { struct partial_symbol **start, **psym; @@ -658,10 +668,6 @@ lookup_partial_symbol (struct objfile *objfile, if (length == 0) return NULL; - gdb::unique_xmalloc_ptr search_name = psymtab_search_name (name); - - lookup_name_info lookup_name (search_name.get (), symbol_name_match_type::FULL); - start = (global ? &objfile->partial_symtabs->global_psymbols[pst->globals_offset] : &objfile->partial_symtabs->static_psymbols[pst->statics_offset]); @@ -686,7 +692,7 @@ lookup_partial_symbol (struct objfile *objfile, internal_error (__FILE__, __LINE__, _("failed internal consistency check")); if (strcmp_iw_ordered ((*center)->ginfo.search_name (), - search_name.get ()) >= 0) + lookup_name.name ().c_str ()) >= 0) { top = center; } @@ -1044,14 +1050,18 @@ static void psym_expand_symtabs_for_function (struct objfile *objfile, const char *func_name) { + psymtab_search_name search_name (func_name); + lookup_name_info lookup_name (search_name.get (), + symbol_name_match_type::FULL); + for (partial_symtab *ps : require_partial_symbols (objfile, true)) { if (ps->readin_p ()) continue; - if ((lookup_partial_symbol (objfile, ps, func_name, 1, VAR_DOMAIN) + if ((lookup_partial_symbol (objfile, ps, lookup_name, 1, VAR_DOMAIN) != NULL) - || (lookup_partial_symbol (objfile, ps, func_name, 0, VAR_DOMAIN) + || (lookup_partial_symbol (objfile, ps, lookup_name, 0, VAR_DOMAIN) != NULL)) psymtab_to_symtab (objfile, ps); } -- 2.21.1