kvm, mem: Refactor some Event subclasses into lambdas
[gem5.git] / src / cpu / exetrace.cc
index 0118dbde1b22b9a0562b354ff591b3668e358b80..bbde89c006b029971e4dfb19e871c2ea4b06ea4c 100644 (file)
  *          Steve Raasch
  */
 
+#include "cpu/exetrace.hh"
+
 #include <iomanip>
 
+#include "arch/isa_traits.hh"
+#include "arch/utility.hh"
 #include "base/loader/symtab.hh"
+#include "config/the_isa.hh"
 #include "cpu/base.hh"
-#include "cpu/exetrace.hh"
 #include "cpu/static_inst.hh"
 #include "cpu/thread_context.hh"
+#include "debug/ExecAll.hh"
 #include "enums/OpClass.hh"
 
 using namespace std;
@@ -46,59 +51,91 @@ using namespace TheISA;
 namespace Trace {
 
 void
-Trace::ExeTracerRecord::dump()
+ExeTracerRecord::dumpTicks(ostream &outs)
+{
+    ccprintf(outs, "%7d: ", when);
+}
+
+void
+Trace::ExeTracerRecord::traceInst(const StaticInstPtr &inst, bool ran)
 {
     ostream &outs = Trace::output();
 
-    if (IsOn(ExecTicks))
-        ccprintf(outs, "%7d: ", when);
+    if (!Debug::ExecUser || !Debug::ExecKernel) {
+        bool in_user_mode = TheISA::inUserMode(thread);
+        if (in_user_mode && !Debug::ExecUser) return;
+        if (!in_user_mode && !Debug::ExecKernel) return;
+    }
 
-    outs << thread->getCpuPtr()->name() << " ";
+    if (Debug::ExecTicks)
+        dumpTicks(outs);
 
-    if (IsOn(ExecSpeculative))
-        outs << (misspeculating ? "-" : "+") << " ";
+    outs << thread->getCpuPtr()->name() << " ";
 
-    if (IsOn(ExecThread))
-        outs << "T" << thread->getThreadNum() << " : ";
+    if (Debug::ExecAsid)
+        outs << "A" << dec << TheISA::getExecutingAsid(thread) << " ";
 
+    if (Debug::ExecThread)
+        outs << "T" << thread->threadId() << " : ";
 
     std::string sym_str;
     Addr sym_addr;
-    if (debugSymbolTable
-        && IsOn(ExecSymbol)
-        && debugSymbolTable->findNearestSymbol(PC, sym_str, sym_addr)) {
-        if (PC != sym_addr)
-            sym_str += csprintf("+%d", PC - sym_addr);
-        outs << "@" << sym_str << " : ";
+    Addr cur_pc = pc.instAddr();
+    if (debugSymbolTable && Debug::ExecSymbol &&
+            (!FullSystem || !inUserMode(thread)) &&
+            debugSymbolTable->findNearestSymbol(cur_pc, sym_str, sym_addr)) {
+        if (cur_pc != sym_addr)
+            sym_str += csprintf("+%d",cur_pc - sym_addr);
+        outs << "@" << sym_str;
+    } else {
+        outs << "0x" << hex << cur_pc;
     }
-    else {
-        outs << "0x" << hex << PC << " : ";
+
+    if (inst->isMicroop()) {
+        outs << "." << setw(2) << dec << pc.microPC();
+    } else {
+        outs << "   ";
     }
 
+    outs << " : ";
+
     //
     //  Print decoded instruction
     //
 
     outs << setw(26) << left;
-    outs << staticInst->disassemble(PC, debugSymbolTable);
-    outs << " : ";
+    outs << inst->disassemble(cur_pc, debugSymbolTable);
 
-    if (IsOn(ExecOpClass)) {
-        outs << Enums::OpClassStrings[staticInst->opClass()] << " : ";
-    }
+    if (ran) {
+        outs << " : ";
 
-    if (IsOn(ExecResult) && data_status != DataInvalid) {
-        ccprintf(outs, " D=%#018x", data.as_int);
-    }
+        if (Debug::ExecOpClass) {
+            outs << Enums::OpClassStrings[inst->opClass()] << " : ";
+        }
+
+        if (Debug::ExecResult && !predicate) {
+            outs << "Predicated False";
+        }
+
+        if (Debug::ExecResult && data_status != DataInvalid) {
+            ccprintf(outs, " D=%#018x", data.as_int);
+        }
 
-    if (IsOn(ExecEffAddr) && addr_valid)
-        outs << " A=0x" << hex << addr;
+        if (Debug::ExecEffAddr && getMemValid())
+            outs << " A=0x" << hex << addr;
 
-    if (IsOn(ExecFetchSeq) && fetch_seq_valid)
-        outs << "  FetchSeq=" << dec << fetch_seq;
+        if (Debug::ExecFetchSeq && fetch_seq_valid)
+            outs << "  FetchSeq=" << dec << fetch_seq;
 
-    if (IsOn(ExecCPSeq) && cp_seq_valid)
-        outs << "  CPSeq=" << dec << cp_seq;
+        if (Debug::ExecCPSeq && cp_seq_valid)
+            outs << "  CPSeq=" << dec << cp_seq;
+
+        if (Debug::ExecFlags) {
+            outs << "  flags=(";
+            inst->printFlags(outs, "|");
+            outs << ")";
+        }
+    }
 
     //
     //  End of line...
@@ -106,7 +143,30 @@ Trace::ExeTracerRecord::dump()
     outs << endl;
 }
 
-/* namespace Trace */ }
+void
+Trace::ExeTracerRecord::dump()
+{
+    /*
+     * The behavior this check tries to achieve is that if ExecMacro is on,
+     * the macroop will be printed. If it's on and microops are also on, it's
+     * printed before the microops start printing to give context. If the
+     * microops aren't printed, then it's printed only when the final microop
+     * finishes. Macroops then behave like regular instructions and don't
+     * complete/print when they fault.
+     */
+    if (Debug::ExecMacro && staticInst->isMicroop() &&
+        ((Debug::ExecMicro &&
+            macroStaticInst && staticInst->isFirstMicroop()) ||
+            (!Debug::ExecMicro &&
+             macroStaticInst && staticInst->isLastMicroop()))) {
+        traceInst(macroStaticInst, false);
+    }
+    if (Debug::ExecMicro || !staticInst->isMicroop()) {
+        traceInst(staticInst, true);
+    }
+}
+
+} // namespace Trace
 
 ////////////////////////////////////////////////////////////////////////
 //
@@ -116,4 +176,4 @@ Trace::ExeTracer *
 ExeTracerParams::create()
 {
     return new Trace::ExeTracer(this);
-};
+}