arch,base,cpu,sim: Statically allocate debugSymbolTable.

This singleton object is used thruoughout the simulator. There is
really no reason not to have it statically allocated, except that
whether it was allocated seems to sometimes be used as a signal that
something already put symbols in it, specifically in SE mode.

To keep that functionality for the moment, this change adds an "empty"
method to the SymbolTable class to make it easy to check if the symbol
table is empty, or if someone already populated it.

Change-Id: Ia93510082d3f9809fc504bc5803254d8c308d572
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/24785
Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Maintainer: Giacomo Travaglini <giacomo.travaglini@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Gabe Black
2020-01-21 15:25:09 -08:00
parent c5b2b8e19f
commit 337c586eab
14 changed files with 27 additions and 32 deletions

View File

@@ -83,7 +83,7 @@ FsFreebsd::initState()
if (params()->early_kernel_symbols) {
kernelObj->loadGlobalSymbols(kernelSymtab, 0, 0, _loadAddrMask);
kernelObj->loadGlobalSymbols(
Loader::debugSymbolTable, 0, 0, _loadAddrMask);
&Loader::debugSymbolTable, 0, 0, _loadAddrMask);
}
// Check if the kernel image has a symbol that tells us it supports

View File

@@ -91,7 +91,7 @@ FsWorkload::FsWorkload(Params *p) : KernelWorkload(*p)
"Can't find a matching boot loader / kernel combination!");
if (bootldr)
bootldr->loadGlobalSymbols(Loader::debugSymbolTable);
bootldr->loadGlobalSymbols(&Loader::debugSymbolTable);
}
void

View File

@@ -78,7 +78,7 @@ FsLinux::initState()
if (params()->early_kernel_symbols) {
kernelObj->loadGlobalSymbols(kernelSymtab, 0, 0, _loadAddrMask);
kernelObj->loadGlobalSymbols(
Loader::debugSymbolTable, 0, 0, _loadAddrMask);
&Loader::debugSymbolTable, 0, 0, _loadAddrMask);
}
// Setup boot data structure

View File

@@ -169,7 +169,7 @@ namespace X86ISA
panic("Tried to %s unmapped address %#x.\nPC: %#x, Instr: %s",
modeStr, addr, tc->pcState().pc(),
inst->disassemble(tc->pcState().pc(),
Loader::debugSymbolTable));
&Loader::debugSymbolTable));
}
}
}

View File

