Use 'flags' when expanding symtabs in gdbpy_lookup_static_symbols

This changes gdbpy_lookup_static_symbols to pass the 'flags' parameter
to expand_symtabs_matching.  This should refine the search somewhat.
Note this is "just" a performance improvement, as the loop over
symtabs already checks 'flags'.

v2 also removes 'SEARCH_GLOBAL_BLOCK' and updates py-symbol.exp to
verify that this works properly.  Thanks to Tom for this insight.

Co-Authored-By: Tom de Vries <tdevries@suse.de>
This commit is contained in:
Tom Tromey
2024-12-18 17:36:09 -07:00
parent 0f68254da9
commit 1c7d9f96cb
4 changed files with 32 additions and 5 deletions

View File

@@ -610,8 +610,7 @@ gdbpy_lookup_static_symbols (PyObject *self, PyObject *args, PyObject *kw)
/* Expand any symtabs that contain potentially matching symbols. */
lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
expand_symtabs_matching (NULL, lookup_name, NULL, NULL,
SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK,
SEARCH_ALL_DOMAINS);
SEARCH_STATIC_BLOCK, flags);
for (objfile *objfile : current_program_space->objfiles ())
{

View File

@@ -0,0 +1,20 @@
/* This testcase is part of GDB, the GNU debugger.
Copyright 2024 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 <http://www.gnu.org/licenses/>. */
/* A global 'rr' -- used for testing that lookup_static_symbols does
not find it. */
int __attribute__ ((used)) rr = 107;

View File

@@ -44,6 +44,7 @@ extern void function_in_other_file (void);
int qq = 72; /* line of qq */
static int __attribute__ ((used)) rr = 42; /* line of rr */
static int __attribute__ ((used)) qqrr = 42;
int func (int arg)
{

View File

@@ -20,11 +20,11 @@ load_lib gdb-python.exp
require allow_python_tests
standard_testfile py-symbol.c py-symbol-2.c
standard_testfile py-symbol.c py-symbol-2.c py-symbol-3.c
set opts { debug additional_flags=-DUSE_TWO_FILES }
if {[prepare_for_testing "failed to prepare" $testfile \
[list $srcfile $srcfile2] $opts]} {
[list $srcfile $srcfile2 $srcfile3] $opts]} {
return -1
}
@@ -36,6 +36,13 @@ set readnow_p [readnow]
gdb_test "python print (len (gdb.lookup_static_symbols ('rr')))" \
"2" "print (len (gdb.lookup_static_symbols ('rr')))"
# This test does not make sense when readnow is in effect.
if {!$readnow_p} {
# Make sure that the global symbol's symtab was not expanded.
gdb_test_no_output "pipe maint info symtab | grep \"name.*py-symbol-3.c\"" \
"global rr symtab was not expanded"
}
# Restart so we don't have expanded symtabs after the previous test.
clean_restart ${binfile}
@@ -65,7 +72,7 @@ gdb_test "python print (gdb.lookup_global_symbol('qq').needs_frame)" \
# Similarly, test looking up a static symbol before we runto_main.
set rr_line [gdb_get_line_number "line of rr"]
set rr_line_alt [gdb_get_line_number "line of other rr" py-symbol-2.c]
gdb_test "python print (gdb.lookup_global_symbol ('rr') is None)" "True" \
gdb_test "python print (gdb.lookup_global_symbol ('qqrr') is None)" "True" \
"lookup_global_symbol for static var"
set cmd "python print (gdb.lookup_static_symbol ('rr').line)"