libabigail
Public Types | Public Member Functions | Static Public Member Functions | List of all members
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 = symtab_iterator
 The (only) iterator type we offer is a const_iterator implemented by the symtab_iterator. More...
 
using symbol_predicate = std::function< bool(const elf_symbol_sptr &)>
 

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. More...
 
const_iterator end () const
 Obtain an iterator to the end of the symtab. More...
 
bool has_symbols () const
 Indicate whether any (kernel) symbols have been seen at construction. More...
 
const elf_symbolslookup_symbol (const std::string &name) const
 Get a vector of symbols that are associated with a certain name. More...
 
const elf_symbol_sptrlookup_symbol (GElf_Addr symbol_addr) const
 Lookup a symbol by its address. More...
 
symtab_filter make_filter () const
 symtab implementations More...
 
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. More...
 

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

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.

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.

◆ 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 141 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 164 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.

◆ 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 504 of file abg-symtab-reader.cc.


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