exetrace.cc revision 8229
113521Sgabeblack@google.com/* 213521Sgabeblack@google.com * Copyright (c) 2001-2005 The Regents of The University of Michigan 313521Sgabeblack@google.com * All rights reserved. 413521Sgabeblack@google.com * 513521Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 613521Sgabeblack@google.com * modification, are permitted provided that the following conditions are 713521Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 813521Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 913521Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1013521Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1113521Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1213521Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1313521Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1413521Sgabeblack@google.com * this software without specific prior written permission. 1513521Sgabeblack@google.com * 1613521Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1713521Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1813521Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1913521Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2013521Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2113521Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2213521Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2313521Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2413521Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2513521Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2613521Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2713521Sgabeblack@google.com * 2813521Sgabeblack@google.com * Authors: Steve Reinhardt 2913521Sgabeblack@google.com * Lisa Hsu 3013521Sgabeblack@google.com * Nathan Binkert 3113521Sgabeblack@google.com * Steve Raasch 3213521Sgabeblack@google.com */ 3313521Sgabeblack@google.com 3413521Sgabeblack@google.com#include <iomanip> 3513521Sgabeblack@google.com 3613521Sgabeblack@google.com#include "arch/isa_traits.hh" 3713521Sgabeblack@google.com#include "arch/utility.hh" 3813521Sgabeblack@google.com#include "base/loader/symtab.hh" 3913521Sgabeblack@google.com#include "config/the_isa.hh" 4013521Sgabeblack@google.com#include "cpu/base.hh" 4113521Sgabeblack@google.com#include "cpu/exetrace.hh" 4213521Sgabeblack@google.com#include "cpu/static_inst.hh" 4313521Sgabeblack@google.com#include "cpu/thread_context.hh" 4413521Sgabeblack@google.com#include "enums/OpClass.hh" 4513521Sgabeblack@google.com 4613521Sgabeblack@google.comusing namespace std; 4713521Sgabeblack@google.comusing namespace TheISA; 4813521Sgabeblack@google.com 4913521Sgabeblack@google.comnamespace Trace { 5013521Sgabeblack@google.com 5113521Sgabeblack@google.comvoid 5213521Sgabeblack@google.comExeTracerRecord::dumpTicks(ostream &outs) 5313521Sgabeblack@google.com{ 5413521Sgabeblack@google.com ccprintf(outs, "%7d: ", when); 5513521Sgabeblack@google.com} 5613521Sgabeblack@google.com 5713521Sgabeblack@google.comvoid 5813521Sgabeblack@google.comTrace::ExeTracerRecord::traceInst(StaticInstPtr inst, bool ran) 5913521Sgabeblack@google.com{ 6013521Sgabeblack@google.com ostream &outs = Trace::output(); 6113521Sgabeblack@google.com 6213521Sgabeblack@google.com if (IsOn(ExecTicks)) 6313521Sgabeblack@google.com dumpTicks(outs); 6413521Sgabeblack@google.com 6513521Sgabeblack@google.com outs << thread->getCpuPtr()->name() << " "; 6613521Sgabeblack@google.com 6713521Sgabeblack@google.com if (IsOn(ExecSpeculative)) 6813521Sgabeblack@google.com outs << (misspeculating ? "-" : "+") << " "; 6913521Sgabeblack@google.com 7013521Sgabeblack@google.com if (IsOn(ExecThread)) 7113521Sgabeblack@google.com outs << "T" << thread->threadId() << " : "; 7213521Sgabeblack@google.com 7313521Sgabeblack@google.com std::string sym_str; 7413521Sgabeblack@google.com Addr sym_addr; 7513521Sgabeblack@google.com Addr cur_pc = pc.instAddr(); 7613521Sgabeblack@google.com if (debugSymbolTable 7713521Sgabeblack@google.com && IsOn(ExecSymbol) 7813521Sgabeblack@google.com#if FULL_SYSTEM 7913521Sgabeblack@google.com && !inUserMode(thread) 8013521Sgabeblack@google.com#endif 8113521Sgabeblack@google.com && debugSymbolTable->findNearestSymbol(cur_pc, sym_str, sym_addr)) { 8213521Sgabeblack@google.com if (cur_pc != sym_addr) 8313521Sgabeblack@google.com sym_str += csprintf("+%d",cur_pc - sym_addr); 8413521Sgabeblack@google.com outs << "@" << sym_str; 8513521Sgabeblack@google.com } else { 8613521Sgabeblack@google.com outs << "0x" << hex << cur_pc; 8713521Sgabeblack@google.com } 8813521Sgabeblack@google.com 8913521Sgabeblack@google.com if (inst->isMicroop()) { 9013521Sgabeblack@google.com outs << "." << setw(2) << dec << pc.microPC(); 9113521Sgabeblack@google.com } else { 9213521Sgabeblack@google.com outs << " "; 9313521Sgabeblack@google.com } 9413521Sgabeblack@google.com 9513521Sgabeblack@google.com outs << " : "; 9613521Sgabeblack@google.com 9713521Sgabeblack@google.com // 9813521Sgabeblack@google.com // Print decoded instruction 9913521Sgabeblack@google.com // 10013521Sgabeblack@google.com 10113521Sgabeblack@google.com outs << setw(26) << left; 10213521Sgabeblack@google.com outs << inst->disassemble(cur_pc, debugSymbolTable); 10313521Sgabeblack@google.com 10413521Sgabeblack@google.com if (ran) { 10513521Sgabeblack@google.com outs << " : "; 10613521Sgabeblack@google.com 10713521Sgabeblack@google.com if (IsOn(ExecOpClass)) { 10813521Sgabeblack@google.com outs << Enums::OpClassStrings[inst->opClass()] << " : "; 10913521Sgabeblack@google.com } 11013521Sgabeblack@google.com 11113521Sgabeblack@google.com if (IsOn(ExecResult) && predicate == false) { 11213521Sgabeblack@google.com outs << "Predicated False"; 11313521Sgabeblack@google.com } 11413521Sgabeblack@google.com 11513521Sgabeblack@google.com if (IsOn(ExecResult) && data_status != DataInvalid) { 11613521Sgabeblack@google.com ccprintf(outs, " D=%#018x", data.as_int); 11713521Sgabeblack@google.com } 11813521Sgabeblack@google.com 11913521Sgabeblack@google.com if (IsOn(ExecEffAddr) && addr_valid) 12013521Sgabeblack@google.com outs << " A=0x" << hex << addr; 12113521Sgabeblack@google.com 12213521Sgabeblack@google.com if (IsOn(ExecFetchSeq) && fetch_seq_valid) 12313521Sgabeblack@google.com outs << " FetchSeq=" << dec << fetch_seq; 12413521Sgabeblack@google.com 12513521Sgabeblack@google.com if (IsOn(ExecCPSeq) && cp_seq_valid) 12613521Sgabeblack@google.com outs << " CPSeq=" << dec << cp_seq; 12713521Sgabeblack@google.com } 12813521Sgabeblack@google.com 12913521Sgabeblack@google.com // 13013521Sgabeblack@google.com // End of line... 13113521Sgabeblack@google.com // 13213521Sgabeblack@google.com outs << endl; 13313521Sgabeblack@google.com} 13413521Sgabeblack@google.com 13513521Sgabeblack@google.comvoid 13613521Sgabeblack@google.comTrace::ExeTracerRecord::dump() 13713521Sgabeblack@google.com{ 13813521Sgabeblack@google.com /* 13913521Sgabeblack@google.com * The behavior this check tries to achieve is that if ExecMacro is on, 14013521Sgabeblack@google.com * the macroop will be printed. If it's on and microops are also on, it's 14113521Sgabeblack@google.com * printed before the microops start printing to give context. If the 14213521Sgabeblack@google.com * microops aren't printed, then it's printed only when the final microop 14313521Sgabeblack@google.com * finishes. Macroops then behave like regular instructions and don't 14413521Sgabeblack@google.com * complete/print when they fault. 14513521Sgabeblack@google.com */ 14613521Sgabeblack@google.com if (IsOn(ExecMacro) && staticInst->isMicroop() && 14713521Sgabeblack@google.com ((IsOn(ExecMicro) && 14813521Sgabeblack@google.com macroStaticInst && staticInst->isFirstMicroop()) || 14913521Sgabeblack@google.com (!IsOn(ExecMicro) && 15013521Sgabeblack@google.com macroStaticInst && staticInst->isLastMicroop()))) { 15113521Sgabeblack@google.com traceInst(macroStaticInst, false); 15213521Sgabeblack@google.com } 15313521Sgabeblack@google.com if (IsOn(ExecMicro) || !staticInst->isMicroop()) { 15413521Sgabeblack@google.com traceInst(staticInst, true); 15513521Sgabeblack@google.com } 156} 157 158} // namespace Trace 159 160//////////////////////////////////////////////////////////////////////// 161// 162// ExeTracer Simulation Object 163// 164Trace::ExeTracer * 165ExeTracerParams::create() 166{ 167 return new Trace::ExeTracer(this); 168}; 169