Serialize the symbol tables

base/loader/symtab.cc:
    Add support for clearing out the symbol table
    Add support for serializing the symbol table (clear on unserialize)
    Don't allow empty symbols to be entered into the table
base/loader/symtab.hh:
    Add support for clearing out the symbol table
    Add support for serializing the symbol table
sim/system.cc:
    Serialize the kernel, console, and palcode symbol tables so that
    we can capture any dynamic symbols that are added and so that we
    don't have to have the same kernel binary around to get the
    symbols right

--HG--
extra : convert_revision : 779888c88aa530f3adcd37dc7600a335951d05f7
This commit is contained in:
Nathan Binkert 2005-11-20 18:42:12 -05:00
parent 4e393f38ec
commit 63bb46b6d8
3 changed files with 63 additions and 6 deletions

View file

@ -31,18 +31,29 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "sim/host.hh" #include "base/loader/symtab.hh"
#include "base/misc.hh" #include "base/misc.hh"
#include "base/str.hh" #include "base/str.hh"
#include "base/loader/symtab.hh" #include "sim/host.hh"
#include "sim/serialize.hh"
using namespace std; using namespace std;
SymbolTable *debugSymbolTable = NULL; SymbolTable *debugSymbolTable = NULL;
void
SymbolTable::clear()
{
addrTable.clear();
symbolTable.clear();
}
bool bool
SymbolTable::insert(Addr address, string symbol) SymbolTable::insert(Addr address, string symbol)
{ {
if (symbol.empty())
return false;
if (!addrTable.insert(make_pair(address, symbol)).second) if (!addrTable.insert(make_pair(address, symbol)).second)
return false; return false;
@ -59,10 +70,8 @@ SymbolTable::load(const string &filename)
string buffer; string buffer;
ifstream file(filename.c_str()); ifstream file(filename.c_str());
if (!file) { if (!file)
cerr << "Can't open symbol table file " << filename << endl; fatal("file error: Can't open symbol table file %s\n", filename);
fatal("file error");
}
while (!file.eof()) { while (!file.eof()) {
getline(file, buffer); getline(file, buffer);
@ -95,3 +104,34 @@ SymbolTable::load(const string &filename)
return true; return true;
} }
void
SymbolTable::serialize(const string &base, ostream &os)
{
paramOut(os, base + ".size", addrTable.size());
int i = 0;
ATable::const_iterator p, end = addrTable.end();
for (p = addrTable.begin(); p != end; ++p) {
paramOut(os, csprintf("%s.addr_%d", base, i), p->first);
paramOut(os, csprintf("%s.symbol_%d", base, i), p->second);
++i;
}
}
void
SymbolTable::unserialize(const string &base, Checkpoint *cp,
const string &section)
{
clear();
int size;
paramIn(cp, section, base + ".size", size);
for (int i = 0; i < size; ++i) {
Addr addr;
std::string symbol;
paramIn(cp, section, csprintf("%s.addr_%d", base, i), addr);
paramIn(cp, section, csprintf("%s.symbol_%d", base, i), symbol);
insert(addr, symbol);
}
}

View file

@ -29,9 +29,12 @@
#ifndef __SYMTAB_HH__ #ifndef __SYMTAB_HH__
#define __SYMTAB_HH__ #define __SYMTAB_HH__
#include <iosfwd>
#include <map> #include <map>
#include "targetarch/isa_traits.hh" // for Addr #include "targetarch/isa_traits.hh" // for Addr
class Checkpoint;
class SymbolTable class SymbolTable
{ {
public: public:
@ -61,12 +64,18 @@ class SymbolTable
SymbolTable(const std::string &file) { load(file); } SymbolTable(const std::string &file) { load(file); }
~SymbolTable() {} ~SymbolTable() {}
void clear();
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 ATable &getAddrTable() const { return addrTable; }
const STable &getSymbolTable() const { return symbolTable; } const STable &getSymbolTable() const { return symbolTable; }
public:
void serialize(const std::string &base, std::ostream &os);
void unserialize(const std::string &base, Checkpoint *cp,
const std::string &section);
public: public:
bool bool
findSymbol(Addr address, std::string &symbol) const findSymbol(Addr address, std::string &symbol) const

View file

@ -333,6 +333,10 @@ void
System::serialize(ostream &os) System::serialize(ostream &os)
{ {
kernelBinning->serialize(os); kernelBinning->serialize(os);
kernelSymtab->serialize("kernel_symtab", os);
consoleSymtab->serialize("console_symtab", os);
palSymtab->serialize("pal_symtab", os);
} }
@ -340,6 +344,10 @@ void
System::unserialize(Checkpoint *cp, const string &section) System::unserialize(Checkpoint *cp, const string &section)
{ {
kernelBinning->unserialize(cp, section); kernelBinning->unserialize(cp, section);
kernelSymtab->unserialize("kernel_symtab", cp, section);
consoleSymtab->unserialize("console_symtab", cp, section);
palSymtab->unserialize("pal_symtab", cp, section);
} }
void void