exetrace.cc revision 56
113373Sgabeblack@google.com/*
213373Sgabeblack@google.com * Copyright (c) 2003 The Regents of The University of Michigan
313373Sgabeblack@google.com * All rights reserved.
413373Sgabeblack@google.com *
513373Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
613373Sgabeblack@google.com * modification, are permitted provided that the following conditions are
713373Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
813373Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
913373Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1013373Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1113373Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1213373Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1313373Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1413373Sgabeblack@google.com * this software without specific prior written permission.
1513373Sgabeblack@google.com *
1613373Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1713373Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1813373Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1913373Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2013373Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2113373Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2213373Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2313373Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2413373Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2513373Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2613373Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2713373Sgabeblack@google.com */
2813373Sgabeblack@google.com
2913373Sgabeblack@google.com#include <fstream>
3013373Sgabeblack@google.com#include <iomanip>
3113373Sgabeblack@google.com
3213373Sgabeblack@google.com#include "cpu/full_cpu/dyn_inst.hh"
3313373Sgabeblack@google.com#include "cpu/full_cpu/spec_state.hh"
3413373Sgabeblack@google.com#include "cpu/full_cpu/issue.hh"
3513373Sgabeblack@google.com#include "cpu/exetrace.hh"
3613373Sgabeblack@google.com#include "cpu/exec_context.hh"
3713373Sgabeblack@google.com#include "base/loader/symtab.hh"
3813373Sgabeblack@google.com#include "cpu/base_cpu.hh"
3913373Sgabeblack@google.com#include "cpu/static_inst.hh"
4013373Sgabeblack@google.com
4113373Sgabeblack@google.comusing namespace std;
4213373Sgabeblack@google.com
4313373Sgabeblack@google.com
4413373Sgabeblack@google.com////////////////////////////////////////////////////////////////////////
4513373Sgabeblack@google.com//
4613373Sgabeblack@google.com//  Methods for the InstRecord object
4713373Sgabeblack@google.com//
4813373Sgabeblack@google.com
4913373Sgabeblack@google.com
5013373Sgabeblack@google.comconst SymbolTable *debugSymbolTable = NULL;
5113373Sgabeblack@google.com
5213373Sgabeblack@google.comvoid
5313373Sgabeblack@google.comTrace::InstRecord::dump(ostream &outs)
5413373Sgabeblack@google.com{
5513373Sgabeblack@google.com    if (flags[PRINT_CYCLE])
5613373Sgabeblack@google.com        ccprintf(outs, "%7d: ", cycle);
5713373Sgabeblack@google.com
5813373Sgabeblack@google.com    outs << cpu->name() << " ";
5913373Sgabeblack@google.com
6013373Sgabeblack@google.com    if (flags[TRACE_MISSPEC])
6113373Sgabeblack@google.com        outs << (misspeculating ? "-" : "+") << " ";
6213373Sgabeblack@google.com
6313373Sgabeblack@google.com    if (flags[PRINT_THREAD_NUM])
6413373Sgabeblack@google.com        outs << "T" << thread << " : ";
6513373Sgabeblack@google.com
6613373Sgabeblack@google.com    outs << "0x" << hex << PC << " : ";
6713373Sgabeblack@google.com
6813373Sgabeblack@google.com    //
6913373Sgabeblack@google.com    //  Print decoded instruction
7013373Sgabeblack@google.com    //
7113373Sgabeblack@google.com
7213373Sgabeblack@google.com#if defined(__GNUC__) && (__GNUC__ < 3)
7313373Sgabeblack@google.com    // There's a bug in gcc 2.x library that prevents setw()
7413373Sgabeblack@google.com    // from working properly on strings
7513373Sgabeblack@google.com    string mc(staticInst->disassemble(PC, debugSymbolTable));
7613373Sgabeblack@google.com    while (mc.length() < 25)
7713373Sgabeblack@google.com        mc += " ";
7813373Sgabeblack@google.com    outs << mc;
7913373Sgabeblack@google.com#else
8013373Sgabeblack@google.com    outs << setw(25) << staticInst->disassemble(PC, debugSymbolTable);
8113373Sgabeblack@google.com#endif
8213373Sgabeblack@google.com
8313373Sgabeblack@google.com    outs << " : ";
8413373Sgabeblack@google.com
8513373Sgabeblack@google.com    if (flags[PRINT_OP_CLASS]) {
8613373Sgabeblack@google.com        outs << opClassStrings[staticInst->opClass()] << " : ";
8713373Sgabeblack@google.com    }
8813373Sgabeblack@google.com
8913373Sgabeblack@google.com    if (flags[PRINT_RESULT_DATA] && data_status != DataInvalid) {
9013373Sgabeblack@google.com        outs << " D=";
91#if 0
92        if (data_status == DataDouble)
93            ccprintf(outs, "%f", data.as_double);
94        else
95            ccprintf(outs, "%#018x", data.as_int);
96#else
97        ccprintf(outs, "%#018x", data.as_int);
98#endif
99    }
100
101    if (flags[PRINT_EFF_ADDR] && addr_valid)
102        outs << " A=0x" << hex << addr;
103
104    if (flags[PRINT_INT_REGS] && regs_valid) {
105        for (int i = 0; i < 32;)
106            for (int j = i + 1; i <= j; i++)
107                ccprintf(outs, "r%02d = %#018x%s", i, iregs->regs[i],
108                         ((i == j) ? "\n" : "    "));
109        outs << "\n";
110    }
111
112    if (flags[PRINT_FETCH_SEQ] && fetch_seq_valid)
113        outs << "  FetchSeq=" << dec << fetch_seq;
114
115    if (flags[PRINT_CP_SEQ] && cp_seq_valid)
116        outs << "  CPSeq=" << dec << cp_seq;
117
118    //
119    //  End of line...
120    //
121    outs << endl;
122    outs.flush();
123}
124
125
126vector<bool> Trace::InstRecord::flags(NUM_BITS);
127
128////////////////////////////////////////////////////////////////////////
129//
130// Parameter space for per-cycle execution address tracing options.
131// Derive from ParamContext so we can override checkParams() function.
132//
133class ExecutionTraceParamContext : public ParamContext
134{
135  public:
136    ExecutionTraceParamContext(const string &_iniSection)
137        : ParamContext(_iniSection)
138        {
139        }
140
141    void checkParams();	// defined at bottom of file
142};
143
144ExecutionTraceParamContext exeTraceParams("exetrace");
145
146Param<bool> exe_trace_spec(&exeTraceParams, "speculative",
147                           "capture speculative instructions", false);
148
149Param<bool> exe_trace_print_cycle(&exeTraceParams, "print_cycle",
150                                  "print cycle number", true);
151Param<bool> exe_trace_print_opclass(&exeTraceParams, "print_opclass",
152                                  "print op class", true);
153Param<bool> exe_trace_print_thread(&exeTraceParams, "print_thread",
154                                  "print thread number", true);
155Param<bool> exe_trace_print_effaddr(&exeTraceParams, "print_effaddr",
156                                  "print effective address", true);
157Param<bool> exe_trace_print_data(&exeTraceParams, "print_data",
158                                  "print result data", true);
159Param<bool> exe_trace_print_iregs(&exeTraceParams, "print_iregs",
160                                  "print all integer regs", false);
161Param<bool> exe_trace_print_fetchseq(&exeTraceParams, "print_fetchseq",
162                                  "print fetch sequence number", false);
163Param<bool> exe_trace_print_cp_seq(&exeTraceParams, "print_cpseq",
164                                  "print correct-path sequence number", false);
165
166//
167// Helper function for ExecutionTraceParamContext::checkParams() just
168// to get us into the InstRecord namespace
169//
170void
171Trace::InstRecord::setParams()
172{
173    flags[TRACE_MISSPEC]     = exe_trace_spec;
174
175    flags[PRINT_CYCLE]       = exe_trace_print_cycle;
176    flags[PRINT_OP_CLASS]    = exe_trace_print_opclass;
177    flags[PRINT_THREAD_NUM]  = exe_trace_print_thread;
178    flags[PRINT_RESULT_DATA] = exe_trace_print_effaddr;
179    flags[PRINT_EFF_ADDR]    = exe_trace_print_data;
180    flags[PRINT_INT_REGS]    = exe_trace_print_iregs;
181    flags[PRINT_FETCH_SEQ]   = exe_trace_print_fetchseq;
182    flags[PRINT_CP_SEQ]      = exe_trace_print_cp_seq;
183}
184
185void
186ExecutionTraceParamContext::checkParams()
187{
188    Trace::InstRecord::setParams();
189}
190
191