From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 85D6C3858C5F for ; Fri, 4 Aug 2023 11:23:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 85D6C3858C5F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id BF05A1F8B0; Fri, 4 Aug 2023 11:23:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1691148182; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=bpnQCqcq6T8MxtM9L1Rb5oBU+WryQ3/05WTkIXw0cUk=; b=gIqFGiIfVJQHHGRmSeAyc2ny+SKubH3aPLMJoPB0bfaTyGmspIJpCnqOZNGs8GuxJ8vqbg +6v4bx9qzE8YEGkbZl5Q9kUHgkemHV9u2OzuzJ+6MHowjo7tfGZAEW+eE879zoXPnU7cgB bvb8H2N7gYdaoYLR7vs4EhoRj5+ecfs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1691148182; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=bpnQCqcq6T8MxtM9L1Rb5oBU+WryQ3/05WTkIXw0cUk=; b=/tr3jk/qzJgzWeFJWjAi7X/Ow4/cax8dbEoGSFG/VRt6az+Rc4isBc3H/WJcycX7XdVHPC 1Z7HPW7wUFo0CoCA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A726D133B5; Fri, 4 Aug 2023 11:23:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 5smvJ5bfzGQcUQAAMHmgww (envelope-from ); Fri, 04 Aug 2023 11:23:02 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] [gdb/symtab] Find main language without symtab expansion Date: Fri, 4 Aug 2023 13:22:43 +0200 Message-Id: <20230804112243.11537-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: When loading an executable using "file a.out", the language is set according to a.out, which can involve looking up the language of symbol "main", which will cause the symtab expansion for the containing CU. Expansion of lto debug info can be slow, so in commit d3214198119 ("[gdb] Use partial symbol table to find language for main") a feature was added to avoid the symtab expansion. This feature stopped working after commit 7f4307436fd ("Fix "start" for D, Rust, etc"). [ The commit addresses problems related to command start, which requires finding the main function: - for language D, "main" was found instead of "D main", and - for Rust, the correct function was found, but attributed the wrong name (not fully qualified). ] Reimplement the feature by adding cooked_index_functions::lookup_global_symbol_language. Tested on x86_64-linux. PR symtab/30661 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30661 --- gdb/dwarf2/read.c | 37 +++++++++++++++++++++++++++++++ gdb/testsuite/gdb.base/main-c.exp | 29 ++++++++++++++++++++++++ gdb/testsuite/gdb.cp/main-cp.exp | 29 ++++++++++++++++++++++++ gdb/testsuite/gdb.cp/main.cc | 22 ++++++++++++++++++ 4 files changed, 117 insertions(+) create mode 100644 gdb/testsuite/gdb.base/main-c.exp create mode 100644 gdb/testsuite/gdb.cp/main-cp.exp create mode 100644 gdb/testsuite/gdb.cp/main.cc diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 61730f6481c..9daea5725b9 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -16714,6 +16714,43 @@ struct cooked_index_functions : public dwarf2_base_index_functions if (dwarf2_has_info (objfile, nullptr)) dwarf2_build_psymtabs (objfile); } + + enum language lookup_global_symbol_language (struct objfile *objfile, + const char *name, + domain_enum domain, + bool *symbol_found_p) override + { + *symbol_found_p = false; + + if (!(domain == VAR_DOMAIN && streq (name, "main"))) + return language_unknown; + + dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); + struct dwarf2_per_bfd *per_bfd = per_objfile->per_bfd; + if (per_bfd->index_table == nullptr) + return language_unknown; + + /* Expansion of large CUs can be slow. By returning the language of main + here for C and C++, we avoid CU expansion during set_initial_language. + But by doing a symbol lookup in the cooked index, we are forced to wait + for finalization to complete. See PR symtab/30174 for ideas how to + bypass that as well. */ + cooked_index *table = per_bfd->index_table->index_for_writing (); + for (const cooked_index_entry *entry : table->find (name, false)) + { + if (entry->tag != DW_TAG_subprogram) + continue; + + enum language lang = entry->per_cu->lang (); + if (!(lang == language_c || lang == language_cplus)) + continue; + + *symbol_found_p = true; + return lang; + } + + return language_unknown; + } }; dwarf2_per_cu_data * diff --git a/gdb/testsuite/gdb.base/main-c.exp b/gdb/testsuite/gdb.base/main-c.exp new file mode 100644 index 00000000000..144b71918a7 --- /dev/null +++ b/gdb/testsuite/gdb.base/main-c.exp @@ -0,0 +1,29 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Check that finding main to set the current language doesn't cause any symtab +# to be expanded. + +standard_testfile main.c + +require !readnow + +if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } { + return -1 +} + +require {string eq [have_index $binfile] ""} + +gdb_test_no_output "maint info symtabs" diff --git a/gdb/testsuite/gdb.cp/main-cp.exp b/gdb/testsuite/gdb.cp/main-cp.exp new file mode 100644 index 00000000000..7404f39f254 --- /dev/null +++ b/gdb/testsuite/gdb.cp/main-cp.exp @@ -0,0 +1,29 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Check that finding main to set the current language doesn't cause any symtab +# to be expanded. + +standard_testfile main.cc + +require !readnow + +if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } { + return -1 +} + +require {string eq [have_index $binfile] ""} + +gdb_test_no_output "maint info symtabs" diff --git a/gdb/testsuite/gdb.cp/main.cc b/gdb/testsuite/gdb.cp/main.cc new file mode 100644 index 00000000000..c6beff77dbe --- /dev/null +++ b/gdb/testsuite/gdb.cp/main.cc @@ -0,0 +1,22 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2023 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +int +main (void) +{ + return 0; +} base-commit: 49459ed32b71aefd0443d82c939f05933505080e -- 2.35.3