From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id A5B8A3959C23 for ; Mon, 30 Mar 2020 11:09:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A5B8A3959C23 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 901F5AF8A; Mon, 30 Mar 2020 11:09:02 +0000 (UTC) Subject: Re: [PATCH][gdb] Expand symbolless symtabs using maint expand-symtabs From: Tom de Vries To: gdb-patches@sourceware.org References: <20200329160050.GA24275@delia> Cc: Simon Marchi , Tom Tromey Autocrypt: addr=tdevries@suse.de; keydata= xsBNBF0ltCcBCADDhsUnMMdEXiHFfqJdXeRvgqSEUxLCy/pHek88ALuFnPTICTwkf4g7uSR7 HvOFUoUyu8oP5mNb4VZHy3Xy8KRZGaQuaOHNhZAT1xaVo6kxjswUi3vYgGJhFMiLuIHdApoc u5f7UbV+egYVxmkvVLSqsVD4pUgHeSoAcIlm3blZ1sDKviJCwaHxDQkVmSsGXImaAU+ViJ5l CwkvyiiIifWD2SoOuFexZyZ7RUddLosgsO0npVUYbl6dEMq2a5ijGF6/rBs1m3nAoIgpXk6P TCKlSWVW6OCneTaKM5C387972qREtiArTakRQIpvDJuiR2soGfdeJ6igGA1FZjU+IsM5ABEB AAHNH1RvbSBkZSBWcmllcyA8dGRldnJpZXNAc3VzZS5kZT7CwKsEEwEIAD4WIQSsnSe5hKbL MK1mGmjuhV2rbOJEoAUCXSW0JwIbAwUJA8JnAAULCQgHAgYVCgkICwIEFgIDAQIeAQIXgAAh CRDuhV2rbOJEoBYhBKydJ7mEpsswrWYaaO6FXats4kSgc48H/Ra2lq5p3dHsrlQLq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1ZtNS DUCSFQjqA6bEGwM22dP8OUY6SC94x1G81A9/xbtm9LQxKm0EiDH8KBMLfQ== Message-ID: Date: Mon, 30 Mar 2020 13:09:01 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200329160050.GA24275@delia> Content-Type: multipart/mixed; boundary="------------E748B3A43D8AC1AB2C286061" Content-Language: en-US X-Spam-Status: No, score=-32.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_DMARC_STATUS, KAM_SHORT, KAM_STOCKGEN, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP 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: Mon, 30 Mar 2020 11:09:06 -0000 This is a multi-part message in MIME format. --------------E748B3A43D8AC1AB2C286061 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit On 29-03-2020 18:00, Tom de Vries wrote: I realized that the copyright is missing in the added .c/.h files. Added. Also, I realized I could make the test-case work with target boards cc-with-gdb-index.exp and cc-with-debug-names.exp, by testing the output of "maint info symtabs" instead of "main info psymtabs". Updated accordingly. Also now handling target board readnow.exp, by marking the test unsupported. Updated and re-tested patch attached below. Thanks, - Tom --------------E748B3A43D8AC1AB2C286061 Content-Type: text/x-patch; charset=UTF-8; name="0001-gdb-Expand-symbolless-symtabs-using-maint-expand-symtabs.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename*0="0001-gdb-Expand-symbolless-symtabs-using-maint-expand-symtab"; filename*1="s.patch" [gdb] Expand symbolless symtabs using maint expand-symtabs Consider this test-case, consisting of header file hello.h: ... inline static const char* foo (void) { return "foo"; } ... and source file hello.c: ... int main (void) { printf ("hello: %s\n", foo ()); return 0; } ... compiled with -g: ... $ gcc hello.c -g ... When trying to expand the partial symtab for hello.h: ... $ gdb -batch \ -iex "set language c" \ a.out \ -ex "maint expand-symtabs hello.h" \ -ex "maint info psymtabs" ... we in fact find that the partial symtab has not been expanded: ... { psymtab hello.h ((struct partial_symtab *) 0x27cf070) readin no ... This is due to the recursively_search_psymtabs call in psym_expand_symtabs_matching: ... if (recursively_search_psymtabs (ps, objfile, domain, lookup_name, symbol_matcher)) ... which always returns false for symbolless partial symtabs. Fix this by passing a NULL symbol_matcher and lookup_name to expand_symtabs_matching in maintenance_expand_symtabs, and skipping the call to recursively_search_psymtabs if symbol_matcher == NULL and lookup_name == NULL. Build and tested on x86_64-linux, with native. In addition, tested test-case with target boards cc-with-gdb-index.exp, cc-with-debug-names.exp and readnow.exp. gdb/ChangeLog: 2020-03-29 Tom de Vries PR symtab/25720 * symmisc.c (maintenance_expand_symtabs): Call expand_symtabs_matching with NULL symbol_matcher and lookup_name. * psymtab.c (psym_expand_symtabs_matching): Handle NULL symbol_matcher and lookup_name. * dwarf2/read.c (dw2_expand_symtabs_matching) (dw2_debug_names_expand_symtabs_matching): Same. * symfile.h (struct quick_symbol_functions::expand_symtabs_matching): Make lookup_name a pointer. Update comment. * symtab.c (global_symbol_searcher::expand_symtabs): Handle lookup_name being a pointer. * symfile.c (expand_symtabs_matching): Same. * symfile-debug.c (debug_qf_expand_symtabs_matching): Same. * linespec.c (iterate_over_all_matching_symtabs): Same. gdb/testsuite/ChangeLog: 2020-03-29 Tom de Vries PR symtab/25720 * gdb.base/maint-expand-symbols-header-file.c: New test. * gdb.base/maint-expand-symbols-header-file.exp: New file. * gdb.base/maint-expand-symbols-header-file.h: New test. --- gdb/dwarf2/read.c | 32 +++++++++++++-- gdb/linespec.c | 2 +- gdb/psymtab.c | 10 ++--- gdb/symfile-debug.c | 2 +- gdb/symfile.c | 2 +- gdb/symfile.h | 13 +++--- gdb/symmisc.c | 8 +--- gdb/symtab.c | 2 +- .../gdb.base/maint-expand-symbols-header-file.c | 26 ++++++++++++ .../gdb.base/maint-expand-symbols-header-file.exp | 47 ++++++++++++++++++++++ .../gdb.base/maint-expand-symbols-header-file.h | 22 ++++++++++ 11 files changed, 142 insertions(+), 24 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 1ec5c1e582..673f2c2904 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -4543,7 +4543,7 @@ static void dw2_expand_symtabs_matching (struct objfile *objfile, gdb::function_view file_matcher, - const lookup_name_info &lookup_name, + const lookup_name_info *lookup_name, gdb::function_view symbol_matcher, gdb::function_view expansion_notify, enum search_domain kind) @@ -4557,9 +4557,21 @@ dw2_expand_symtabs_matching dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile, file_matcher); + if (symbol_matcher == NULL && lookup_name == NULL) + { + for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units) + { + QUIT; + + dw2_expand_symtabs_matching_one (per_cu, file_matcher, + expansion_notify); + } + return; + } + mapped_index &index = *dwarf2_per_objfile->index_table; - dw2_expand_symtabs_matching_symbol (index, lookup_name, + dw2_expand_symtabs_matching_symbol (index, *lookup_name, symbol_matcher, kind, [&] (offset_type idx) { @@ -5551,7 +5563,7 @@ static void dw2_debug_names_expand_symtabs_matching (struct objfile *objfile, gdb::function_view file_matcher, - const lookup_name_info &lookup_name, + const lookup_name_info *lookup_name, gdb::function_view symbol_matcher, gdb::function_view expansion_notify, enum search_domain kind) @@ -5565,9 +5577,21 @@ dw2_debug_names_expand_symtabs_matching dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile, file_matcher); + if (symbol_matcher == NULL && lookup_name == NULL) + { + for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units) + { + QUIT; + + dw2_expand_symtabs_matching_one (per_cu, file_matcher, + expansion_notify); + } + return; + } + mapped_debug_names &map = *dwarf2_per_objfile->debug_names_table; - dw2_expand_symtabs_matching_symbol (map, lookup_name, + dw2_expand_symtabs_matching_symbol (map, *lookup_name, symbol_matcher, kind, [&] (offset_type namei) { diff --git a/gdb/linespec.c b/gdb/linespec.c index d853e02d8f..e1349e78a0 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -1149,7 +1149,7 @@ iterate_over_all_matching_symtabs if (objfile->sf) objfile->sf->qf->expand_symtabs_matching (objfile, NULL, - lookup_name, + &lookup_name, NULL, NULL, search_domain); diff --git a/gdb/psymtab.c b/gdb/psymtab.c index 56c1b68b54..1399edbfa7 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -1301,13 +1301,11 @@ static void psym_expand_symtabs_matching (struct objfile *objfile, gdb::function_view file_matcher, - const lookup_name_info &lookup_name_in, + const lookup_name_info *lookup_name, gdb::function_view symbol_matcher, gdb::function_view expansion_notify, enum search_domain domain) { - lookup_name_info lookup_name = lookup_name_in.make_ignore_params (); - /* Clear the search flags. */ for (partial_symtab *ps : require_partial_symbols (objfile, true)) ps->searched_flag = PST_NOT_SEARCHED; @@ -1344,8 +1342,10 @@ psym_expand_symtabs_matching continue; } - if (recursively_search_psymtabs (ps, objfile, domain, - lookup_name, symbol_matcher)) + if ((symbol_matcher == NULL && lookup_name == NULL) + || recursively_search_psymtabs (ps, objfile, domain, + lookup_name->make_ignore_params (), + symbol_matcher)) { struct compunit_symtab *symtab = psymtab_to_symtab (objfile, ps); diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c index 53a77a5405..60489dbfa5 100644 --- a/gdb/symfile-debug.c +++ b/gdb/symfile-debug.c @@ -254,7 +254,7 @@ static void debug_qf_expand_symtabs_matching (struct objfile *objfile, gdb::function_view file_matcher, - const lookup_name_info &lookup_name, + const lookup_name_info *lookup_name, gdb::function_view symbol_matcher, gdb::function_view expansion_notify, enum search_domain kind) diff --git a/gdb/symfile.c b/gdb/symfile.c index 3b63887ce1..8b29516b4e 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -3786,7 +3786,7 @@ expand_symtabs_matching { if (objfile->sf) objfile->sf->qf->expand_symtabs_matching (objfile, file_matcher, - lookup_name, + &lookup_name, symbol_matcher, expansion_notify, kind); } diff --git a/gdb/symfile.h b/gdb/symfile.h index 85f8e7c155..68b1813ec5 100644 --- a/gdb/symfile.h +++ b/gdb/symfile.h @@ -242,11 +242,14 @@ struct quick_symbol_functions names (the passed file name is already only the lbasename'd part). - Otherwise, if KIND does not match, this symbol is skipped. + If the file is not skipped, and SYMBOL_MATCHER and LOOKUP_NAME are NULL, + the symbol table is expanded. - If even KIND matches, SYMBOL_MATCHER is called for each symbol - defined in the file. The symbol "search" name is passed to - SYMBOL_MATCHER. + Otherwise, individual symbols are considered. + + If KIND does not match, the symbol is skipped. + + If the symbol name does not match LOOKUP_NAME, the symbol is skipped. If SYMBOL_MATCHER returns false, then the symbol is skipped. @@ -254,7 +257,7 @@ struct quick_symbol_functions void (*expand_symtabs_matching) (struct objfile *objfile, gdb::function_view file_matcher, - const lookup_name_info &lookup_name, + const lookup_name_info *lookup_name, gdb::function_view symbol_matcher, gdb::function_view expansion_notify, enum search_domain kind); diff --git a/gdb/symmisc.c b/gdb/symmisc.c index bee136ed46..1076a0bcaf 100644 --- a/gdb/symmisc.c +++ b/gdb/symmisc.c @@ -977,12 +977,8 @@ maintenance_expand_symtabs (const char *args, int from_tty) return (!basenames && (regexp == NULL || re_exec (filename))); }, - lookup_name_info::match_any (), - [] (const char *symname) - { - /* Since we're not searching on symbols, just return true. */ - return true; - }, + NULL, + NULL, NULL, ALL_DOMAIN); } diff --git a/gdb/symtab.c b/gdb/symtab.c index f300d759e0..073b76db2d 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -4513,7 +4513,7 @@ global_symbol_searcher::expand_symtabs { return file_matches (filename, filenames, basenames); }, - lookup_name_info::match_any (), + &lookup_name_info::match_any (), [&] (const char *symname) { return (!preg.has_value () diff --git a/gdb/testsuite/gdb.base/maint-expand-symbols-header-file.c b/gdb/testsuite/gdb.base/maint-expand-symbols-header-file.c new file mode 100644 index 0000000000..649c5b97c5 --- /dev/null +++ b/gdb/testsuite/gdb.base/maint-expand-symbols-header-file.c @@ -0,0 +1,26 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2020 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 . */ + +#include +#include "maint-expand-symbols-header-file.h" + +int +main (void) +{ + printf ("hello: %s\n", foo ()); + return 0; +} diff --git a/gdb/testsuite/gdb.base/maint-expand-symbols-header-file.exp b/gdb/testsuite/gdb.base/maint-expand-symbols-header-file.exp new file mode 100644 index 0000000000..85376662df --- /dev/null +++ b/gdb/testsuite/gdb.base/maint-expand-symbols-header-file.exp @@ -0,0 +1,47 @@ +# Copyright 2020 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 . +# +# Test-case to verify that symbol-less symtabs are expanded by +# "maint expand-symtabs". + +standard_testfile .c + +if {[build_executable "failed to prepare" $testfile \ + $srcfile {debug nowarnings}]} { + return -1 +} + +clean_restart + +# Make sure that no symtabs are expanded, by setting language before +# loading exec. +gdb_test_no_output "set language c" +gdb_load ${binfile} + +set test "verify no symtabs are expanded" +if { [readnow] } { + unsupported $test + return -1 +} +gdb_test_no_output "maint info symtabs" $test + +# Expand the header file symtab. +gdb_test_no_output "maint expand-symtabs maint-expand-symbols-header-file.h" + +# Check that the header file symtab was in fact expanded. +set file_re "\[^\r\n\]*/maint-expand-symbols-header-file.h" +gdb_test "maint info symtabs" \ + "\r\n\t{ symtab $file_re \\(\\(struct symtab \\*\\) $hex\\)\r\n.*" \ + "check header file psymtab expansion" diff --git a/gdb/testsuite/gdb.base/maint-expand-symbols-header-file.h b/gdb/testsuite/gdb.base/maint-expand-symbols-header-file.h new file mode 100644 index 0000000000..d8d2517c7b --- /dev/null +++ b/gdb/testsuite/gdb.base/maint-expand-symbols-header-file.h @@ -0,0 +1,22 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2020 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 . */ + +inline static const char* +foo (void) +{ + return "foo"; +} --------------E748B3A43D8AC1AB2C286061--