gem5  v22.1.0.0
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
gem5::loader::SymbolTable Class Reference

#include <symtab.hh>

Public Types

typedef std::shared_ptr< SymbolTableSymbolTablePtr
 
typedef SymbolVector::iterator iterator
 
typedef SymbolVector::const_iterator const_iterator
 

Public Member Functions

const_iterator begin () const
 
const_iterator end () const
 
void clear ()
 Clears the table. More...
 
bool insert (const Symbol &symbol)
 Insert a new symbol in the table if it does not already exist. More...
 
bool insert (const SymbolTable &other)
 Copies the symbols of another table to this table if there are no common symbols between the tables. More...
 
bool empty () const
 Verifies whether the table is empty. More...
 
SymbolTablePtr offset (Addr addr_offset) const
 Generate a new table by applying an offset to the symbols of the current table. More...
 
SymbolTablePtr mask (Addr m) const
 Generate a new table by a mask to the symbols of the current table. More...
 
SymbolTablePtr rename (std::function< void(std::string &)> func) const
 Modify the symbols' name with a given transform function. More...
 
SymbolTablePtr globals () const
 Generates a new symbol table containing only global symbols. More...
 
SymbolTablePtr locals () const
 Generates a new symbol table containing only local symbols. More...
 
SymbolTablePtr weaks () const
 Generates a new symbol table containing only weak symbols. More...
 
void serialize (const std::string &base, CheckpointOut &cp) const
 Serialize the table's contents. More...
 
void unserialize (const std::string &base, CheckpointIn &cp, Symbol::Binding default_binding=Symbol::Binding::Global)
 Populate the table by unserializing a checkpoint. More...
 
const_iterator find (Addr address) const
 Search for a symbol by its address. More...
 
const_iterator find (const std::string &name) const
 Search for a symbol by its name. More...
 
const_iterator findNearest (Addr addr, Addr &next_addr) const
 Find the nearest symbol equal to or less than the supplied address (e.g., the label for the enclosing function). More...
 
const_iterator findNearest (Addr addr) const
 Overload for findNearestSymbol() for callers who don't care about nextaddr. More...
 

Private Types

typedef std::vector< SymbolSymbolVector
 Vector containing all the symbols in the table. More...
 
typedef std::multimap< Addr, int > AddrMap
 Map addresses to an index into the symbol vector. More...
 
typedef std::map< std::string, int > NameMap
 Map a symbol name to an index into the symbol vector. More...
 
typedef std::function< void(SymbolTable &symtab, const Symbol &symbol)> SymTabOp
 A function that applies an operation on a symbol with respect to a symbol table. More...
 
typedef std::function< bool(const Symbol &symbol)> SymTabFilter
 A function that applies a condition to the symbol provided to decide whether the symbol is accepted, or if it must be filtered out. More...
 

Private Member Functions

bool upperBound (Addr addr, AddrMap::const_iterator &iter) const
 Get the first address larger than the given address, if any. More...
 
SymbolTablePtr operate (SymTabOp op) const
 Create a derived symbol table by applying an operation on the symbols of the current table. More...
 
SymbolTablePtr filter (SymTabFilter filter) const
 Applies a filter to the symbols of the table to generate a new table. More...
 
SymbolTablePtr filterByBinding (Symbol::Binding binding) const
 Generate a new table by applying a filter that only accepts the symbols whose binding matches the given binding. More...
 

Private Attributes

SymbolVector symbols
 
AddrMap addrMap
 
NameMap nameMap
 

Detailed Description

Definition at line 65 of file symtab.hh.

Member Typedef Documentation

◆ AddrMap

typedef std::multimap<Addr, int> gem5::loader::SymbolTable::AddrMap
private

Map addresses to an index into the symbol vector.

Definition at line 74 of file symtab.hh.

◆ const_iterator

typedef SymbolVector::const_iterator gem5::loader::SymbolTable::const_iterator

Definition at line 170 of file symtab.hh.

◆ iterator

typedef SymbolVector::iterator gem5::loader::SymbolTable::iterator

Definition at line 169 of file symtab.hh.

◆ NameMap

typedef std::map<std::string, int> gem5::loader::SymbolTable::NameMap
private

Map a symbol name to an index into the symbol vector.

Definition at line 76 of file symtab.hh.

◆ SymbolTablePtr

Definition at line 68 of file symtab.hh.

◆ SymbolVector

Vector containing all the symbols in the table.

Definition at line 72 of file symtab.hh.

◆ SymTabFilter

typedef std::function<bool(const Symbol &symbol)> gem5::loader::SymbolTable::SymTabFilter
private

A function that applies a condition to the symbol provided to decide whether the symbol is accepted, or if it must be filtered out.

Definition at line 130 of file symtab.hh.

◆ SymTabOp

typedef std::function<void(SymbolTable &symtab, const Symbol &symbol)> gem5::loader::SymbolTable::SymTabOp
private

A function that applies an operation on a symbol with respect to a symbol table.

