libabigail
Loading...
Searching...
No Matches
symtab Class Reference

symtab is the actual data container of the symtab_reader implementation. More...

#include <abg-symtab-reader.h>

Public Types

using const_iterator
 The (only) iterator type we offer is a const_iterator implemented by the symtab_iterator.
 
using symbol_predicate
 

Public Member Functions

const_iterator begin (const symtab_filter &filter) const
 Obtain an iterator to the beginning of the symtab according to the filter criteria. Whenever this iterator advances, it skips elements that do not match the filter criteria.
 
const_iterator end () const
 Obtain an iterator to the end of the symtab.
 
elf_symbol_sptr function_symbol_is_exported (const GElf_Addr symbol_address)
 Test if a given function symbol has been exported.
 
elf_symbol_sptr function_symbol_is_exported (const string &)
 Test if a given function symbol has been exported.
 
elf_symbol_sptr function_symbol_is_undefined (const string &)
 Test if a name is a the name of an undefined function symbol.
 
bool has_symbols () const
 Indicate whether any (kernel) symbols have been seen at construction.
 
const elf_symbolslookup_symbol (const std::string &name) const
 Get a vector of symbols that are associated with a certain name.
 
const elf_symbol_sptrlookup_symbol (GElf_Addr symbol_addr) const
 Lookup a symbol by its address.
 
const elf_symbol_sptr lookup_undefined_function_symbol (const std::string &name)
 Lookup an undefined function symbol with a given name.
 
const elf_symbol_sptr lookup_undefined_variable_symbol (const std::string &name)
 Lookup an undefined variable symbol with a given name.
 
symtab_filter make_filter () const
 symtab implementations
 
void update_main_symbol (GElf_Addr addr, const std::string &name)
 Notify the symtab about the name of the main symbol at a given address.
 
elf_symbol_sptr variable_symbol_is_exported (const GElf_Addr symbol_address)
 Test if a given variable symbol has been exported.
 
elf_symbol_sptr variable_symbol_is_exported (const string &)
 Test if a given variable symbol has been exported.
 
elf_symbol_sptr variable_symbol_is_undefined (const string &)
 Test if a name is a the name of an undefined variable symbol.
 

Static Public Member Functions

static symtab_ptr load (Elf *elf_handle, const ir::environment &env, symbol_predicate is_suppressed=NULL)
 Construct a symtab object and instantiate it from an ELF handle. Also pass in the ir::environment we are living in. If specified, the symbol_predicate will be respected when creating the full vector of symbols.
 
static symtab_ptr load (string_elf_symbols_map_sptr function_symbol_map, string_elf_symbols_map_sptr variables_symbol_map)
 Construct a symtab object from existing name->symbol lookup maps. They were possibly read from a different representation (XML maybe).
 

Detailed Description

symtab is the actual data container of the symtab_reader implementation.

The symtab is instantiated either via an Elf handle (from binary) or from a set of existing symbol maps (usually when instantiated from XML). It will then discover the symtab, possibly the ksymtab (for Linux Kernel binaries) and setup the data containers and lookup maps for later perusal.

The symtab is supposed to be used in a const context as all information is already computed at construction time. Symbols are stored sorted to allow deterministic reading of the entries.

An example use of the symtab class is

const auto symtab = symtab::load(elf_handle, env); symtab_filter filter = symtab->make_filter(); filter.set_public_symbols(); filter.set_functions();

for (const auto& symbol : filtered_symtab(*symtab, filter)) { std::cout << symbol->get_name() << "\n"; }

This uses the filtered_symtab proxy object to capture the filter.

Definition at line 202 of file abg-symtab-reader.h.

Member Typedef Documentation

◆ const_iterator

The (only) iterator type we offer is a const_iterator implemented by the symtab_iterator.

Definition at line 219 of file abg-symtab-reader.h.

◆ symbol_predicate

using symbol_predicate

Definition at line 205 of file abg-symtab-reader.h.

Member Function Documentation

◆ begin()

const_iterator begin ( const symtab_filter & filter) const
inline

Obtain an iterator to the beginning of the symtab according to the filter criteria. Whenever this iterator advances, it skips elements that do not match the filter criteria.

Parameters
filterthe symtab_filter to match symbols against
Returns
a filtering const_iterator of the underlying type

Definition at line 229 of file abg-symtab-reader.h.

◆ end()

const_iterator end ( ) const
inline

Obtain an iterator to the end of the symtab.

Returns
an end iterator

Definition at line 236 of file abg-symtab-reader.h.

◆ function_symbol_is_exported() [1/2]

elf_symbol_sptr function_symbol_is_exported ( const GElf_Addr symbol_address)

Test if a given function symbol has been exported.

Note that this doesn't test if the symbol is defined or not, but assumes the symbol is defined.

Parameters
symbol_addressthe address of the symbol we are looking for. Note that this address must be a relative offset from the beginning of the .text section, just like the kind of addresses that are present in the .symtab section.
Returns
the elf symbol if found, or nil otherwise.

Definition at line 200 of file abg-symtab-reader.cc.

◆ function_symbol_is_exported() [2/2]

elf_symbol_sptr function_symbol_is_exported ( const string & name)

Test if a given function symbol has been exported.

Note that this doesn't test if the symbol is defined or not, but assumes the symbol is defined.

Parameters
namethe name of the symbol we are looking for.
Returns
the elf symbol if found, or nil otherwise.

