From: Gabe Black Date: Tue, 21 Jan 2020 23:25:09 +0000 (-0800) Subject: arch,base,cpu,sim: Statically allocate debugSymbolTable. X-Git-Tag: v20.1.0.0~639 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=337c586eabb1f9c4a2cb3c4bf87d5baea8897c00;p=gem5.git 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 Maintainer: Giacomo Travaglini Tested-by: kokoro --- diff --git a/src/arch/arm/freebsd/fs_workload.cc b/src/arch/arm/freebsd/fs_workload.cc index ea99b4273..e3660d9b1 100644 --- a/src/arch/arm/freebsd/fs_workload.cc +++ b/src/arch/arm/freebsd/fs_workload.cc @@ -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 diff --git a/src/arch/arm/fs_workload.cc b/src/arch/arm/fs_workload.cc index 09c7bb2e7..4c654b822 100644 --- a/src/arch/arm/fs_workload.cc +++ b/src/arch/arm/fs_workload.cc @@ -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 diff --git a/src/arch/arm/linux/fs_workload.cc b/src/arch/arm/linux/fs_workload.cc index 9ebb1172b..7f0853fdc 100644 --- a/src/arch/arm/linux/fs_workload.cc +++ b/src/arch/arm/linux/fs_workload.cc @@ -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 diff --git a/src/arch/x86/faults.cc b/src/arch/x86/faults.cc index 98bd10755..0754da388 100644 --- a/src/arch/x86/faults.cc +++ b/src/arch/x86/faults.cc @@ -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)); } } } diff --git a/src/base/cp_annotate.cc b/src/base/cp_annotate.cc index c886e3970..159e6e0f7 100644 --- a/src/base/cp_annotate.cc +++ b/src/base/cp_annotate.cc @@ -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()); diff --git a/src/base/loader/symtab.cc b/src/base/loader/symtab.cc index a8e1a1534..eaada2268 100644 --- a/src/base/loader/symtab.cc +++ b/src/base/loader/symtab.cc @@ -44,7 +44,7 @@ using namespace std; namespace Loader { -SymbolTable *debugSymbolTable = NULL; +SymbolTable debugSymbolTable; void SymbolTable::clear() diff --git a/src/base/loader/symtab.hh b/src/base/loader/symtab.hh index 38e97ea9c..30f0a4fcb 100644 --- a/src/base/loader/symtab.hh +++ b/src/base/loader/symtab.hh @@ -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 diff --git a/src/cpu/base.cc b/src/cpu/base.cc index a74e285ca..dc3cbf051 100644 --- a/src/cpu/base.cc +++ b/src/cpu/base.cc @@ -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; diff --git a/src/cpu/exetrace.cc b/src/cpu/exetrace.cc index 60c8fd0ac..c9c8b686c 100644 --- a/src/cpu/exetrace.cc +++ b/src/cpu/exetrace.cc @@ -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 << " : "; diff --git a/src/mem/abstract_mem.cc b/src/mem/abstract_mem.cc index 9323f61e8..678527e69 100644 --- a/src/mem/abstract_mem.cc +++ b/src/mem/abstract_mem.cc @@ -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(); diff --git a/src/sim/kernel_workload.cc b/src/sim/kernel_workload.cc index 415ff9630..74f9fc775 100644 --- a/src/sim/kernel_workload.cc +++ b/src/sim/kernel_workload.cc @@ -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."); } diff --git a/src/sim/process.cc b/src/sim/process.cc index a55362d0a..9a8816375 100644 --- a/src/sim/process.cc +++ b/src/sim/process.cc @@ -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(); } } } diff --git a/src/sim/pseudo_inst.cc b/src/sim/pseudo_inst.cc index 64a9c449e..da19168dd 100644 --- a/src/sim/pseudo_inst.cc +++ b/src/sim/pseudo_inst.cc @@ -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 }); } diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh index 5bd9f54f3..4a37e99a0 100644 --- a/src/sim/syscall_emul.hh +++ b/src/sim/syscall_emul.hh @@ -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); } }