exetrace.cc revision 2
1/*
2 * Copyright (c) 2003 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <fstream>
30#include <iomanip>
31
32#include "dyn_inst.hh"
33#include "spec_state.hh"
34#include "issue.hh"
35#include "exetrace.hh"
36#include "exec_context.hh"
37#include "symtab.hh"
38#include "base_cpu.hh"
39#include "static_inst.hh"
40
41using namespace std;
42
43
44////////////////////////////////////////////////////////////////////////
45//
46//  Methods for the InstRecord object
47//
48
49
50const SymbolTable *debugSymbolTable = NULL;
51
52void
53Trace::InstRecord::dump(ostream &outs)
54{
55    if (flags[PRINT_CYCLE])
56        ccprintf(outs, "%7d: ", cycle);
57
58    outs << cpu->name() << " ";
59
60    if (flags[TRACE_MISSPEC])
61        outs << (misspeculating ? "-" : "+") << " ";
62
63    if (flags[PRINT_THREAD_NUM])
64        outs << "T" << thread << " : ";
65
66    outs << "0x" << hex << PC << " : ";
67
68    //
69    //  Print decoded instruction
70    //
71
72#if defined(__GNUC__) && (__GNUC__ < 3)
73    // There's a bug in gcc 2.x library that prevents setw()
74    // from working properly on strings
75    string mc(staticInst->disassemble(PC, debugSymbolTable));
76    while (mc.length() < 25)
77        mc += " ";
78    outs << mc;
79#else
80    outs << setw(25) << staticInst->disassemble(PC, debugSymbolTable);
81#endif
82
83    outs << " : ";
84
85    if (flags[PRINT_OP_CLASS]) {
86        outs << opClassStrings[staticInst->opClass()] << " : ";
87    }
88
89    if (flags[PRINT_RESULT_DATA] && data_status != DataInvalid) {
90        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