Next: Symbol Tables In Python, Previous: Blocks In Python, Up: Python API
gdb represents every variable, function and type as an
entry in a symbol table. See Examining the Symbol Table.
Similarly, Python represents these symbols in gdb with the
gdb.Symbol
object.
The following symbol-related functions are available in the gdb
module:
This function searches for a symbol by name. The search scope can be restricted to the parameters defined in the optional domain and block arguments.
name is the name of the symbol. It must be a string. The optional block argument restricts the search to symbols visible in that block. The block argument must be a
gdb.Block
object. If omitted, the block for the current frame is used. The optional domain argument restricts the search to the domain type. The domain argument must be a domain constant defined in thegdb
module and described later in this chapter.The result is a tuple of two elements. The first element is a
gdb.Symbol
object orNone
if the symbol is not found. If the symbol is found, the second element isTrue
if the symbol is a field of a method's object (e.g.,this
in C++), otherwise it isFalse
. If the symbol is not found, the second element isFalse
.
This function searches for a global symbol by name. The search scope can be restricted to by the domain argument.
name is the name of the symbol. It must be a string. The optional domain argument restricts the search to the domain type. The domain argument must be a domain constant defined in the
gdb
module and described later in this chapter.The result is a
gdb.Symbol
object orNone
if the symbol is not found.
A gdb.Symbol
object has the following attributes:
The type of the symbol or
None
if no type is recorded. This attribute is represented as agdb.Type
object. See Types In Python. This attribute is not writable.
The symbol table in which the symbol appears. This attribute is represented as a
gdb.Symtab
object. See Symbol Tables In Python. This attribute is not writable.
The line number in the source code at which the symbol was defined. This is an integer.
The name of the symbol, as used by the linker (i.e., may be mangled). This attribute is not writable.
The name of the symbol in a form suitable for output. This is either
name
orlinkage_name
, depending on whether the user asked gdb to display demangled or mangled names.
The address class of the symbol. This classifies how to find the value of a symbol. Each address class is a constant defined in the
gdb
module and described later in this chapter.
This is
True
if evaluating this symbol's value requires a frame (see Frames In Python) andFalse
otherwise. Typically, local variables will require a frame, but other symbols will not.
A gdb.Symbol
object has the following methods:
Returns
True
if thegdb.Symbol
object is valid,False
if not. Agdb.Symbol
object can become invalid if the symbol it refers to does not exist in gdb any longer. All othergdb.Symbol
methods will throw an exception if it is invalid at the time the method is called.
Compute the value of the symbol, as a
gdb.Value
. For functions, this computes the address of the function, cast to the appropriate type. If the symbol requires a frame in order to compute its value, then frame must be given. If frame is not given, or if frame is invalid, then this method will throw an exception.
The available domain categories in gdb.Symbol
are represented
as constants in the gdb
module:
gdb.SYMBOL_UNDEF_DOMAIN
gdb.SYMBOL_VAR_DOMAIN
gdb.SYMBOL_STRUCT_DOMAIN
gdb.SYMBOL_LABEL_DOMAIN
gdb.SYMBOL_VARIABLES_DOMAIN
SYMBOLS_VAR_DOMAIN
; it
contains everything minus functions and types.
gdb.SYMBOL_FUNCTION_DOMAIN
gdb.SYMBOL_TYPES_DOMAIN
The available address class categories in gdb.Symbol
are represented
as constants in the gdb
module:
gdb.SYMBOL_LOC_UNDEF
gdb.SYMBOL_LOC_CONST
gdb.SYMBOL_LOC_STATIC
gdb.SYMBOL_LOC_REGISTER
gdb.SYMBOL_LOC_ARG
gdb.SYMBOL_LOC_REF_ARG
LOC_ARG
except that the value's address is stored at the
offset, not the value itself.
gdb.SYMBOL_LOC_REGPARM_ADDR
LOC_REGISTER
except
the register holds the address of the argument instead of the argument
itself.
gdb.SYMBOL_LOC_LOCAL
gdb.SYMBOL_LOC_TYPEDEF
SYMBOL_STRUCT_DOMAIN
all
have this class.
gdb.SYMBOL_LOC_BLOCK
gdb.SYMBOL_LOC_CONST_BYTES
gdb.SYMBOL_LOC_UNRESOLVED
gdb.SYMBOL_LOC_OPTIMIZED_OUT
gdb.SYMBOL_LOC_COMPUTED