@@ -163,7 +163,7 @@ CPA::swSmBegin(ThreadContext *tc, Addr sm_string, int32_t sm_id, int32_t flags)
Addr junk;
char sm[50];
if (!TheISA::inUserMode(tc))
Loader::debugSymbolTable->findNearestSymbol(
Loader::debugSymbolTable.findNearestSymbol(
tc->readIntReg(ReturnAddressReg), st, junk);
tc->getVirtProxy().readString(sm, sm_string, 50);
@@ -337,7 +337,7 @@ CPA::swAutoBegin(ThreadContext *tc, Addr next_pc)
Addr sym_addr = 0;
if (!TheISA::inUserMode(tc)) {
Loader::debugSymbolTable->findNearestSymbol(next_pc, sym, sym_addr);
Loader::debugSymbolTable.findNearestSymbol(next_pc, sym, sym_addr);
} else {
Linux::ThreadInfo ti(tc);
string app = ti.curTaskName();
@@ -390,7 +390,7 @@ CPA::swEnd(ThreadContext *tc)
std::string st;
Addr junk;
if (!TheISA::inUserMode(tc))
Loader::debugSymbolTable->findNearestSymbol(
Loader::debugSymbolTable.findNearestSymbol(
tc->readIntReg(ReturnAddressReg), st, junk);
System *sys = tc->getSystemPtr();
StringWrap name(sys->name());

View File

@@ -44,7 +44,7 @@ using namespace std;
namespace Loader
{
SymbolTable *debugSymbolTable = NULL;
SymbolTable debugSymbolTable;
void
SymbolTable::clear()

View File

@@ -93,6 +93,7 @@ class SymbolTable
bool insert(const Symbol &symbol);
bool insert(const SymbolTable &other);
bool load(const std::string &file);
bool empty() const { return symbols.empty(); }
void serialize(const std::string &base, CheckpointOut &cp) const;
void unserialize(const std::string &base, CheckpointIn &cp,
@@ -156,7 +157,7 @@ class SymbolTable
/// there should be one of these per System object for full system,
/// and per Process object for non-full-system, but so far one big
/// global one has worked well enough.
extern SymbolTable *debugSymbolTable;
extern SymbolTable debugSymbolTable;
} // namespace Loader

View File

@@ -751,17 +751,17 @@ bool AddressMonitor::doMonitor(PacketPtr pkt) {
void
BaseCPU::traceFunctionsInternal(Addr pc)
{
if (!Loader::debugSymbolTable)
if (Loader::debugSymbolTable.empty())
return;
// if pc enters different function, print new function symbol and
// update saved range. Otherwise do nothing.
if (pc < currentFunctionStart || pc >= currentFunctionEnd) {
auto it = Loader::debugSymbolTable->findNearest(
auto it = Loader::debugSymbolTable.findNearest(
pc, currentFunctionEnd);
string sym_str;
if (it == Loader::debugSymbolTable->end()) {
if (it == Loader::debugSymbolTable.end()) {
// no symbol found: use addr as label
sym_str = csprintf("%#x", pc);
currentFunctionStart = pc;

View File

@@ -78,10 +78,9 @@ Trace::ExeTracerRecord::traceInst(const StaticInstPtr &inst, bool ran)
Addr cur_pc = pc.instAddr();
Loader::SymbolTable::const_iterator it;
if (Loader::debugSymbolTable && Debug::ExecSymbol &&
(!FullSystem || !inUserMode(thread)) &&
(it = Loader::debugSymbolTable->findNearest(cur_pc)) !=
Loader::debugSymbolTable->end()) {
if (Debug::ExecSymbol && (!FullSystem || !inUserMode(thread)) &&
(it = Loader::debugSymbolTable.findNearest(cur_pc)) !=
Loader::debugSymbolTable.end()) {
Addr delta = cur_pc - it->address;
if (delta)
ccprintf(outs, "@%s+%d", it->name, delta);
@@ -104,7 +103,7 @@ Trace::ExeTracerRecord::traceInst(const StaticInstPtr &inst, bool ran)
//
outs << setw(26) << left;
outs << inst->disassemble(cur_pc, Loader::debugSymbolTable);
outs << inst->disassemble(cur_pc, &Loader::debugSymbolTable);
if (ran) {
outs << " : ";

View File

@@ -80,7 +80,7 @@ AbstractMemory::initState()
auto *object = Loader::createObjectFile(file, true);
fatal_if(!object, "%s: Could not load %s.", name(), file);
panic_if(!object->loadGlobalSymbols(Loader::debugSymbolTable),
panic_if(!object->loadGlobalSymbols(&Loader::debugSymbolTable),
"%s: Could not load symbols from %s.", name(), file);
Loader::MemoryImage image = object->buildImage();

View File

@@ -35,9 +35,6 @@ KernelWorkload::KernelWorkload(const Params &p) : Workload(&p), _params(p),
_loadAddrMask(p.load_addr_mask), _loadAddrOffset(p.load_addr_offset),
kernelSymtab(new Loader::SymbolTable), commandLine(p.command_line)
{
if (!Loader::debugSymbolTable)
Loader::debugSymbolTable = new Loader::SymbolTable;
if (params().object_file == "") {
inform("No kernel set for full system simulation. "
"Assuming you know what you're doing.");
@@ -70,10 +67,10 @@ KernelWorkload::KernelWorkload(const Params &p) : Workload(&p), _params(p),
fatal_if(!kernelObj->loadLocalSymbols(kernelSymtab),
"Could not load kernel local symbols.");
fatal_if(!kernelObj->loadGlobalSymbols(Loader::debugSymbolTable),
fatal_if(!kernelObj->loadGlobalSymbols(&Loader::debugSymbolTable),
"Could not load kernel symbols.");
fatal_if(!kernelObj->loadLocalSymbols(Loader::debugSymbolTable),
fatal_if(!kernelObj->loadLocalSymbols(&Loader::debugSymbolTable),
"Could not load kernel local symbols.");
}

View File

@@ -155,13 +155,11 @@ Process::Process(ProcessParams *params, EmulationPageTable *pTable,
image = objFile->buildImage();
if (!::Loader::debugSymbolTable) {
::Loader::debugSymbolTable = new ::Loader::SymbolTable();
if (!objFile->loadGlobalSymbols(::Loader::debugSymbolTable) ||
!objFile->loadLocalSymbols(::Loader::debugSymbolTable) ||
!objFile->loadWeakSymbols(::Loader::debugSymbolTable)) {
delete ::Loader::debugSymbolTable;
::Loader::debugSymbolTable = nullptr;
if (::Loader::debugSymbolTable.empty()) {
if (!objFile->loadGlobalSymbols(&::Loader::debugSymbolTable) ||
!objFile->loadLocalSymbols(&::Loader::debugSymbolTable) ||
!objFile->loadWeakSymbols(&::Loader::debugSymbolTable)) {
::Loader::debugSymbolTable.clear();
}
}
}

View File

@@ -267,7 +267,7 @@ addsymbol(ThreadContext *tc, Addr addr, Addr symbolAddr)
tc->getSystemPtr()->workload->insertSymbol(
{ Loader::Symbol::Binding::Global, symbol, addr });
Loader::debugSymbolTable->insert(
Loader::debugSymbolTable.insert(
{ Loader::Symbol::Binding::Global, symbol, addr });
}

View File

@@ -1719,7 +1719,7 @@ mmapFunc(SyscallDesc *desc, ThreadContext *tc,
ffdp->getFileName());
if (lib) {
lib->loadAllSymbols(Loader::debugSymbolTable,
lib->loadAllSymbols(&Loader::debugSymbolTable,
lib->buildImage().minAddr(), start);
}
}