aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2019-09-23 16:59:08 +0100
committerAndrew Burgess <andrew.burgess@embecosm.com>2019-11-10 21:35:28 +0000
commit09ff83af3c8558594bd31bfaf4ed7daadf4f707d (patch)
treeeebca5a0d285af21ced0622302c626e35373ffff /gdb/doc/python.texi
parentgdb: Add a class to track last display symtab and line information (diff)
downloadbinutils-gdb-09ff83af3c8558594bd31bfaf4ed7daadf4f707d.tar.gz
binutils-gdb-09ff83af3c8558594bd31bfaf4ed7daadf4f707d.tar.bz2
binutils-gdb-09ff83af3c8558594bd31bfaf4ed7daadf4f707d.zip
gdb/python: smarter symbol lookup for gdb.lookup_static_symbol
When using gdb.lookup_static_symbol I think that GDB should find static symbols (global symbol with static linkage) from the current object file ahead of static symbols from other object files. This means that if we have two source files f1.c and f2.c, and both files contains 'static int foo;', then when we are stopped in f1.c a call to 'gdb.lookup_static_symbol ("foo")' will find f1.c::foo, and if we are stopped in f2.c we would find 'f2.c::foo'. Given that gdb.lookup_static_symbol always returns a single symbol, but there can be multiple static symbols with the same name GDB is always making a choice about which symbols to return. I think that it makes sense for the choice GDB makes in this case to match what a user would get on the command line if they asked to 'print foo'. gdb/testsuite/ChangeLog: * gdb.python/py-symbol.c: Declare and call function from new py-symbol-2.c file. * gdb.python/py-symbol.exp: Compile both source files, and add new tests for gdb.lookup_static_symbol. * gdb.python/py-symbol-2.c: New file. gdb/doc/ChangeLog: * python.texi (Symbols In Python): Extend documentation for gdb.lookup_static_symbol. gdb/ChangeLog: * python/py-symbol.c (gdbpy_lookup_static_symbol): Lookup in static block of current object file first. Also fix typo in header comment. Change-Id: Ie55dbeb8806f35577b46015deecde27a0ca2ab64
Diffstat (limited to 'gdb/doc/python.texi')
-rw-r--r--gdb/doc/python.texi9
1 files changed, 9 insertions, 0 deletions
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index 13191fc9ae8..9e227deba90 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -4872,6 +4872,15 @@ Note that this function will not find function-scoped static variables. To look
up such variables, iterate over the variables of the function's
@code{gdb.Block} and check that @code{block.addr_class} is
@code{gdb.SYMBOL_LOC_STATIC}.
+
+There can be multiple global symbols with static linkage with the same
+name. This function will only return the first matching symbol that
+it finds. Which symbol is found depends on where @value{GDBN} is
+currently stopped, as @value{GDBN} will first search for matching
+symbols in the current object file, and then search all other object
+files. If the application is not yet running then @value{GDBN} will
+search all object files in the order they appear in the debug
+information.
@end defun
A @code{gdb.Symbol} object has the following attributes: