From patchwork Thu Jan 25 18:19:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 84747 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 77ADA3857C4E for ; Thu, 25 Jan 2024 18:20:11 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by sourceware.org (Postfix) with ESMTPS id D73343858408 for ; Thu, 25 Jan 2024 18:19:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D73343858408 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D73343858408 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d32 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706206782; cv=none; b=CvLDdH5h0Q94itel82EJ92U+3xhSd8RHGApdRz8pNpsns8zUcK+YD/JtCemhKxS+v2UOpdn2EZzIt/ZKekcJmqtKNQmyD0Me9ngArzWTnWw5lR+fFtIvyk1W6crIohfY86FYpdxJc6GwR4fgUyeAC17IZe0P28q3Zau1Pc4pBVI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706206782; c=relaxed/simple; bh=ohd/T153EGrQLEuyn4p6RQHcNdrILsBuK/J0oW/iOyo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=gllnp65Y1RbyAxMB2ABLWUfvzzgWWYmlQ/v7+b8Rl8pPj7h73ZmUw/UHo3ij3a/bEHzAzpXyW7pbNazNIT7/y0TY0yeyjEoJ88Ce4CWz4tBT6k6gL9yvLIKiXo1E5UzbXMPKsnMCbdjBTVO555b6tuG98Daxr2WEEHtnBfJE9Cw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd32.google.com with SMTP id ca18e2360f4ac-7bf7e37dc60so270332739f.3 for ; Thu, 25 Jan 2024 10:19:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1706206779; x=1706811579; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Sgvgcv2zHgtLWUwlbmsNefqZARlucuHjvzXKEaJatWI=; b=amT5pA5rwKKsAvRSqgpvKOUp0Sc+m/A1OEpdbcFLPp6Nq0+y98vfqP6paN44DDFGvL 1hXJJ0rnmFuU5wZQkv15XEqCmyHVAWhK70RHqF+Jq82f3xSfPjcHjKFl8tOZs93TfTJy irl/6eUSp/Gmx8jg1GFhz8NYvU8opCTQ+rp55bUoqPU3/rn/ipip0OpCDpxLbVW3c5LQ i6VWRFnHWSdXYGZR7eMIoeP7S83zVLe5U7rcVuDl8LA6D8OIcb+OUAO3ytDAHnYWTe7R ObUKOW2JnkdhrN6kM0yYmAW/mHg00r9VE3ATrOmYTcTX85lhslUg9vaj6GZfQabBmwYY 96tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706206779; x=1706811579; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Sgvgcv2zHgtLWUwlbmsNefqZARlucuHjvzXKEaJatWI=; b=JaZ01nRdVxJwebBLc5pwkztdGxW3Br6qQCR5PtGsuAHbfW3SMzPlcHegKK4B+kQ4gX tm9e0d+TlXve8Uv6HoscrXqYo9Q+pkNm+Zw0RK9ftnS+fFxN/SsF0JnAa0o0r4WEVM27 pk+e7tIcWTkVNfAcd5PnhMaHp6LgqQdxmtwUppjLwmaU5HrJtPlD2v9cxtjhcnB5iawJ zCN6MDax1W0o6uK8T2Ccks1kRqHoNpUGFteAuqAArklUqr7PdQIzWfN+PkgP7ijDGTY7 QyGC5RapE+omuH5mKYUTy54duV4+VWG689Q8+oeL0eJrKm1P3nOyCbTLBq/EdvZ98ikD FKwQ== X-Gm-Message-State: AOJu0YwPpcxTW4vTi6B0PbeRTax+/mA3tJrKtwBBDPBTITGcz70vY1+a s6TOAmbRmE9g0OKv0KMEq3wt0F7AfPV0IDu1k0FzXk4cOVFP511L044y4qSpdJXwQYEVWh3NRcA = X-Google-Smtp-Source: AGHT+IGboMNMY6QiNo9NGpP/pcrAOV4oHjWXULHrKnktZJ7Ku15RLd7vAjaCZ/8XZVUq9M/Hmjg81g== X-Received: by 2002:a05:6602:2bc6:b0:7bf:50cb:e610 with SMTP id s6-20020a0566022bc600b007bf50cbe610mr205218iov.6.1706206779044; Thu, 25 Jan 2024 10:19:39 -0800 (PST) Received: from localhost.localdomain (97-122-68-157.hlrn.qwest.net. [97.122.68.157]) by smtp.gmail.com with ESMTPSA id i25-20020a02c619000000b0046eae1a6315sm4396735jan.72.2024.01.25.10.19.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 10:19:38 -0800 (PST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Move lookup_name_info creation into basic_lookup_transparent_type Date: Thu, 25 Jan 2024 11:19:29 -0700 Message-ID: <20240125181929.5811-1-tromey@adacore.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org I noticed that basic_lookup_transparent_type calls two different functions that both proceed to create a lookup_name_info. It's more efficient to create this object in the outermost layer possible. Making this change required a few related changes, resulting in this patch. There are still more changs of this sort that could be made. Regression tested on x86-64 Fedora 38. --- gdb/block.c | 9 +++---- gdb/block.h | 3 +-- gdb/compile/compile-object-load.c | 13 +++++----- gdb/objfiles.h | 3 ++- gdb/psymtab.c | 12 ++++----- gdb/symfile-debug.c | 11 ++++---- gdb/symtab.c | 42 ++++++++++++++++++------------- 7 files changed, 47 insertions(+), 46 deletions(-) diff --git a/gdb/block.c b/gdb/block.c index 4b9307ea794..1dd3fd7adbf 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -673,17 +673,14 @@ better_symbol (struct symbol *a, struct symbol *b, const domain_enum domain) non-encoded names tested for a match. */ struct symbol * -block_lookup_symbol (const struct block *block, const char *name, - symbol_name_match_type match_type, +block_lookup_symbol (const struct block *block, const lookup_name_info &name, const domain_enum domain) { - lookup_name_info lookup_name (name, match_type); - if (!block->function ()) { struct symbol *other = NULL; - for (struct symbol *sym : block_iterator_range (block, &lookup_name)) + for (struct symbol *sym : block_iterator_range (block, &name)) { /* See comment related to PR gcc/debug/91507 in block_lookup_symbol_primary. */ @@ -711,7 +708,7 @@ block_lookup_symbol (const struct block *block, const char *name, struct symbol *sym_found = NULL; - for (struct symbol *sym : block_iterator_range (block, &lookup_name)) + for (struct symbol *sym : block_iterator_range (block, &name)) { if (sym->matches (domain)) { diff --git a/gdb/block.h b/gdb/block.h index 5c56518bfce..2c07a19364b 100644 --- a/gdb/block.h +++ b/gdb/block.h @@ -565,8 +565,7 @@ extern struct symbol *better_symbol (struct symbol *a, struct symbol *b, /* Search BLOCK for symbol NAME in DOMAIN. */ extern struct symbol *block_lookup_symbol (const struct block *block, - const char *name, - symbol_name_match_type match_type, + const lookup_name_info &name, const domain_enum domain); /* Search BLOCK for symbol NAME in DOMAIN but only in primary symbol table of diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c index b2cc3a1a042..213070c80b3 100644 --- a/gdb/compile/compile-object-load.c +++ b/gdb/compile/compile-object-load.c @@ -421,6 +421,10 @@ get_out_value_type (struct symbol *func_sym, struct objfile *objfile, lookup_name_info func_matcher (GCC_FE_WRAPPER_FUNCTION, symbol_name_match_type::SEARCH_NAME); + lookup_name_info i_val_matcher (COMPILE_I_EXPR_VAL, + symbol_name_match_type::SEARCH_NAME); + lookup_name_info i_ptr_matcher (COMPILE_I_EXPR_PTR_TYPE, + symbol_name_match_type::SEARCH_NAME); bv = func_sym->symtab ()->compunit ()->blockvector (); nblocks = bv->num_blocks (); @@ -434,10 +438,7 @@ get_out_value_type (struct symbol *func_sym, struct objfile *objfile, block = bv->block (block_loop); if (block->function () != NULL) continue; - gdb_val_sym = block_lookup_symbol (block, - COMPILE_I_EXPR_VAL, - symbol_name_match_type::SEARCH_NAME, - VAR_DOMAIN); + gdb_val_sym = block_lookup_symbol (block, i_val_matcher, VAR_DOMAIN); if (gdb_val_sym == NULL) continue; @@ -461,9 +462,7 @@ get_out_value_type (struct symbol *func_sym, struct objfile *objfile, gdb_type = gdb_val_sym->type (); gdb_type = check_typedef (gdb_type); - gdb_ptr_type_sym = block_lookup_symbol (block, COMPILE_I_EXPR_PTR_TYPE, - symbol_name_match_type::SEARCH_NAME, - VAR_DOMAIN); + gdb_ptr_type_sym = block_lookup_symbol (block, i_ptr_matcher, VAR_DOMAIN); if (gdb_ptr_type_sym == NULL) error (_("No \"%s\" symbol found"), COMPILE_I_EXPR_PTR_TYPE); gdb_ptr_type = gdb_ptr_type_sym->type (); diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 65115ce17f0..0d9993db0b7 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -561,7 +561,8 @@ struct objfile defined, or NULL if no such symbol table exists. If OBJFILE contains !TYPE_OPAQUE symbol prefer its compunit. If it contains only TYPE_OPAQUE symbol(s), return at least that compunit. */ - struct compunit_symtab *lookup_symbol (block_enum kind, const char *name, + struct compunit_symtab *lookup_symbol (block_enum kind, + const lookup_name_info &name, domain_enum domain); /* See quick_symbol_functions. */ diff --git a/gdb/psymtab.c b/gdb/psymtab.c index 4a3a872309d..7388618f41b 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -1522,9 +1522,9 @@ maintenance_check_psymtabs (const char *ignore, int from_tty) && psym->ginfo.value_address () == 0) continue; - sym = block_lookup_symbol (b, psym->ginfo.search_name (), - symbol_name_match_type::SEARCH_NAME, - psym->domain); + lookup_name_info lookup_name + (psym->ginfo.search_name (), symbol_name_match_type::SEARCH_NAME); + sym = block_lookup_symbol (b, lookup_name, psym->domain); if (!sym) { gdb_printf ("Static symbol `"); @@ -1537,9 +1537,9 @@ maintenance_check_psymtabs (const char *ignore, int from_tty) b = bv->global_block (); for (partial_symbol *psym : ps->global_psymbols) { - sym = block_lookup_symbol (b, psym->ginfo.search_name (), - symbol_name_match_type::SEARCH_NAME, - psym->domain); + lookup_name_info lookup_name + (psym->ginfo.search_name (), symbol_name_match_type::SEARCH_NAME); + sym = block_lookup_symbol (b, lookup_name, psym->domain); if (!sym) { gdb_printf ("Global symbol `"); diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c index b0d2e19295d..2f8d761476f 100644 --- a/gdb/symfile-debug.c +++ b/gdb/symfile-debug.c @@ -241,25 +241,24 @@ objfile::map_symtabs_matching_filename } struct compunit_symtab * -objfile::lookup_symbol (block_enum kind, const char *name, domain_enum domain) +objfile::lookup_symbol (block_enum kind, const lookup_name_info &name, + domain_enum domain) { struct compunit_symtab *retval = nullptr; if (debug_symfile) gdb_printf (gdb_stdlog, "qf->lookup_symbol (%s, %d, \"%s\", %s)\n", - objfile_debug_name (this), kind, name, + objfile_debug_name (this), kind, name.c_str (), domain_name (domain)); - lookup_name_info lookup_name (name, symbol_name_match_type::FULL); - auto search_one_symtab = [&] (compunit_symtab *stab) { struct symbol *sym, *with_opaque = NULL; const struct blockvector *bv = stab->blockvector (); const struct block *block = bv->block (kind); - sym = block_find_symbol (block, lookup_name, domain, &with_opaque); + sym = block_find_symbol (block, name, domain, &with_opaque); /* Some caution must be observed with overloaded functions and methods, since the index will not contain any overload @@ -282,7 +281,7 @@ objfile::lookup_symbol (block_enum kind, const char *name, domain_enum domain) { if (!iter->expand_symtabs_matching (this, nullptr, - &lookup_name, + &name, nullptr, search_one_symtab, kind == GLOBAL_BLOCK diff --git a/gdb/symtab.c b/gdb/symtab.c index 7c0a69108d4..3435029664d 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -1994,13 +1994,14 @@ lookup_language_this (const struct language_defn *lang, lang->name (), host_address_to_string (block), objfile_debug_name (block->objfile ())); + lookup_name_info this_name (lang->name_of_this (), + symbol_name_match_type::SEARCH_NAME); + while (block) { struct symbol *sym; - sym = block_lookup_symbol (block, lang->name_of_this (), - symbol_name_match_type::SEARCH_NAME, - VAR_DOMAIN); + sym = block_lookup_symbol (block, this_name, VAR_DOMAIN); if (sym != NULL) { symbol_lookup_debug_printf_v @@ -2235,7 +2236,8 @@ lookup_symbol_in_block (const char *name, symbol_name_match_type match_type, domain_name (domain)); } - sym = block_lookup_symbol (block, name, match_type, domain); + lookup_name_info lookup_name (name, match_type); + sym = block_lookup_symbol (block, lookup_name, domain); if (sym) { symbol_lookup_debug_printf_v ("lookup_symbol_in_block (...) = %s", @@ -2409,7 +2411,8 @@ lookup_symbol_via_quick_fns (struct objfile *objfile, block_index == GLOBAL_BLOCK ? "GLOBAL_BLOCK" : "STATIC_BLOCK", name, domain_name (domain)); - cust = objfile->lookup_symbol (block_index, name, domain); + lookup_name_info lookup_name (name, symbol_name_match_type::FULL); + cust = objfile->lookup_symbol (block_index, lookup_name, domain); if (cust == NULL) { symbol_lookup_debug_printf_v @@ -2419,8 +2422,7 @@ lookup_symbol_via_quick_fns (struct objfile *objfile, bv = cust->blockvector (); block = bv->block (block_index); - result.symbol = block_lookup_symbol (block, name, - symbol_name_match_type::FULL, domain); + result.symbol = block_lookup_symbol (block, lookup_name, domain); if (result.symbol == NULL) error_in_psymtab_expansion (block_index, name, cust); @@ -2680,7 +2682,7 @@ lookup_transparent_type (const char *name) static struct type * basic_lookup_transparent_type_quick (struct objfile *objfile, enum block_enum block_index, - const char *name) + const lookup_name_info &name) { struct compunit_symtab *cust; const struct blockvector *bv; @@ -2694,10 +2696,9 @@ basic_lookup_transparent_type_quick (struct objfile *objfile, bv = cust->blockvector (); block = bv->block (block_index); - lookup_name_info lookup_name (name, symbol_name_match_type::FULL); - sym = block_find_symbol (block, lookup_name, STRUCT_DOMAIN, nullptr); + sym = block_find_symbol (block, name, STRUCT_DOMAIN, nullptr); if (sym == nullptr) - error_in_psymtab_expansion (block_index, name, cust); + error_in_psymtab_expansion (block_index, name.c_str (), cust); gdb_assert (!TYPE_IS_OPAQUE (sym->type ())); return sym->type (); } @@ -2709,18 +2710,17 @@ basic_lookup_transparent_type_quick (struct objfile *objfile, static struct type * basic_lookup_transparent_type_1 (struct objfile *objfile, enum block_enum block_index, - const char *name) + const lookup_name_info &name) { const struct blockvector *bv; const struct block *block; const struct symbol *sym; - lookup_name_info lookup_name (name, symbol_name_match_type::FULL); for (compunit_symtab *cust : objfile->compunits ()) { bv = cust->blockvector (); block = bv->block (block_index); - sym = block_find_symbol (block, lookup_name, STRUCT_DOMAIN, nullptr); + sym = block_find_symbol (block, name, STRUCT_DOMAIN, nullptr); if (sym != nullptr) { gdb_assert (!TYPE_IS_OPAQUE (sym->type ())); @@ -2742,6 +2742,8 @@ basic_lookup_transparent_type (const char *name) { struct type *t; + lookup_name_info lookup_name (name, symbol_name_match_type::FULL); + /* Now search all the global symbols. Do the symtab's first, then check the psymtab's. If a psymtab indicates the existence of the desired name as a global, then do psymtab-to-symtab @@ -2749,14 +2751,16 @@ basic_lookup_transparent_type (const char *name) for (objfile *objfile : current_program_space->objfiles ()) { - t = basic_lookup_transparent_type_1 (objfile, GLOBAL_BLOCK, name); + t = basic_lookup_transparent_type_1 (objfile, GLOBAL_BLOCK, + lookup_name); if (t) return t; } for (objfile *objfile : current_program_space->objfiles ()) { - t = basic_lookup_transparent_type_quick (objfile, GLOBAL_BLOCK, name); + t = basic_lookup_transparent_type_quick (objfile, GLOBAL_BLOCK, + lookup_name); if (t) return t; } @@ -2770,14 +2774,16 @@ basic_lookup_transparent_type (const char *name) for (objfile *objfile : current_program_space->objfiles ()) { - t = basic_lookup_transparent_type_1 (objfile, STATIC_BLOCK, name); + t = basic_lookup_transparent_type_1 (objfile, STATIC_BLOCK, + lookup_name); if (t) return t; } for (objfile *objfile : current_program_space->objfiles ()) { - t = basic_lookup_transparent_type_quick (objfile, STATIC_BLOCK, name); + t = basic_lookup_transparent_type_quick (objfile, STATIC_BLOCK, + lookup_name); if (t) return t; }