exetrace.cc revision 10417
12SN/A/*
21762SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan
32SN/A * All rights reserved.
42SN/A *
52SN/A * Redistribution and use in source and binary forms, with or without
62SN/A * modification, are permitted provided that the following conditions are
72SN/A * met: redistributions of source code must retain the above copyright
82SN/A * notice, this list of conditions and the following disclaimer;
92SN/A * redistributions in binary form must reproduce the above copyright
102SN/A * notice, this list of conditions and the following disclaimer in the
112SN/A * documentation and/or other materials provided with the distribution;
122SN/A * neither the name of the copyright holders nor the names of its
132SN/A * contributors may be used to endorse or promote products derived from
142SN/A * this software without specific prior written permission.
152SN/A *
162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt
292665Ssaidi@eecs.umich.edu *          Lisa Hsu
302665Ssaidi@eecs.umich.edu *          Nathan Binkert
312665Ssaidi@eecs.umich.edu *          Steve Raasch
322SN/A */
332SN/A
342SN/A#include <iomanip>
352SN/A
367349SAli.Saidi@ARM.com#include "arch/isa_traits.hh"
377680Sgblack@eecs.umich.edu#include "arch/utility.hh"
3856SN/A#include "base/loader/symtab.hh"
398229Snate@binkert.org#include "config/the_isa.hh"
401717SN/A#include "cpu/base.hh"
412518SN/A#include "cpu/exetrace.hh"
4256SN/A#include "cpu/static_inst.hh"
434776Sgblack@eecs.umich.edu#include "cpu/thread_context.hh"
448232Snate@binkert.org#include "debug/ExecAll.hh"
454762Snate@binkert.org#include "enums/OpClass.hh"
463065Sgblack@eecs.umich.edu
472SN/Ausing namespace std;
482973Sgblack@eecs.umich.eduusing namespace TheISA;
492SN/A
503506Ssaidi@eecs.umich.edunamespace Trace {
514054Sbinkertn@umich.edu
524054Sbinkertn@umich.eduvoid
535866Sksewell@umich.eduExeTracerRecord::dumpTicks(ostream &outs)
545866Sksewell@umich.edu{
555866Sksewell@umich.edu    ccprintf(outs, "%7d: ", when);
565866Sksewell@umich.edu}
575866Sksewell@umich.edu
585866Sksewell@umich.eduvoid
5910417Sandreas.hansson@arm.comTrace::ExeTracerRecord::traceInst(const StaticInstPtr &inst, bool ran)
604054Sbinkertn@umich.edu{
614776Sgblack@eecs.umich.edu    ostream &outs = Trace::output();
624054Sbinkertn@umich.edu
638300Schander.sudanthi@arm.com    if (!Debug::ExecUser || !Debug::ExecKernel) {
648300Schander.sudanthi@arm.com        bool in_user_mode = TheISA::inUserMode(thread);
658300Schander.sudanthi@arm.com        if (in_user_mode && !Debug::ExecUser) return;
668300Schander.sudanthi@arm.com        if (!in_user_mode && !Debug::ExecKernel) return;
678300Schander.sudanthi@arm.com    }
688300Schander.sudanthi@arm.com
698232Snate@binkert.org    if (Debug::ExecTicks)
705866Sksewell@umich.edu        dumpTicks(outs);
714054Sbinkertn@umich.edu
724776Sgblack@eecs.umich.edu    outs << thread->getCpuPtr()->name() << " ";
734054Sbinkertn@umich.edu
748232Snate@binkert.org    if (Debug::ExecSpeculative)
754776Sgblack@eecs.umich.edu        outs << (misspeculating ? "-" : "+") << " ";
764054Sbinkertn@umich.edu
778300Schander.sudanthi@arm.com    if (Debug::ExecAsid)
788300Schander.sudanthi@arm.com        outs << "A" << dec << TheISA::getExecutingAsid(thread) << " ";
798300Schander.sudanthi@arm.com
808232Snate@binkert.org    if (Debug::ExecThread)
815715Shsul@eecs.umich.edu        outs << "T" << thread->threadId() << " : ";
824776Sgblack@eecs.umich.edu
834776Sgblack@eecs.umich.edu    std::string sym_str;
844776Sgblack@eecs.umich.edu    Addr sym_addr;
857720Sgblack@eecs.umich.edu    Addr cur_pc = pc.instAddr();
869809Sumesh.b2006@gmail.com    if (debugSymbolTable && Debug::ExecSymbol &&
879809Sumesh.b2006@gmail.com            (!FullSystem || !inUserMode(thread)) &&
889809Sumesh.b2006@gmail.com            debugSymbolTable->findNearestSymbol(cur_pc, sym_str, sym_addr)) {
897349SAli.Saidi@ARM.com        if (cur_pc != sym_addr)
907349SAli.Saidi@ARM.com            sym_str += csprintf("+%d",cur_pc - sym_addr);
915784Sgblack@eecs.umich.edu        outs << "@" << sym_str;
927720Sgblack@eecs.umich.edu    } else {
937349SAli.Saidi@ARM.com        outs << "0x" << hex << cur_pc;
944776Sgblack@eecs.umich.edu    }
954776Sgblack@eecs.umich.edu
965784Sgblack@eecs.umich.edu    if (inst->isMicroop()) {
977720Sgblack@eecs.umich.edu        outs << "." << setw(2) << dec << pc.microPC();
985784Sgblack@eecs.umich.edu    } else {
995784Sgblack@eecs.umich.edu        outs << "   ";
1005784Sgblack@eecs.umich.edu    }
1015784Sgblack@eecs.umich.edu
1025784Sgblack@eecs.umich.edu    outs << " : ";
1035784Sgblack@eecs.umich.edu
1044776Sgblack@eecs.umich.edu    //
1054776Sgblack@eecs.umich.edu    //  Print decoded instruction
1064776Sgblack@eecs.umich.edu    //
1074776Sgblack@eecs.umich.edu
1084776Sgblack@eecs.umich.edu    outs << setw(26) << left;
1097349SAli.Saidi@ARM.com    outs << inst->disassemble(cur_pc, debugSymbolTable);
1104776Sgblack@eecs.umich.edu
1115784Sgblack@eecs.umich.edu    if (ran) {
1125784Sgblack@eecs.umich.edu        outs << " : ";
1135784Sgblack@eecs.umich.edu
1148232Snate@binkert.org        if (Debug::ExecOpClass) {
1155784Sgblack@eecs.umich.edu            outs << Enums::OpClassStrings[inst->opClass()] << " : ";
1165784Sgblack@eecs.umich.edu        }
1175784Sgblack@eecs.umich.edu
11810231Ssteve.reinhardt@amd.com        if (Debug::ExecResult && !predicate) {
1197600Sminkyu.jeong@arm.com            outs << "Predicated False";
1207600Sminkyu.jeong@arm.com        }
1217600Sminkyu.jeong@arm.com
1228232Snate@binkert.org        if (Debug::ExecResult && data_status != DataInvalid) {
1235784Sgblack@eecs.umich.edu            ccprintf(outs, " D=%#018x", data.as_int);
1245784Sgblack@eecs.umich.edu        }
1255784Sgblack@eecs.umich.edu
1268232Snate@binkert.org        if (Debug::ExecEffAddr && addr_valid)
1275784Sgblack@eecs.umich.edu            outs << " A=0x" << hex << addr;
1285784Sgblack@eecs.umich.edu
1298232Snate@binkert.org        if (Debug::ExecFetchSeq && fetch_seq_valid)
1305784Sgblack@eecs.umich.edu            outs << "  FetchSeq=" << dec << fetch_seq;
1315784Sgblack@eecs.umich.edu
1328232Snate@binkert.org        if (Debug::ExecCPSeq && cp_seq_valid)
1335784Sgblack@eecs.umich.edu            outs << "  CPSeq=" << dec << cp_seq;
13410383Smitch.hayenga@arm.com
13510383Smitch.hayenga@arm.com        if (Debug::ExecFlags) {
13610383Smitch.hayenga@arm.com            outs << "  flags=(";
13710383Smitch.hayenga@arm.com            inst->printFlags(outs, "|");
13810383Smitch.hayenga@arm.com            outs << ")";
13910383Smitch.hayenga@arm.com        }
1404776Sgblack@eecs.umich.edu    }
1414776Sgblack@eecs.umich.edu
1424776Sgblack@eecs.umich.edu    //
1434776Sgblack@eecs.umich.edu    //  End of line...
1444776Sgblack@eecs.umich.edu    //
1454776Sgblack@eecs.umich.edu    outs << endl;
1463506Ssaidi@eecs.umich.edu}
1473506Ssaidi@eecs.umich.edu
1485784Sgblack@eecs.umich.eduvoid
1495784Sgblack@eecs.umich.eduTrace::ExeTracerRecord::dump()
1505784Sgblack@eecs.umich.edu{
1515784Sgblack@eecs.umich.edu    /*
1525784Sgblack@eecs.umich.edu     * The behavior this check tries to achieve is that if ExecMacro is on,
1535784Sgblack@eecs.umich.edu     * the macroop will be printed. If it's on and microops are also on, it's
1545784Sgblack@eecs.umich.edu     * printed before the microops start printing to give context. If the
1555784Sgblack@eecs.umich.edu     * microops aren't printed, then it's printed only when the final microop
1565784Sgblack@eecs.umich.edu     * finishes. Macroops then behave like regular instructions and don't
1575784Sgblack@eecs.umich.edu     * complete/print when they fault.
1585784Sgblack@eecs.umich.edu     */
1598232Snate@binkert.org    if (Debug::ExecMacro && staticInst->isMicroop() &&
1608232Snate@binkert.org        ((Debug::ExecMicro &&
1618232Snate@binkert.org            macroStaticInst && staticInst->isFirstMicroop()) ||
1628232Snate@binkert.org            (!Debug::ExecMicro &&
1635791Srstrong@cs.ucsd.edu             macroStaticInst && staticInst->isLastMicroop()))) {
1645784Sgblack@eecs.umich.edu        traceInst(macroStaticInst, false);
1655784Sgblack@eecs.umich.edu    }
1668232Snate@binkert.org    if (Debug::ExecMicro || !staticInst->isMicroop()) {
1675784Sgblack@eecs.umich.edu        traceInst(staticInst, true);
1685784Sgblack@eecs.umich.edu    }
1695784Sgblack@eecs.umich.edu}
1705784Sgblack@eecs.umich.edu
1717811Ssteve.reinhardt@amd.com} // namespace Trace
1724776Sgblack@eecs.umich.edu
1732SN/A////////////////////////////////////////////////////////////////////////
1742SN/A//
1754776Sgblack@eecs.umich.edu//  ExeTracer Simulation Object
1762SN/A//
1774776Sgblack@eecs.umich.eduTrace::ExeTracer *
1784776Sgblack@eecs.umich.eduExeTracerParams::create()
1793748Sgblack@eecs.umich.edu{
1805034Smilesck@eecs.umich.edu    return new Trace::ExeTracer(this);
1818902Sandreas.hansson@arm.com}
182