From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1805) id 9FD963858C83; Tue, 18 Oct 2022 13:25:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9FD963858C83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666099543; bh=2xm6Lblbf7vdNdknE0XO7uCEWpCp8g4X/h6/pE66utc=; h=From:To:Subject:Date:From; b=WzGifUWULnOxskMnzTtYeTtvM+CfTPdV8oMpplsWq17QQ4mZ//k5TE0+vU1TvLc4s sKaKoP3ZxcbobEvDMo6OD/YIgNsgFDw2mDx+3r+n61U7WnmhrLzpV4i36M4aMAivuI zgzwVPCL6enn90KS6NAZ9VqG4HEJpRUJqNgOME8Q= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Markus Metzger To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb, symtab: inline find_quick_global_symbol_language X-Act-Checkin: binutils-gdb X-Git-Author: Markus Metzger X-Git-Refname: refs/heads/master X-Git-Oldrev: 6f96c196beccb6f30b78ef878b3eaa420dfaa687 X-Git-Newrev: 531bd03892bbf95f346819006b365c0b0ccb6d06 Message-Id: <20221018132543.9FD963858C83@sourceware.org> Date: Tue, 18 Oct 2022 13:25:43 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D531bd03892bb= f95f346819006b365c0b0ccb6d06 commit 531bd03892bbf95f346819006b365c0b0ccb6d06 Author: Markus Metzger Date: Mon May 2 16:33:32 2022 +0200 gdb, symtab: inline find_quick_global_symbol_language =20 There is only one use of find_quick_global_symbol_language that calls it for the special symbol "main". =20 Inline the function as it is probably not correct in the general case where we may have multiple instances of global symbols with the same na= me but different languages in different libraries in different linker namespaces. =20 Further, change the objfiles iteration into a call to gdbarch_iterate_over_objfiles_in_search_order, which would only search = the initial linker namespace, where we expect "main" to be located. Diff: --- gdb/symtab.c | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/gdb/symtab.c b/gdb/symtab.c index 50ee87ee0a9..7bb32242c1b 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2610,23 +2610,6 @@ lookup_symbol_in_objfile (struct objfile *objfile, e= num block_enum block_index, return result; } =20 -/* Find the language for partial symbol with NAME. */ - -static enum language -find_quick_global_symbol_language (const char *name, const domain_enum dom= ain) -{ - for (objfile *objfile : current_program_space->objfiles ()) - { - bool symbol_found_p; - enum language lang - =3D objfile->lookup_global_symbol_language (name, domain, &symbol_found_p= ); - if (symbol_found_p) - return lang; - } - - return language_unknown; -} - /* This function contains the common code of lookup_{global,static}_symbol. OBJFILE is only used if BLOCK_INDEX is GLOBAL_SCOPE, in which case it is the objfile to start the lookup in. */ @@ -6367,13 +6350,25 @@ find_main_name (void) Fallback to "main". */ =20 /* Try to find language for main in psymtabs. */ - enum language lang - =3D find_quick_global_symbol_language ("main", VAR_DOMAIN); - if (lang !=3D language_unknown) - { - set_main_name ("main", lang); - return; - } + bool symbol_found_p =3D false; + gdbarch_iterate_over_objfiles_in_search_order + (target_gdbarch (), + [&symbol_found_p] (objfile *obj) + { + language lang + =3D obj->lookup_global_symbol_language ("main", VAR_DOMAIN, + &symbol_found_p); + if (symbol_found_p) + { + set_main_name ("main", lang); + return 1; + } + + return 0; + }, nullptr); + + if (symbol_found_p) + return; =20 set_main_name ("main", language_unknown); }