summaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorNathan Binkert <binkertn@umich.edu>2005-11-20 17:44:58 -0500
committerNathan Binkert <binkertn@umich.edu>2005-11-20 17:44:58 -0500
commit0dcb288365931b5b6c1048302c23656473fea1af (patch)
tree6c7b5369fe283b61ad6c10fc5764bfd4a8af9ccb /arch
parentf66ba9064090296563dc3f7712f2c0459fca3c5d (diff)
downloadgem5-0dcb288365931b5b6c1048302c23656473fea1af.tar.xz
Cleanup the StackTrace interfaces and profile interfaces so they
are more efficient and reduce the number of new/delete calls arch/alpha/stacktrace.cc: - Change the StackTrace code so that the class can more easily be cleaned out and reused to avoid extra allocations. - Allow trace() to accept a static instruction pointer so it can determine if the instruction is worth tracing. This is moved from the CPU. - provide constants for special meaning PCs (user, console, unknown), instead of magic numbers - switch to using kernelSymtab instead of allSymtab which will be going away - if the stack adjustment doesn't make any sense, exit and push unknown so we don't get into an infinite loop or record garbage. - check to see if we've made too many iterations through the stack and panic to avoid an infinite loop arch/alpha/stacktrace.hh: - Change the StackTrace code so that the class can more easily be cleaned out and reused to avoid extra allocations. - Allow trace() to accept a static instruction pointer so it can determine if the instruction is worth tracing. This is moved from the CPU. - provide constants for special meaning PCs (user, console, unknown), instead of magic numbers cpu/base.cc: only clear the profile if we have one include profile.hh here since base.hh doesn't do it anymore cpu/base.hh: no need to include cpu/profile.hh here cpu/profile.cc: use ProfileNode pointers instead of objects in the ChildList Consume a vector of addresses since that's really all we care about. cpu/profile.hh: Keep pointers to ProfileNodes to reduce the size of these structures keep a StackTrace around so that we may reuse it. provide consume functions that use the new StackTrace trace interface one consume function is inline and tries to fastpath the no trace condition, it calls the outlined consume function if a trace is generated. cpu/simple/cpu.cc: include cpu/profile.hh here since base.hh no longer does use the new FunctionProfile::consume interface (which contains the tracing functions) --HG-- extra : convert_revision : 5a1d9265289a75f67a497b322926be1f8c2d8eb3
Diffstat (limited to 'arch')
-rw-r--r--arch/alpha/stacktrace.cc49
-rw-r--r--arch/alpha/stacktrace.hh32
2 files changed, 60 insertions, 21 deletions
diff --git a/arch/alpha/stacktrace.cc b/arch/alpha/stacktrace.cc
index fdad9d673..5a8df3d35 100644
--- a/arch/alpha/stacktrace.cc
+++ b/arch/alpha/stacktrace.cc
@@ -103,25 +103,42 @@ ProcessInfo::name(Addr ksp) const
return comm;
}
-StackTrace::StackTrace(ExecContext *_xc, bool is_call)
- : xc(_xc)
+StackTrace::StackTrace()
+ : xc(0), stack(64)
+{
+}
+
+StackTrace::StackTrace(ExecContext *_xc, StaticInstPtr<TheISA> inst)
+ : xc(0), stack(64)
{
+ trace(_xc, inst);
+}
+
+StackTrace::~StackTrace()
+{
+}
+
+void
+StackTrace::trace(ExecContext *_xc, bool is_call)
+{
+ xc = _xc;
+
bool usermode = (xc->regs.ipr[AlphaISA::IPR_DTB_CM] & 0x18) != 0;
Addr pc = xc->regs.npc;
bool kernel = xc->system->kernelStart <= pc && pc <= xc->system->kernelEnd;
if (usermode) {
- stack.push_back(1);
+ stack.push_back(user);
return;
}
if (!kernel) {
- stack.push_back(2);
+ stack.push_back(console);
return;
}
- SymbolTable *symtab = xc->system->allSymtab;
+ SymbolTable *symtab = xc->system->kernelSymtab;
Addr ksp = xc->regs.intRegFile[TheISA::StackPointerReg];
Addr bottom = ksp & ~0x3fff;
Addr addr;
@@ -151,10 +168,15 @@ StackTrace::StackTrace(ExecContext *_xc, bool is_call)
if (!ra)
return;
+ if (size <= 0) {
+ stack.push_back(unknown);
+ return;
+ }
+
pc = ra;
ksp += size;
} else {
- stack.push_back(3);
+ stack.push_back(unknown);
return;
}
@@ -162,15 +184,14 @@ StackTrace::StackTrace(ExecContext *_xc, bool is_call)
pc <= xc->system->kernelEnd;
if (!kernel)
return;
+
+ if (stack.size() >= 1000)
+ panic("unwinding too far");
}
panic("unwinding too far");
}
-StackTrace::~StackTrace()
-{
-}
-
bool
StackTrace::isEntry(Addr addr)
{
@@ -302,18 +323,18 @@ void
StackTrace::dump()
{
StringWrap name(xc->cpu->name());
- SymbolTable *symtab = xc->system->allSymtab;
+ SymbolTable *symtab = xc->system->kernelSymtab;
DPRINTFN("------ Stack ------\n");
string symbol;
for (int i = 0, size = stack.size(); i < size; ++i) {
Addr addr = stack[size - i - 1];
- if (addr == 1)
+ if (addr == user)
symbol = "user";
- else if (addr == 2)
+ else if (addr == console)
symbol = "console";
- else if (addr == 3)
+ else if (addr == unknown)
symbol = "unknown";
else
symtab->findSymbol(addr, symbol);
diff --git a/arch/alpha/stacktrace.hh b/arch/alpha/stacktrace.hh
index 5a4741eba..244e574b6 100644
--- a/arch/alpha/stacktrace.hh
+++ b/arch/alpha/stacktrace.hh
@@ -34,7 +34,6 @@
class ExecContext;
class StackTrace;
-class SymbolTable;
class ProcessInfo
{
@@ -67,13 +66,28 @@ class StackTrace
bool decodeSave(MachInst inst, int &reg, int &disp);
bool decodeStack(MachInst inst, int &disp);
+ void trace(ExecContext *xc, bool is_call);
+
public:
- StackTrace(ExecContext *xc, bool is_call);
+ StackTrace();
+ StackTrace(ExecContext *xc, StaticInstPtr<TheISA> inst);
~StackTrace();
+ void clear()
+ {
+ xc = 0;
+ stack.clear();
+ }
+
+ bool valid() const { return xc != NULL; }
+ bool trace(ExecContext *xc, StaticInstPtr<TheISA> inst);
+
public:
const std::vector<Addr> &getstack() const { return stack; }
- static StackTrace *create(ExecContext *xc, StaticInstPtr<TheISA> inst);
+
+ static const int user = 1;
+ static const int console = 2;
+ static const int unknown = 3;
#if TRACING_ON
private:
@@ -87,13 +101,17 @@ class StackTrace
#endif
};
-inline StackTrace *
-StackTrace::create(ExecContext *xc, StaticInstPtr<TheISA> inst)
+inline bool
+StackTrace::trace(ExecContext *xc, StaticInstPtr<TheISA> inst)
{
if (!inst->isCall() && !inst->isReturn())
- return NULL;
+ return false;
+
+ if (valid())
+ clear();
- return new StackTrace(xc, !inst->isReturn());
+ trace(xc, !inst->isReturn());
+ return true;
}
#endif // __ARCH_ALPHA_STACKTRACE_HH__