Clean up symbol table access functions and make it

possible to inline them.  The symbol table is heavily
used in the stacktrace code and the faster access
functions should help out.

base/loader/symtab.cc:
    Put these in the header file since they are simple and can
    be inlined.
base/loader/symtab.hh:
    Move the various findFoo functions to the header file so they
    can be inlined.  Add findNearestAddr functions that don't
    return the symbol.  This is so you can figure out what
    function you're in based on the symbol table, but not waste
    time copying out the symbol name if you don't need it.

--HG--
extra : convert_revision : 00cac40a79b0641a70c5ec7d9838fa0ec505c6a1
This commit is contained in:
Nathan Binkert 2005-10-12 17:18:10 -04:00
parent 17b1c8f90d
commit 67b807d907
2 changed files with 90 additions and 50 deletions

View file

@ -95,44 +95,3 @@ SymbolTable::load(const string &filename)
return true; return true;
} }
bool
SymbolTable::findNearestSymbol(Addr address, string &symbol,
Addr &sym_address, Addr &next_sym_address) const
{
// find first key *larger* than desired address
ATable::const_iterator i = addrTable.upper_bound(address);
// if very first key is larger, we're out of luck
if (i == addrTable.begin())
return false;
next_sym_address = i->first;
--i;
sym_address = i->first;
symbol = i->second;
return true;
}
bool
SymbolTable::findSymbol(Addr address, string &symbol) const
{
ATable::const_iterator i = addrTable.find(address);
if (i == addrTable.end())
return false;
symbol = (*i).second;
return true;
}
bool
SymbolTable::findAddress(const string &symbol, Addr &address) const
{
STable::const_iterator i = symbolTable.find(symbol);
if (i == symbolTable.end())
return false;
address = (*i).second;
return true;
}

View file

@ -34,13 +34,28 @@
class SymbolTable class SymbolTable
{ {
private: public:
typedef std::map<Addr, std::string> ATable; typedef std::map<Addr, std::string> ATable;
typedef std::map<std::string, Addr> STable; typedef std::map<std::string, Addr> STable;
private:
ATable addrTable; ATable addrTable;
STable symbolTable; STable symbolTable;
private:
bool
upperBound(Addr addr, ATable::const_iterator &iter) const
{
// find first key *larger* than desired address
iter = addrTable.upper_bound(addr);
// if very first key is larger, we're out of luck
if (iter == addrTable.begin())
return false;
return true;
}
public: public:
SymbolTable() {} SymbolTable() {}
SymbolTable(const std::string &file) { load(file); } SymbolTable(const std::string &file) { load(file); }
@ -49,6 +64,32 @@ class SymbolTable
bool insert(Addr address, std::string symbol); bool insert(Addr address, std::string symbol);
bool load(const std::string &file); bool load(const std::string &file);
const ATable &getAddrTable() const { return addrTable; }
const STable &getSymbolTable() const { return symbolTable; }
public:
bool
findSymbol(Addr address, std::string &symbol) const
{
ATable::const_iterator i = addrTable.find(address);
if (i == addrTable.end())
return false;
symbol = (*i).second;
return true;
}
bool
findAddress(const std::string &symbol, Addr &address) const
{
STable::const_iterator i = symbolTable.find(symbol);
if (i == symbolTable.end())
return false;
address = (*i).second;
return true;
}
/// Find the nearest symbol equal to or less than the supplied /// Find the nearest symbol equal to or less than the supplied
/// address (e.g., the label for the enclosing function). /// address (e.g., the label for the enclosing function).
/// @param address The address to look up. /// @param address The address to look up.
@ -57,21 +98,61 @@ class SymbolTable
/// @param next_sym_address Address of following symbol (for /// @param next_sym_address Address of following symbol (for
/// determining valid range of symbol). /// determining valid range of symbol).
/// @retval True if a symbol was found. /// @retval True if a symbol was found.
bool findNearestSymbol(Addr address, std::string &symbol, bool
Addr &sym_address, Addr &next_sym_address) const; findNearestSymbol(Addr addr, std::string &symbol, Addr &symaddr,
Addr &nextaddr) const
{
ATable::const_iterator i;
if (!upperBound(addr, i))
return false;
nextaddr = i->first;
--i;
symaddr = i->first;
symbol = i->second;
return true;
}
/// Overload for findNearestSymbol() for callers who don't care /// Overload for findNearestSymbol() for callers who don't care
/// about next_sym_address. /// about next_sym_address.
bool findNearestSymbol(Addr address, std::string &symbol, bool
Addr &sym_address) const findNearestSymbol(Addr addr, std::string &symbol, Addr &symaddr) const
{ {
Addr dummy; ATable::const_iterator i;
return findNearestSymbol(address, symbol, sym_address, dummy); if (!upperBound(addr, i))
return false;
--i;
symaddr = i->first;
symbol = i->second;
return true;
} }
bool findSymbol(Addr address, std::string &symbol) const; bool
bool findAddress(const std::string &symbol, Addr &address) const; findNearestAddr(Addr addr, Addr &symaddr, Addr &nextaddr) const
{
ATable::const_iterator i;
if (!upperBound(addr, i))
return false;
nextaddr = i->first;
--i;
symaddr = i->first;
return true;
}
bool
findNearestAddr(Addr addr, Addr &symaddr) const
{
ATable::const_iterator i;
if (!upperBound(addr, i))
return false;
--i;
symaddr = i->first;
return true;
}
}; };
/// Global unified debugging symbol table (for target). Conceptually /// Global unified debugging symbol table (for target). Conceptually