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.Blockobject. 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 thegdbmodule and described later in this chapter.The result is a tuple of two elements. The first element is a
gdb.Symbolobject orNoneif the symbol is not found. If the symbol is found, the second element isTrueif the symbol is a field of a method's object (e.g.,thisin 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
gdbmodule and described later in this chapter.The result is a
gdb.Symbolobject orNoneif the symbol is not found.
A gdb.Symbol object has the following attributes:
The type of the symbol or
Noneif no type is recorded. This attribute is represented as agdb.Typeobject. See Types In Python. This attribute is not writable.
The symbol table in which the symbol appears. This attribute is represented as a
gdb.Symtabobject. 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
nameorlinkage_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
gdbmodule and described later in this chapter.
This is
Trueif evaluating this symbol's value requires a frame (see Frames In Python) andFalseotherwise. Typically, local variables will require a frame, but other symbols will not.
A gdb.Symbol object has the following methods:
Returns
Trueif thegdb.Symbolobject is valid,Falseif not. Agdb.Symbolobject can become invalid if the symbol it refers to does not exist in gdb any longer. All othergdb.Symbolmethods 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_DOMAINgdb.SYMBOL_VAR_DOMAINgdb.SYMBOL_STRUCT_DOMAINgdb.SYMBOL_LABEL_DOMAINgdb.SYMBOL_VARIABLES_DOMAINSYMBOLS_VAR_DOMAIN; it
contains everything minus functions and types.
gdb.SYMBOL_FUNCTION_DOMAINgdb.SYMBOL_TYPES_DOMAINThe available address class categories in gdb.Symbol are represented
as constants in the gdb module:
gdb.SYMBOL_LOC_UNDEFgdb.SYMBOL_LOC_CONSTgdb.SYMBOL_LOC_STATICgdb.SYMBOL_LOC_REGISTERgdb.SYMBOL_LOC_ARGgdb.SYMBOL_LOC_REF_ARGLOC_ARG except that the value's address is stored at the
offset, not the value itself.
gdb.SYMBOL_LOC_REGPARM_ADDRLOC_REGISTER except
the register holds the address of the argument instead of the argument
itself.
gdb.SYMBOL_LOC_LOCALgdb.SYMBOL_LOC_TYPEDEFSYMBOL_STRUCT_DOMAIN all
have this class.
gdb.SYMBOL_LOC_BLOCKgdb.SYMBOL_LOC_CONST_BYTESgdb.SYMBOL_LOC_UNRESOLVEDgdb.SYMBOL_LOC_OPTIMIZED_OUTgdb.SYMBOL_LOC_COMPUTED