The operation can, for example, simply add the symbol to the table; modify and insert the symbol; do nothing at all; etc.

Definition at line 108 of file symtab.hh.

Member Function Documentation

◆ begin()

const_iterator gem5::loader::SymbolTable::begin ( ) const
inline
Returns
An iterator to the beginning of the symbol vector.

Definition at line 173 of file symtab.hh.

References symbols.

◆ clear()

void gem5::loader::SymbolTable::clear ( )

Clears the table.

Definition at line 47 of file symtab.cc.

References addrMap, nameMap, and symbols.

Referenced by gem5::PowerProcess::initState(), and unserialize().

◆ empty()

bool gem5::loader::SymbolTable::empty ( ) const
inline

Verifies whether the table is empty.

Returns
Whether the symbol table is empty.

Definition at line 204 of file symtab.hh.

References symbols.

◆ end()

const_iterator gem5::loader::SymbolTable::end ( ) const
inline

◆ filter()

SymbolTablePtr gem5::loader::SymbolTable::filter ( SymTabFilter  filter) const
inlineprivate

Applies a filter to the symbols of the table to generate a new table.

The filter decides whether the symbols will be inserted in the new table or not.

Parameters
filterThe filter to be applied.
Returns
A new table, filtered.

Definition at line 141 of file symtab.hh.

References insert(), and operate().

Referenced by filterByBinding().

◆ filterByBinding()

SymbolTablePtr gem5::loader::SymbolTable::filterByBinding ( Symbol::Binding  binding) const
inlineprivate

Generate a new table by applying a filter that only accepts the symbols whose binding matches the given binding.

Parameters
Thebinding that must be matched.
Returns
A new table, filtered by binding.

Definition at line 160 of file symtab.hh.

References filter().

Referenced by globals(), locals(), and weaks().

◆ find() [1/2]

const_iterator gem5::loader::SymbolTable::find ( Addr  address) const
inline

Search for a symbol by its address.

Since many symbols can map to the same address, this function returns the first found. If the symbol is not found this function returns the end() iterator.

Parameters
addressThe address of the symbol being searched for.
Returns
A const iterator to the symbol. end() if not found.

Definition at line 322 of file symtab.hh.

References addrMap, end(), gem5::ArmISA::i, and symbols.

Referenced by gem5::Workload::addFuncEvent(), gem5::PowerISA::BranchOp::generateDisassembly(), gem5::PowerISA::BranchDispCondOp::generateDisassembly(), gem5::linux::ThreadInfo::get_data(), gem5::ArmISA::FsFreebsd::initState(), gem5::ArmISA::FsLinux::initState(), and gem5::BaseStackTrace::tryGetSymbol().

◆ find() [2/2]

const_iterator gem5::loader::SymbolTable::find ( const std::string &  name) const
inline

Search for a symbol by its name.

If the symbol is not found this function returns the end() iterator.

Parameters
nameThe name of the symbol being searched for.
Returns
A const iterator to the symbol. end() if not found.

Definition at line 341 of file symtab.hh.

References end(), gem5::ArmISA::i, name(), nameMap, and symbols.

◆ findNearest() [1/2]

const_iterator gem5::loader::SymbolTable::findNearest ( Addr  addr) const
inline

Overload for findNearestSymbol() for callers who don't care about nextaddr.

Definition at line 383 of file symtab.hh.

References gem5::X86ISA::addr, addrMap, end(), gem5::ArmISA::i, symbols, and upperBound().

◆ findNearest() [2/2]

const_iterator gem5::loader::SymbolTable::findNearest ( Addr  addr,
Addr next_addr 
) const
inline

Find the nearest symbol equal to or less than the supplied address (e.g., the label for the enclosing function).

If there is no valid next address, next_addr is assigned 0.

Parameters
addrThe address to look up.
next_addrAddress of following symbol (to determine the valid range of the symbol).
Return values
Aconst_iterator which points to the symbol if found, or end.

Definition at line 361 of file symtab.hh.

References gem5::X86ISA::addr, addrMap, end(), gem5::ArmISA::i, symbols, and upperBound().

Referenced by gem5::SparcISA::BranchDisp::generateDisassembly(), gem5::ArmISA::ArmStaticInst::printMemSymbol(), gem5::ArmISA::ArmStaticInst::printTarget(), gem5::FunctionProfile::sample(), and gem5::BaseCPU::traceFunctionsInternal().

◆ globals()

SymbolTablePtr gem5::loader::SymbolTable::globals ( ) const
inline

Generates a new symbol table containing only global symbols.

Returns
The new table.

Definition at line 267 of file symtab.hh.

References filterByBinding(), and gem5::loader::Symbol::Global.

Referenced by gem5::ArmISA::FsWorkload::FsWorkload(), gem5::ArmISA::FsFreebsd::initState(), and gem5::ArmISA::FsLinux::initState().

◆ insert() [1/2]

bool gem5::loader::SymbolTable::insert ( const Symbol symbol)

◆ insert() [2/2]

