From: Tom Tromey Date: Thu, 19 Dec 2024 00:36:09 +0000 (-0700) Subject: Use 'flags' when expanding symtabs in gdbpy_lookup_static_symbols X-Git-Tag: binutils-2_44~305 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1c7d9f96cb5c91e43d6ed9fb9081b9c94d06e548;p=thirdparty%2Fbinutils-gdb.git 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 --- diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c index 8648a5073d0..f1ba0ba00e0 100644 --- a/gdb/python/py-symbol.c +++ b/gdb/python/py-symbol.c @@ -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 ()) { diff --git a/gdb/testsuite/gdb.python/py-symbol-3.c b/gdb/testsuite/gdb.python/py-symbol-3.c new file mode 100644 index 00000000000..6a951934fe7 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-symbol-3.c @@ -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 . */ + +/* A global 'rr' -- used for testing that lookup_static_symbols does + not find it. */ +int __attribute__ ((used)) rr = 107; diff --git a/gdb/testsuite/gdb.python/py-symbol.c b/gdb/testsuite/gdb.python/py-symbol.c index 57fce1ea840..b6b2cd6edb1 100644 --- a/gdb/testsuite/gdb.python/py-symbol.c +++ b/gdb/testsuite/gdb.python/py-symbol.c @@ -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) { diff --git a/gdb/testsuite/gdb.python/py-symbol.exp b/gdb/testsuite/gdb.python/py-symbol.exp index c174ba4c70e..e6411b4d16a 100644 --- a/gdb/testsuite/gdb.python/py-symbol.exp +++ b/gdb/testsuite/gdb.python/py-symbol.exp @@ -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)"