Next: , Previous: Blocks In Python, Up: Python API


23.2.2.17 Python representation of Symbols.

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:

— Function: lookup_symbol name [block] [domain]

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. 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.

A gdb.Symbol object has the following attributes:

— Instance Variable of Symbol: symtab

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.

— Instance Variable of Symbol: name

The name of the symbol as a string. This attribute is not writable.

— Instance Variable of Symbol: linkage_name

The name of the symbol, as used by the linker (i.e., may be mangled). This attribute is not writable.

— Instance Variable of Symbol: print_name

The name of the symbol in a form suitable for output. This is either name or linkage_name, depending on whether the user asked gdb to display demangled or mangled names.

— Instance Variable of Symbol: addr_class

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.

— Instance Variable of Symbol: is_argument

True if the symbol is an argument of a function.

— Instance Variable of Symbol: is_constant

True if the symbol is a constant.

— Instance Variable of Symbol: is_function

True if the symbol is a function or a method.

— Instance Variable of Symbol: is_variable

True if the symbol is a variable.

The available domain categories in gdb.Symbol are represented as constants in the gdb module:

SYMBOL_UNDEF_DOMAIN
This is used when a domain has not been discovered or none of the following domains apply. This usually indicates an error either in the symbol information or in gdb's handling of symbols.
SYMBOL_VAR_DOMAIN
This domain contains variables, function names, typedef names and enum type values.
SYMBOL_STRUCT_DOMAIN
This domain holds struct, union and enum type names.
SYMBOL_LABEL_DOMAIN
This domain contains names of labels (for gotos).
SYMBOL_VARIABLES_DOMAIN
This domain holds a subset of the SYMBOLS_VAR_DOMAIN; it contains everything minus functions and types.
SYMBOL_FUNCTION_DOMAIN
This domain contains all functions.
SYMBOL_TYPES_DOMAIN
This domain contains all types.

The available address class categories in gdb.Symbol are represented as constants in the gdb module:

SYMBOL_LOC_UNDEF
If this is returned by address class, it indicates an error either in the symbol information or in gdb's handling of symbols.
SYMBOL_LOC_CONST
Value is constant int.
SYMBOL_LOC_STATIC
Value is at a fixed address.
SYMBOL_LOC_REGISTER
Value is in a register.
SYMBOL_LOC_ARG
Value is an argument. This value is at the offset stored within the symbol inside the frame's argument list.
SYMBOL_LOC_REF_ARG
Value address is stored in the frame's argument list. Just like LOC_ARG except that the value's address is stored at the offset, not the value itself.
SYMBOL_LOC_REGPARM_ADDR
Value is a specified register. Just like LOC_REGISTER except the register holds the address of the argument instead of the argument itself.
SYMBOL_LOC_LOCAL
Value is a local variable.
SYMBOL_LOC_TYPEDEF
Value not used. Symbols in the domain SYMBOL_STRUCT_DOMAIN all have this class.
SYMBOL_LOC_BLOCK
Value is a block.
SYMBOL_LOC_CONST_BYTES
Value is a byte-sequence.
SYMBOL_LOC_UNRESOLVED
Value is at a fixed address, but the address of the variable has to be determined from the minimal symbol table whenever the variable is referenced.
SYMBOL_LOC_OPTIMIZED_OUT
The value does not actually exist in the program.
SYMBOL_LOC_COMPUTED
The value's address is a computed location.