bool gem5::loader::SymbolTable::insert ( const SymbolTable other)

Copies the symbols of another table to this table if there are no common symbols between the tables.

Parameters
symbolThe symbol to be inserted.
Returns
True if successful; false if tables contain any common symbols.

Definition at line 75 of file symtab.cc.

References insert(), and nameMap.

◆ locals()

SymbolTablePtr gem5::loader::SymbolTable::locals ( ) const
inline

Generates a new symbol table containing only local symbols.

Returns
The new table.

Definition at line 278 of file symtab.hh.

References filterByBinding(), and gem5::loader::Symbol::Local.

◆ mask()

SymbolTablePtr gem5::loader::SymbolTable::mask ( Addr  m) const
inline

Generate a new table by a mask to the symbols of the current table.

The current table is not modified.

Parameters
mThe mask to be applied.
Returns
The new table.

Definition at line 233 of file symtab.hh.

References gem5::loader::Symbol::address, insert(), gem5::VegaISA::m, gem5::X86ISA::op, and operate().

Referenced by gem5::KernelWorkload::KernelWorkload().

◆ offset()

SymbolTablePtr gem5::loader::SymbolTable::offset ( Addr  addr_offset) const
inline

Generate a new table by applying an offset to the symbols of the current table.

The current table is not modified.

Parameters
addr_offsetThe offset to be applied.
Returns
The new table.

Definition at line 214 of file symtab.hh.

References gem5::loader::Symbol::address, insert(), gem5::X86ISA::op, and operate().

◆ operate()

SymbolTablePtr gem5::loader::SymbolTable::operate ( SymTabOp  op) const
inlineprivate

Create a derived symbol table by applying an operation on the symbols of the current table.

The current table is not modified.

Parameters
opThe operation to be applied to the new table.
Returns
The new table.

Definition at line 118 of file symtab.hh.

References gem5::X86ISA::op, and symbols.

Referenced by filter(), mask(), offset(), and rename().

◆ rename()

SymbolTablePtr gem5::loader::SymbolTable::rename ( std::function< void(std::string &)>  func) const
inline

Modify the symbols' name with a given transform function.

Parameters
funcThe transform function accepting the reference of the symbol's name.
Return values
SymbolTablePtrA pointer to the modified SymbolTable copy.

Definition at line 251 of file symtab.hh.

References insert(), gem5::loader::Symbol::name, gem5::X86ISA::op, and operate().

◆ serialize()

void gem5::loader::SymbolTable::serialize ( const std::string &  base,
CheckpointOut cp 
) const

Serialize the table's contents.

Parameters
baseThe base section.
cpThe checkpoint to use.

Definition at line 93 of file symtab.cc.

References gem5::X86ISA::base, gem5::csprintf(), gem5::ArmISA::i, gem5::paramOut(), and symbols.

Referenced by gem5::KernelWorkload::serialize().

◆ unserialize()

void gem5::loader::SymbolTable::unserialize ( const std::string &  base,
CheckpointIn cp,
Symbol::Binding  default_binding = Symbol::Binding::Global 
)

Populate the table by unserializing a checkpoint.

Parameters
baseThe base section.
cpThe checkpoint to use.
default_bindingThe binding to be used if an unserialized symbol's binding is not found.

Definition at line 107 of file symtab.cc.

References gem5::X86ISA::base, clear(), gem5::csprintf(), gem5::ArmISA::i, insert(), name(), gem5::optParamIn(), and gem5::paramIn().

Referenced by gem5::KernelWorkload::unserialize().

◆ upperBound()

bool gem5::loader::SymbolTable::upperBound ( Addr  addr,
AddrMap::const_iterator &  iter 
) const
inlineprivate

Get the first address larger than the given address, if any.

Parameters
addrThe address to compare against.
iterAn iterator to the larger-address entry.
Returns
True if successful; false if no larger addresses exist.

Definition at line 90 of file symtab.hh.

References gem5::X86ISA::addr, and addrMap.

Referenced by findNearest().

◆ weaks()

SymbolTablePtr gem5::loader::SymbolTable::weaks ( ) const
inline

Generates a new symbol table containing only weak symbols.

Returns
The new table.

Definition at line 289 of file symtab.hh.

References filterByBinding(), and gem5::loader::Symbol::Weak.

Member Data Documentation

◆ addrMap

AddrMap gem5::loader::SymbolTable::addrMap
private

Definition at line 79 of file symtab.hh.

Referenced by clear(), find(), findNearest(), insert(), and upperBound().

◆ nameMap

NameMap gem5::loader::SymbolTable::nameMap
private

Definition at line 80 of file symtab.hh.

Referenced by clear(), find(), and insert().

◆ symbols

SymbolVector gem5::loader::SymbolTable::symbols
private

Definition at line 78 of file symtab.hh.

Referenced by begin(), clear(), empty(), end(), find(), findNearest(), insert(), operate(), and serialize().


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

Generated on Wed Dec 21 2022 10:24:15 for gem5 by doxygen 1.9.1