gem5 v24.0.0.0
Loading...
Searching...
No Matches
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.
 
bool insert (const Symbol &symbol)
 Insert a new symbol in the table if it does not already exist.
 
bool insert (const SymbolTable &other)
 Copies the symbols of another table to this table if there are no common symbols between the tables.
 
bool empty () const
 Verifies whether the table is empty.
 
SymbolTablePtr offset (Addr addr_offset) const
 Generate a new table by applying an offset to the symbols of the current table.
 
SymbolTablePtr mask (Addr m) const
 Generate a new table by a mask to the symbols of the current table.
 
SymbolTablePtr rename (std::function< std::string(const std::string &)> func) const
 Modify the symbols' name with a given transform function.
 
SymbolTablePtr globals () const
 Generates a new symbol table containing only global symbols.
 
SymbolTablePtr locals () const
 Generates a new symbol table containing only local symbols.
 
SymbolTablePtr weaks () const
 Generates a new symbol table containing only weak symbols.
 
SymbolTablePtr functionSymbols () const
 Generates a new symbol table containing only function symbols.
 
void serialize (const std::string &base, CheckpointOut &cp) const
 Serialize the table's contents.
 
void unserialize (const std::string &base, CheckpointIn &cp, Symbol::Binding default_binding=Symbol::Binding::Global)
 Populate the table by unserializing a checkpoint.
 
const_iterator find (Addr address) const
 Search for a symbol by its address.
 
const_iterator find (const std::string &name) const
 Search for a symbol by its name.
 
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).
 
const_iterator findNearest (Addr addr) const
 Overload for findNearestSymbol() for callers who don't care about nextaddr.
 

Private Types

typedef std::vector< SymbolSymbolVector
 Vector containing all the symbols in the table.
 
typedef std::multimap< Addr, int > AddrMap
 Map addresses to an index into the symbol vector.
 
typedef std::map< std::string, int > NameMap
 Map a symbol name to an index into the symbol vector.
 
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.
 
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.
 

Private Member Functions

bool upperBound (Addr addr, AddrMap::const_iterator &iter) const
 Get the first address larger than the given address, if any.
 
SymbolTablePtr operate (SymTabOp op) const
 Create a derived symbol table by applying an operation on the symbols of the current table.
 
SymbolTablePtr filter (SymTabFilter filter) const
 Applies a filter to the symbols of the table to generate a new table.
 
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.
 
SymbolTablePtr filterBySymbolType (const Symbol::SymbolType &symbol_type) const
 Generate a new table by applying a filter that only accepts the symbols whose type matches the given symbol type.
 

Private Attributes

SymbolVector symbols
 
AddrMap addrMap
 
NameMap nameMap
 

Detailed Description

Definition at line 151 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 160 of file symtab.hh.

◆ const_iterator

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

Definition at line 272 of file symtab.hh.

◆ iterator

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

Definition at line 271 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 162 of file symtab.hh.

◆ SymbolTablePtr

Definition at line 154 of file symtab.hh.

◆ SymbolVector

Vector containing all the symbols in the table.

Definition at line 158 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 216 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 194 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 275 of file symtab.hh.

References symbols.

Referenced by checkTable().

◆ clear()

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

Clears the table.

Definition at line 58 of file symtab.cc.

References addrMap, clear(), nameMap, and symbols.

Referenced by clear(), gem5::PowerProcess::initState(), TEST(), 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 306 of file symtab.hh.

References symbols.

Referenced by TEST(), TEST(), and TEST().

◆ end()

◆ 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 227 of file symtab.hh.

References filter(), insert(), and operate().

Referenced by filter(), filterByBinding(), and filterBySymbolType().

◆ 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 246 of file symtab.hh.

References filter().

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

◆ filterBySymbolType()

SymbolTablePtr gem5::loader::SymbolTable::filterBySymbolType ( const Symbol::SymbolType & symbol_type) const
inlineprivate

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

Parameters
Thetype that must be matched.
Returns
A new table, filtered by type.

Definition at line 262 of file symtab.hh.

References filter().

Referenced by functionSymbols().

◆ 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 435 of file symtab.hh.

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

Referenced by gem5::Workload::addFuncEvent(), gem5::PowerISA::BranchDispCondOp::generateDisassembly(), gem5::PowerISA::BranchOp::generateDisassembly(), gem5::linux::ThreadInfo::get_data(), gem5::ArmISA::FsFreebsd::initState(), gem5::ArmISA::FsLinux::initState(), TEST(), TEST(), TEST(), TEST(), TEST(), 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 454 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 496 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 474 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(), TEST(), TEST(), TEST(), TEST(), TEST(), and gem5::BaseCPU::traceFunctionsInternal().

◆ functionSymbols()

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

Generates a new symbol table containing only function symbols.

Returns
The new table.

Definition at line 402 of file symtab.hh.

References filterBySymbolType(), and gem5::loader::Symbol::Function.

Referenced by gem5::RiscvISA::BootloaderKernelWorkload::loadKernelSymbolTable(), and TEST().

◆ globals()

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

Generates a new symbol table containing only global symbols.

Returns
The new table.

Definition at line 369 of file symtab.hh.

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

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

◆ insert() [1/2]

◆ 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 86 of file symtab.cc.

References insert(), nameMap, and warn.

◆ locals()

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

Generates a new symbol table containing only local symbols.

Returns
The new table.

Definition at line 380 of file symtab.hh.

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

Referenced by TEST().

◆ 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 335 of file symtab.hh.

References insert(), gem5::ArmISA::m, gem5::X86ISA::op, and operate().

Referenced by gem5::KernelWorkload::KernelWorkload(), and TEST().

◆ 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 316 of file symtab.hh.

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

Referenced by gem5::RiscvISA::BootloaderKernelWorkload::loadBootloaderSymbolTable(), and TEST().

◆ 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 204 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< std::string(const 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 353 of file symtab.hh.

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

Referenced by TEST(), and TEST().

◆ 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 107 of file symtab.cc.

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

Referenced by gem5::KernelWorkload::serialize(), gem5::RiscvISA::BootloaderKernelWorkload::serialize(), and TEST_F().

◆ 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 127 of file symtab.cc.

References gem5::X86ISA::base, clear(), gem5::csprintf(), gem5::ArmISA::i, insert(), name(), gem5::optParamIn(), gem5::loader::Symbol::Other, gem5::paramIn(), gem5::X86ISA::type, and warn_once.

Referenced by TEST_F(), TEST_F(), TEST_F(), gem5::KernelWorkload::unserialize(), and gem5::RiscvISA::BootloaderKernelWorkload::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 176 of file symtab.hh.

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

Referenced by findNearest(), and 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 391 of file symtab.hh.

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

Referenced by TEST().

Member Data Documentation

◆ addrMap

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

Definition at line 165 of file symtab.hh.

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

◆ nameMap

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

Definition at line 166 of file symtab.hh.

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

◆ symbols

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

Definition at line 164 of file symtab.hh.

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


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

Generated on Tue Jun 18 2024 16:24:19 for gem5 by doxygen 1.11.0