exetrace.cc revision 8902
15094Sgblack@eecs.umich.edu/*
22632Sstever@eecs.umich.edu * Copyright (c) 2001-2005 The Regents of The University of Michigan
32632Sstever@eecs.umich.edu * All rights reserved.
42632Sstever@eecs.umich.edu *
52632Sstever@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
62632Sstever@eecs.umich.edu * modification, are permitted provided that the following conditions are
72632Sstever@eecs.umich.edu * met: redistributions of source code must retain the above copyright
82632Sstever@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
92632Sstever@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
102632Sstever@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
112632Sstever@eecs.umich.edu * documentation and/or other materials provided with the distribution;
122632Sstever@eecs.umich.edu * neither the name of the copyright holders nor the names of its
132632Sstever@eecs.umich.edu * contributors may be used to endorse or promote products derived from
142632Sstever@eecs.umich.edu * this software without specific prior written permission.
152632Sstever@eecs.umich.edu *
162632Sstever@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172632Sstever@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182632Sstever@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192632Sstever@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202632Sstever@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212632Sstever@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222632Sstever@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232632Sstever@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242632Sstever@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252632Sstever@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262632Sstever@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272632Sstever@eecs.umich.edu *
282632Sstever@eecs.umich.edu * Authors: Steve Reinhardt
292632Sstever@eecs.umich.edu *          Lisa Hsu
302632Sstever@eecs.umich.edu *          Nathan Binkert
312469SN/A *          Steve Raasch
322469SN/A */
332482SN/A
342469SN/A#include <iomanip>
352469SN/A
363599Sgblack@eecs.umich.edu#include "arch/isa_traits.hh"
3712287Sgabeblack@google.com#include "arch/utility.hh"
3812287Sgabeblack@google.com#include "base/loader/symtab.hh"
3912287Sgabeblack@google.com#include "config/the_isa.hh"
4012287Sgabeblack@google.com#include "cpu/base.hh"
4112287Sgabeblack@google.com#include "cpu/exetrace.hh"
422469SN/A#include "cpu/static_inst.hh"
432469SN/A#include "cpu/thread_context.hh"
442469SN/A#include "debug/ExecAll.hh"
4512287Sgabeblack@google.com#include "enums/OpClass.hh"
4612287Sgabeblack@google.com
4712287Sgabeblack@google.comusing namespace std;
4812287Sgabeblack@google.comusing namespace TheISA;
4912287Sgabeblack@google.com
502469SN/Anamespace Trace {
5112287Sgabeblack@google.com
5212287Sgabeblack@google.comvoid
5312287Sgabeblack@google.comExeTracerRecord::dumpTicks(ostream &outs)
542469SN/A{
5512287Sgabeblack@google.com    ccprintf(outs, "%7d: ", when);
565094Sgblack@eecs.umich.edu}
5712287Sgabeblack@google.com
5812287Sgabeblack@google.comvoid
5912287Sgabeblack@google.comTrace::ExeTracerRecord::traceInst(StaticInstPtr inst, bool ran)
6012287Sgabeblack@google.com{
6112287Sgabeblack@google.com    ostream &outs = Trace::output();
622469SN/A
632469SN/A    if (!Debug::ExecUser || !Debug::ExecKernel) {
642526SN/A        bool in_user_mode = TheISA::inUserMode(thread);
6512287Sgabeblack@google.com        if (in_user_mode && !Debug::ExecUser) return;
6612287Sgabeblack@google.com        if (!in_user_mode && !Debug::ExecKernel) return;
6712287Sgabeblack@google.com    }
6812287Sgabeblack@google.com
6912287Sgabeblack@google.com    if (Debug::ExecTicks)
7012287Sgabeblack@google.com        dumpTicks(outs);
7112287Sgabeblack@google.com
7212287Sgabeblack@google.com    outs << thread->getCpuPtr()->name() << " ";
7312287Sgabeblack@google.com
7412287Sgabeblack@google.com    if (Debug::ExecSpeculative)
7512287Sgabeblack@google.com        outs << (misspeculating ? "-" : "+") << " ";
7612287Sgabeblack@google.com
7712287Sgabeblack@google.com    if (Debug::ExecAsid)
783599Sgblack@eecs.umich.edu        outs << "A" << dec << TheISA::getExecutingAsid(thread) << " ";
793599Sgblack@eecs.umich.edu
8012287Sgabeblack@google.com    if (Debug::ExecThread)
813599Sgblack@eecs.umich.edu        outs << "T" << thread->threadId() << " : ";
8212287Sgabeblack@google.com
833599Sgblack@eecs.umich.edu    std::string sym_str;
843599Sgblack@eecs.umich.edu    Addr sym_addr;
853599Sgblack@eecs.umich.edu    Addr cur_pc = pc.instAddr();
8612287Sgabeblack@google.com    if (debugSymbolTable && Debug::ExecSymbol && !inUserMode(thread)
873599Sgblack@eecs.umich.edu        && debugSymbolTable->findNearestSymbol(cur_pc, sym_str, sym_addr)) {
8812287Sgabeblack@google.com        if (cur_pc != sym_addr)
893599Sgblack@eecs.umich.edu            sym_str += csprintf("+%d",cur_pc - sym_addr);
9012287Sgabeblack@google.com        outs << "@" << sym_str;
9112287Sgabeblack@google.com    } else {
9212287Sgabeblack@google.com        outs << "0x" << hex << cur_pc;
933792Sgblack@eecs.umich.edu    }
942469SN/A
9512287Sgabeblack@google.com    if (inst->isMicroop()) {
963599Sgblack@eecs.umich.edu        outs << "." << setw(2) << dec << pc.microPC();
973599Sgblack@eecs.umich.edu    } else {
983599Sgblack@eecs.umich.edu        outs << "   ";
992469SN/A    }
10012287Sgabeblack@google.com
10112287Sgabeblack@google.com    outs << " : ";
10212287Sgabeblack@google.com
10312287Sgabeblack@google.com    //
1043792Sgblack@eecs.umich.edu    //  Print decoded instruction
1052469SN/A    //
10612287Sgabeblack@google.com
1073599Sgblack@eecs.umich.edu    outs << setw(26) << left;
1083599Sgblack@eecs.umich.edu    outs << inst->disassemble(cur_pc, debugSymbolTable);
1093599Sgblack@eecs.umich.edu
1102469SN/A    if (ran) {
1112482SN/A        outs << " : ";
1122469SN/A
1132469SN/A        if (Debug::ExecOpClass) {
1142526SN/A            outs << Enums::OpClassStrings[inst->opClass()] << " : ";
1152526SN/A        }
1162526SN/A
11712287Sgabeblack@google.com        if (Debug::ExecResult && predicate == false) {
11812287Sgabeblack@google.com            outs << "Predicated False";
11912287Sgabeblack@google.com        }
12012287Sgabeblack@google.com
12112287Sgabeblack@google.com        if (Debug::ExecResult && data_status != DataInvalid) {
1223587Sgblack@eecs.umich.edu            ccprintf(outs, " D=%#018x", data.as_int);
1233587Sgblack@eecs.umich.edu        }
12412287Sgabeblack@google.com
12512287Sgabeblack@google.com        if (Debug::ExecEffAddr && addr_valid)
12612287Sgabeblack@google.com            outs << " A=0x" << hex << addr;
12712287Sgabeblack@google.com
12812287Sgabeblack@google.com        if (Debug::ExecFetchSeq && fetch_seq_valid)
12912287Sgabeblack@google.com            outs << "  FetchSeq=" << dec << fetch_seq;
13012287Sgabeblack@google.com
1313587Sgblack@eecs.umich.edu        if (Debug::ExecCPSeq && cp_seq_valid)
1323587Sgblack@eecs.umich.edu            outs << "  CPSeq=" << dec << cp_seq;
13312287Sgabeblack@google.com    }
13412287Sgabeblack@google.com
13512287Sgabeblack@google.com    //
13612287Sgabeblack@google.com    //  End of line...
13712287Sgabeblack@google.com    //
1382469SN/A    outs << endl;
1392469SN/A}
140
141void
142Trace::ExeTracerRecord::dump()
143{
144    /*
145     * The behavior this check tries to achieve is that if ExecMacro is on,
146     * the macroop will be printed. If it's on and microops are also on, it's
147     * printed before the microops start printing to give context. If the
148     * microops aren't printed, then it's printed only when the final microop
149     * finishes. Macroops then behave like regular instructions and don't
150     * complete/print when they fault.
151     */
152    if (Debug::ExecMacro && staticInst->isMicroop() &&
153        ((Debug::ExecMicro &&
154            macroStaticInst && staticInst->isFirstMicroop()) ||
155            (!Debug::ExecMicro &&
156             macroStaticInst && staticInst->isLastMicroop()))) {
157        traceInst(macroStaticInst, false);
158    }
159    if (Debug::ExecMicro || !staticInst->isMicroop()) {
160        traceInst(staticInst, true);
161    }
162}
163
164} // namespace Trace
165
166////////////////////////////////////////////////////////////////////////
167//
168//  ExeTracer Simulation Object
169//
170Trace::ExeTracer *
171ExeTracerParams::create()
172{
173    return new Trace::ExeTracer(this);
174}
175