gdb/python: Introduce gdb.lookup_static_symbols

If gdb.lookup_static_symbol is going to return a single symbol then it
makes sense (I think) for it to return a context sensitive choice of
symbol, that is the global static symbol that would be visible to the
program at that point.

However, if the user of the python API wants to instead get a
consistent set of global static symbols, no matter where they stop,
then they have to instead consider all global static symbols with a
given name - there could be many.  That is what this new API function
offers, it returns a list (possibly empty) of all global static
symbols matching a given name (and optionally a given symbol domain).

gdb/ChangeLog:

	* python/py-symbol.c (gdbpy_lookup_static_symbols): New
	function.
	* python/python-internal.h (gdbpy_lookup_static_symbols):
	Declare new function.
	* python/python.c (python_GdbMethods): Add
	gdb.lookup_static_symbols method.
	* NEWS: Mention gdb.lookup_static_symbols.

gdb/testsuite/ChangeLog:

	* gdb.python/py-symbol.exp: Add test for
	gdb.lookup_static_symbols.

gdb/doc/ChangeLog:

	* python.texi (Symbols In Python): Add documentation for
	gdb.lookup_static_symbols.

Change-Id: I1153b0ae5bcbc43b3dcf139043c7a48bf791e1a3
This commit is contained in:
Andrew Burgess 2019-10-15 16:18:26 +01:00
parent 09ff83af3c
commit 086baaf134
9 changed files with 142 additions and 0 deletions

View file

@ -4883,6 +4883,41 @@ search all object files in the order they appear in the debug
information.
@end defun
@findex gdb.lookup_global_symbol
@defun gdb.lookup_global_symbol (name @r{[}, domain@r{]})
This function searches for a global symbol by name.
The search scope can be restricted to by the domain argument.
@var{name} is the name of the symbol. It must be a string.
The optional @var{domain} argument restricts the search to the domain type.
The @var{domain} argument must be a domain constant defined in the @code{gdb}
module and described later in this chapter.
The result is a @code{gdb.Symbol} object or @code{None} if the symbol
is not found.
@end defun
@findex gdb.lookup_static_symbols
@defun gdb.lookup_static_symbols (name @r{[}, domain@r{]})
Similar to @code{gdb.lookup_static_symbol}, this function searches for
global symbols with static linkage by name, and optionally restricted
by the domain argument. However, this function returns a list of all
matching symbols found, not just the first one.
@var{name} is the name of the symbol. It must be a string.
The optional @var{domain} argument restricts the search to the domain type.
The @var{domain} argument must be a domain constant defined in the @code{gdb}
module and described later in this chapter.
The result is a list of @code{gdb.Symbol} objects which could be empty
if no matching symbols were found.
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}.
@end defun
A @code{gdb.Symbol} object has the following attributes:
@defvar Symbol.type