]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use 'flags' when expanding symtabs in gdbpy_lookup_static_symbols
authorTom Tromey <tom@tromey.com>
Thu, 19 Dec 2024 00:36:09 +0000 (17:36 -0700)
committerTom Tromey <tom@tromey.com>
Tue, 31 Dec 2024 20:35:38 +0000 (13:35 -0700)
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>
gdb/python/py-symbol.c
gdb/testsuite/gdb.python/py-symbol-3.c [new file with mode: 0644]
gdb/testsuite/gdb.python/py-symbol.c
gdb/testsuite/gdb.python/py-symbol.exp

index 8648a5073d08a2e9025e269830483495dc17aec5..f1ba0ba00e06349571eee1651835375ee7faea89 100644 (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 ())
        {
diff --git a/gdb/testsuite/gdb.python/py-symbol-3.c b/gdb/testsuite/gdb.python/py-symbol-3.c
new file mode 100644 (file)
index 0000000..6a95193
--- /dev/null
@@ -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;
index 57fce1ea8409c0fc2cdb11c46589ae814433202e..b6b2cd6edb17400e2a7dee9cd25e11fa0378ca1a 100644 (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)
 {
index c174ba4c70eb8137a4059564aa7b55dabe4a4ffd..e6411b4d16a01c252a331de6523eba26f1cfa8b7 100644 (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)"