#include <string>
#include <vector>
-#include "sim/host.hh"
+#include "base/loader/symtab.hh"
#include "base/misc.hh"
#include "base/str.hh"
-#include "base/loader/symtab.hh"
+#include "sim/host.hh"
+#include "sim/serialize.hh"
using namespace std;
SymbolTable *debugSymbolTable = NULL;
+void
+SymbolTable::clear()
+{
+ addrTable.clear();
+ symbolTable.clear();
+}
+
bool
SymbolTable::insert(Addr address, string symbol)
{
+ if (symbol.empty())
+ return false;
+
if (!addrTable.insert(make_pair(address, symbol)).second)
return false;
string buffer;
ifstream file(filename.c_str());
- if (!file) {
- cerr << "Can't open symbol table file " << filename << endl;
- fatal("file error");
- }
+ if (!file)
+ fatal("file error: Can't open symbol table file %s\n", filename);
while (!file.eof()) {
getline(file, buffer);
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 §ion)
+{
+ 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);
+ }
+}
#ifndef __SYMTAB_HH__
#define __SYMTAB_HH__
+#include <iosfwd>
#include <map>
+
#include "targetarch/isa_traits.hh" // for Addr
+class Checkpoint;
class SymbolTable
{
public:
SymbolTable(const std::string &file) { load(file); }
~SymbolTable() {}
+ void clear();
bool insert(Addr address, std::string symbol);
bool load(const std::string &file);
const ATable &getAddrTable() const { return addrTable; }
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 §ion);
+
public:
bool
findSymbol(Addr address, std::string &symbol) const
System::serialize(ostream &os)
{
kernelBinning->serialize(os);
+
+ kernelSymtab->serialize("kernel_symtab", os);
+ consoleSymtab->serialize("console_symtab", os);
+ palSymtab->serialize("pal_symtab", os);
}
System::unserialize(Checkpoint *cp, const string §ion)
{
kernelBinning->unserialize(cp, section);
+
+ kernelSymtab->unserialize("kernel_symtab", cp, section);
+ consoleSymtab->unserialize("console_symtab", cp, section);
+ palSymtab->unserialize("pal_symtab", cp, section);
}
void