From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 70D5638654AD; Thu, 15 Feb 2024 17:31:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 70D5638654AD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1708018279; bh=hG/x3BQQLoe3TGUaWgWQlSAD0rLNTjdqTzTUi4k9dzM=; h=From:To:Subject:Date:From; b=SneM6QvpgQFLRBAI9+k+v0IMzTqFDbGyXf/4p/XRg3h9EyY0Fp8ywXauMGeFU9TGk Ursi64QFpr47h0VXZxUvEZq5EWxu1lpUJ/68n9559oU4hO+EXtAfmEJC3ft44NGZKy kO9oZiKAQXtGH/r+a1B375TSOHEkByxaKT69PtMY= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Move lookup_name_info creation into basic_lookup_transparent_type X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 7921285b6c2ba0bee9bb21d8e23fdea4c790c181 X-Git-Newrev: e70d6457a648c25d4382bcc030e9f5a94f3ca189 Message-Id: <20240215173119.70D5638654AD@sourceware.org> Date: Thu, 15 Feb 2024 17:31:19 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3De70d6457a648= c25d4382bcc030e9f5a94f3ca189 commit e70d6457a648c25d4382bcc030e9f5a94f3ca189 Author: Tom Tromey Date: Thu Jan 25 11:17:24 2024 -0700 Move lookup_name_info creation into basic_lookup_transparent_type =20 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. =20 There are still more changes of this sort that could be made. =20 Regression tested on x86-64 Fedora 38. Diff: --- gdb/block.c | 9 +++----- gdb/block.h | 3 +-- gdb/compile/compile-object-load.c | 13 ++++++------ gdb/objfiles.h | 3 ++- gdb/psymtab.c | 10 +++++---- gdb/symfile-debug.c | 10 ++++----- gdb/symtab.c | 43 ++++++++++++++++++++++-------------= ---- 7 files changed, 46 insertions(+), 45 deletions(-) diff --git a/gdb/block.c b/gdb/block.c index 0bdd0f915c0..079053cd79e 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -679,17 +679,14 @@ better_symbol (struct symbol *a, struct symbol *b, non-encoded names tested for a match. */ =20 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 &na= me, const domain_search_flags domain) { - lookup_name_info lookup_name (name, match_type); - if (!block->function ()) { struct symbol *other =3D NULL; =20 - 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. */ @@ -717,7 +714,7 @@ block_lookup_symbol (const struct block *block, const c= har *name, =20 struct symbol *sym_found =3D NULL; =20 - 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 0c121941f05..00630123120 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. */ =20 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_search_flags domain); =20 /* 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 e26f0f46048..33971a51a71 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 ob= jfile *objfile, =20 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); =20 bv =3D func_sym->symtab ()->compunit ()->blockvector (); nblocks =3D bv->num_blocks (); @@ -434,10 +438,7 @@ get_out_value_type (struct symbol *func_sym, struct ob= jfile *objfile, block =3D bv->block (block_loop); if (block->function () !=3D NULL) continue; - gdb_val_sym =3D block_lookup_symbol (block, - COMPILE_I_EXPR_VAL, - symbol_name_match_type::SEARCH_NAME, - SEARCH_VFT); + gdb_val_sym =3D block_lookup_symbol (block, i_val_matcher, SEARCH_VF= T); if (gdb_val_sym =3D=3D NULL) continue; =20 @@ -461,9 +462,7 @@ get_out_value_type (struct symbol *func_sym, struct obj= file *objfile, gdb_type =3D gdb_val_sym->type (); gdb_type =3D check_typedef (gdb_type); =20 - gdb_ptr_type_sym =3D block_lookup_symbol (block, COMPILE_I_EXPR_PTR_TYPE, - symbol_name_match_type::SEARCH_NAME, - SEARCH_VFT); + gdb_ptr_type_sym =3D block_lookup_symbol (block, i_ptr_matcher, SEARCH_V= FT); if (gdb_ptr_type_sym =3D=3D NULL) error (_("No \"%s\" symbol found"), COMPILE_I_EXPR_PTR_TYPE); gdb_ptr_type =3D gdb_ptr_type_sym->type (); diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 98e2355f7a9..7ed23224ba8 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -561,7 +561,8 @@ public: 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_search_flags domain); =20 /* See quick_symbol_functions. */ diff --git a/gdb/psymtab.c b/gdb/psymtab.c index cb7a397afb1..334a9417055 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -1505,8 +1505,9 @@ maintenance_check_psymtabs (const char *ignore, int f= rom_tty) && psym->ginfo.value_address () =3D=3D 0) continue; =20 - sym =3D block_lookup_symbol (b, psym->ginfo.search_name (), - symbol_name_match_type::SEARCH_NAME, + lookup_name_info lookup_name + (psym->ginfo.search_name (), symbol_name_match_type::SEARCH_NAME); + sym =3D block_lookup_symbol (b, lookup_name, to_search_flags (psym->domain)); if (!sym) { @@ -1520,8 +1521,9 @@ maintenance_check_psymtabs (const char *ignore, int f= rom_tty) b =3D bv->global_block (); for (partial_symbol *psym : ps->global_psymbols) { - sym =3D block_lookup_symbol (b, psym->ginfo.search_name (), - symbol_name_match_type::SEARCH_NAME, + lookup_name_info lookup_name + (psym->ginfo.search_name (), symbol_name_match_type::SEARCH_NAME); + sym =3D block_lookup_symbol (b, lookup_name, to_search_flags (psym->domain)); if (!sym) { diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c index 36719fccabe..3955298b1fe 100644 --- a/gdb/symfile-debug.c +++ b/gdb/symfile-debug.c @@ -240,7 +240,7 @@ objfile::map_symtabs_matching_filename } =20 struct compunit_symtab * -objfile::lookup_symbol (block_enum kind, const char *name, +objfile::lookup_symbol (block_enum kind, const lookup_name_info &name, domain_search_flags domain) { struct compunit_symtab *retval =3D nullptr; @@ -248,18 +248,16 @@ objfile::lookup_symbol (block_enum kind, const char *= name, 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).c_str ()); =20 - lookup_name_info lookup_name (name, symbol_name_match_type::FULL); - auto search_one_symtab =3D [&] (compunit_symtab *stab) { struct symbol *sym, *with_opaque =3D NULL; const struct blockvector *bv =3D stab->blockvector (); const struct block *block =3D bv->block (kind); =20 - sym =3D block_find_symbol (block, lookup_name, domain, &with_opaque); + sym =3D block_find_symbol (block, name, domain, &with_opaque); =20 /* Some caution must be observed with overloaded functions and methods, since the index will not contain any overload @@ -282,7 +280,7 @@ objfile::lookup_symbol (block_enum kind, const char *na= me, { if (!iter->expand_symtabs_matching (this, nullptr, - &lookup_name, + &name, nullptr, search_one_symtab, kind =3D=3D GLOBAL_BLOCK diff --git a/gdb/symtab.c b/gdb/symtab.c index 02f5d4f1b3d..cd2bc8f2e21 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2023,13 +2023,14 @@ lookup_language_this (const struct language_defn *l= ang, lang->name (), host_address_to_string (block), objfile_debug_name (block->objfile ())); =20 + lookup_name_info this_name (lang->name_of_this (), + symbol_name_match_type::SEARCH_NAME); + while (block) { struct symbol *sym; =20 - sym =3D block_lookup_symbol (block, lang->name_of_this (), - symbol_name_match_type::SEARCH_NAME, - SEARCH_VFT); + sym =3D block_lookup_symbol (block, this_name, SEARCH_VFT); if (sym !=3D NULL) { symbol_lookup_debug_printf_v @@ -2264,7 +2265,8 @@ lookup_symbol_in_block (const char *name, symbol_name= _match_type match_type, domain_name (domain).c_str ()); } =20 - sym =3D block_lookup_symbol (block, name, match_type, domain); + lookup_name_info lookup_name (name, match_type); + sym =3D block_lookup_symbol (block, lookup_name, domain); if (sym) { symbol_lookup_debug_printf_v ("lookup_symbol_in_block (...) =3D %s", @@ -2438,7 +2440,8 @@ lookup_symbol_via_quick_fns (struct objfile *objfile, block_index =3D=3D GLOBAL_BLOCK ? "GLOBAL_BLOCK" : "STATIC_BLOCK", name, domain_name (domain).c_str ()); =20 - cust =3D objfile->lookup_symbol (block_index, name, domain); + lookup_name_info lookup_name (name, symbol_name_match_type::FULL); + cust =3D objfile->lookup_symbol (block_index, lookup_name, domain); if (cust =3D=3D NULL) { symbol_lookup_debug_printf_v @@ -2448,8 +2451,7 @@ lookup_symbol_via_quick_fns (struct objfile *objfile, =20 bv =3D cust->blockvector (); block =3D bv->block (block_index); - result.symbol =3D block_lookup_symbol (block, name, - symbol_name_match_type::FULL, domain); + result.symbol =3D block_lookup_symbol (block, lookup_name, domain); if (result.symbol =3D=3D NULL) error_in_psymtab_expansion (block_index, name, cust); =20 @@ -2703,7 +2705,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; @@ -2717,10 +2719,9 @@ basic_lookup_transparent_type_quick (struct objfile = *objfile, bv =3D cust->blockvector (); block =3D bv->block (block_index); =20 - lookup_name_info lookup_name (name, symbol_name_match_type::FULL); - sym =3D block_find_symbol (block, lookup_name, SEARCH_STRUCT_DOMAIN, nul= lptr); + sym =3D block_find_symbol (block, name, SEARCH_STRUCT_DOMAIN, nullptr); if (sym =3D=3D 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 (); } @@ -2732,19 +2733,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; =20 - lookup_name_info lookup_name (name, symbol_name_match_type::FULL); for (compunit_symtab *cust : objfile->compunits ()) { bv =3D cust->blockvector (); block =3D bv->block (block_index); - sym =3D block_find_symbol (block, lookup_name, SEARCH_STRUCT_DOMAIN, - nullptr); + sym =3D block_find_symbol (block, name, SEARCH_STRUCT_DOMAIN, nullpt= r); if (sym !=3D nullptr) { gdb_assert (!TYPE_IS_OPAQUE (sym->type ())); @@ -2766,6 +2765,8 @@ basic_lookup_transparent_type (const char *name) { struct type *t; =20 + 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 @@ -2773,14 +2774,16 @@ basic_lookup_transparent_type (const char *name) =20 for (objfile *objfile : current_program_space->objfiles ()) { - t =3D basic_lookup_transparent_type_1 (objfile, GLOBAL_BLOCK, name); + t =3D basic_lookup_transparent_type_1 (objfile, GLOBAL_BLOCK, + lookup_name); if (t) return t; } =20 for (objfile *objfile : current_program_space->objfiles ()) { - t =3D basic_lookup_transparent_type_quick (objfile, GLOBAL_BLOCK, na= me); + t =3D basic_lookup_transparent_type_quick (objfile, GLOBAL_BLOCK, + lookup_name); if (t) return t; } @@ -2794,14 +2797,16 @@ basic_lookup_transparent_type (const char *name) =20 for (objfile *objfile : current_program_space->objfiles ()) { - t =3D basic_lookup_transparent_type_1 (objfile, STATIC_BLOCK, name); + t =3D basic_lookup_transparent_type_1 (objfile, STATIC_BLOCK, + lookup_name); if (t) return t; } =20 for (objfile *objfile : current_program_space->objfiles ()) { - t =3D basic_lookup_transparent_type_quick (objfile, STATIC_BLOCK, na= me); + t =3D basic_lookup_transparent_type_quick (objfile, STATIC_BLOCK, + lookup_name); if (t) return t; }