Definition at line 178 of file abg-symtab-reader.cc.

◆ function_symbol_is_undefined()

elf_symbol_sptr function_symbol_is_undefined ( const string & sym_name)

Test if a name is a the name of an undefined function symbol.

Parameters
sym_namethe symbol name to consider.
Returns
the undefined symbol if found, nil otherwise.

Definition at line 262 of file abg-symtab-reader.cc.

◆ has_symbols()

bool has_symbols ( ) const
inline

Indicate whether any (kernel) symbols have been seen at construction.

Returns
true if there are symbols detected earlier.

Definition at line 211 of file abg-symtab-reader.h.

◆ load() [1/2]

symtab_ptr load ( Elf * elf_handle,
const ir::environment & env,
symbol_predicate is_suppressed = NULL )
static

Construct a symtab object and instantiate it from an ELF handle. Also pass in the ir::environment we are living in. If specified, the symbol_predicate will be respected when creating the full vector of symbols.

Parameters
elf_handlethe elf handle to load the symbol table from
envthe environment we are operating in
is_suppresseda predicate function to determine if a symbol should be suppressed
Returns
a smart pointer handle to symtab, set to nullptr if the load was not completed

Definition at line 319 of file abg-symtab-reader.cc.

◆ load() [2/2]

symtab_ptr load ( string_elf_symbols_map_sptr function_symbol_map,
string_elf_symbols_map_sptr variables_symbol_map )
static

Construct a symtab object from existing name->symbol lookup maps. They were possibly read from a different representation (XML maybe).

Parameters
function_symbol_mapa map from ELF function name to elf_symbol
variable_symbol_mapa map from ELF variable name to elf_symbol
Returns
a smart pointer handle to symtab, set to nullptr if the load was not completed

Definition at line 342 of file abg-symtab-reader.cc.

◆ lookup_symbol() [1/2]

const elf_symbols & lookup_symbol ( const std::string & name) const

Get a vector of symbols that are associated with a certain name.

Parameters
namethe name the symbols need to match
Returns
a vector of symbols, empty if no matching symbols have been found

Definition at line 86 of file abg-symtab-reader.cc.

◆ lookup_symbol() [2/2]

const elf_symbol_sptr & lookup_symbol ( GElf_Addr symbol_addr) const

Lookup a symbol by its address.

Parameters
symbol_addrthe starting address of the symbol
Returns
a symbol if found, else an empty sptr

Definition at line 101 of file abg-symtab-reader.cc.

◆ lookup_undefined_function_symbol()

const elf_symbol_sptr lookup_undefined_function_symbol ( const std::string & sym_name)

Lookup an undefined function symbol with a given name.

Parameters
sym_namethe name of the function symbol to lookup.
Returns
the undefined function symbol found or nil if none was found.

Definition at line 125 of file abg-symtab-reader.cc.

◆ lookup_undefined_variable_symbol()

const elf_symbol_sptr lookup_undefined_variable_symbol ( const std::string & sym_name)

Lookup an undefined variable symbol with a given name.

Parameters
sym_namethe name of the variable symbol to lookup.
Returns
the undefined variable symbol found or nil if none was found.

Definition at line 151 of file abg-symtab-reader.cc.

◆ make_filter()

symtab_filter make_filter ( ) const

symtab implementations

Obtain a suitable default filter for iterating this symtab object.

The symtab_filter obtained is populated with some sensible default settings, such as public_symbols(true) and kernel_symbols(true) if the binary has been identified as Linux Kernel binary.

Returns
a symtab_filter with sensible populated defaults

Definition at line 71 of file abg-symtab-reader.cc.

◆ update_main_symbol()

void update_main_symbol ( GElf_Addr addr,
const std::string & name )

Notify the symtab about the name of the main symbol at a given address.

From just alone the symtab we can't guess the main symbol of a bunch of aliased symbols that all point to the same address. During processing of additional information (such as DWARF), this information becomes apparent and we can adjust the addr->symbol lookup map as well as the alias reference of the symbol objects.

Parameters
addrthe addr that we are updating the main symbol for
namethe name of the main symbol

Definition at line 686 of file abg-symtab-reader.cc.

◆ variable_symbol_is_exported() [1/2]

elf_symbol_sptr variable_symbol_is_exported ( const GElf_Addr symbol_address)

Test if a given variable symbol has been exported.

Note that this assumes the symbol is exported but doesn't test for it.

Parameters
symbol_addressthe address of the symbol we are looking for. Note that this address must be a relative offset from the beginning of the .text section, just like the kind of addresses that are present in the .symtab section.
Returns
the elf symbol if found, or nil otherwise.

Definition at line 244 of file abg-symtab-reader.cc.

◆ variable_symbol_is_exported() [2/2]

elf_symbol_sptr variable_symbol_is_exported ( const string & name)

Test if a given variable symbol has been exported.

Note that this assumes the symbol is exported but doesn't test for it.

Parameters
namethe name of the symbol we are looking for.
Returns
the elf symbol if found, or nil otherwise.

Definition at line 222 of file abg-symtab-reader.cc.

◆ variable_symbol_is_undefined()

elf_symbol_sptr variable_symbol_is_undefined ( const string & sym_name)

Test if a name is a the name of an undefined variable symbol.

Parameters
sym_namethe symbol name to consider.

Definition at line 282 of file abg-symtab-reader.cc.


The documentation for this class was generated from the following files: