exetrace.cc revision 1967
1/*
2 * Copyright (c) 2001-2005 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 "sim/param.hh"
33#include "encumbered/cpu/full/dyn_inst.hh"
34#include "encumbered/cpu/full/spec_state.hh"
35#include "encumbered/cpu/full/issue.hh"
36#include "cpu/exetrace.hh"
37#include "cpu/exec_context.hh"
38#include "base/loader/symtab.hh"
39#include "cpu/base.hh"
40#include "cpu/static_inst.hh"
41
42using namespace std;
43
44
45////////////////////////////////////////////////////////////////////////
46//
47//  Methods for the InstRecord object
48//
49
50
51void
52Trace::InstRecord::dump(ostream &outs)
53{
54    if (flags[INTEL_FORMAT]) {
55        if (cpu->system->name() == trace_system) {
56            ccprintf(outs, "%7d ) ", cycle);
57            outs << "0x" << hex << PC << ":\t";
58            if (staticInst->isLoad()) {
59                outs << "<RD 0x" << hex << addr;
60                outs << ">";
61            } else if (staticInst->isStore()) {
62                outs << "<WR 0x" << hex << addr;
63                outs << ">";
64            }
65            outs << endl;
66        }
67    } else {
68        if (flags[PRINT_CYCLE])
69            ccprintf(outs, "%7d: ", cycle);
70
71        outs << cpu->name() << " ";
72
73        if (flags[TRACE_MISSPEC])
74            outs << (misspeculating ? "-" : "+") << " ";
75
76        if (flags[PRINT_THREAD_NUM])
77            outs << "T" << thread << " : ";
78
79
80        std::string sym_str;
81        Addr sym_addr;
82        if (debugSymbolTable
83            && debugSymbolTable->findNearestSymbol(PC, sym_str, sym_addr)) {
84            if (PC != sym_addr)
85                sym_str += csprintf("+%d", PC - sym_addr);
86            outs << "@" << sym_str << " : ";
87        }
88        else {
89            outs << "0x" << hex << PC << " : ";
90        }
91
92        //
93        //  Print decoded instruction
94        //
95
96#if defined(__GNUC__) && (__GNUC__ < 3)
97        // There's a bug in gcc 2.x library that prevents setw()
98        // from working properly on strings
99        string mc(staticInst->disassemble(PC, debugSymbolTable));
100        while (mc.length() < 26)
101            mc += " ";
102        outs << mc;
103#else
104        outs << setw(26) << left << staticInst->disassemble(PC, debugSymbolTable);
105#endif
106
107        outs << " : ";
108
109        if (flags[PRINT_OP_CLASS]) {
110            outs << opClassStrings[staticInst->opClass()] << " : ";
111        }
112
113        if (flags[PRINT_RESULT_DATA] && data_status != DataInvalid) {
114            outs << " D=";
115#if 0
116            if (data_status == DataDouble)
117                ccprintf(outs, "%f", data.as_double);
118            else
119                ccprintf(outs, "%#018x", data.as_int);
120#else
121            ccprintf(outs, "%#018x", data.as_int);
122#endif
123        }
124
125        if (flags[PRINT_EFF_ADDR] && addr_valid)
126            outs << " A=0x" << hex << addr;
127
128        if (flags[PRINT_INT_REGS] && regs_valid) {
129            for (int i = 0; i < 32;)
130                for (int j = i + 1; i <= j; i++)
131                    ccprintf(outs, "r%02d = %#018x%s", i, iregs->regs[i],
132                             ((i == j) ? "\n" : "    "));
133            outs << "\n";
134        }
135
136        if (flags[PRINT_FETCH_SEQ] && fetch_seq_valid)
137            outs << "  FetchSeq=" << dec << fetch_seq;
138
139        if (flags[PRINT_CP_SEQ] && cp_seq_valid)
140            outs << "  CPSeq=" << dec << cp_seq;
141
142        //
143        //  End of line...
144        //
145        outs << endl;
146    }
147}
148
149
150vector<bool> Trace::InstRecord::flags(NUM_BITS);
151string Trace::InstRecord::trace_system;
152
153////////////////////////////////////////////////////////////////////////
154//
155// Parameter space for per-cycle execution address tracing options.
156// Derive from ParamContext so we can override checkParams() function.
157//
158class ExecutionTraceParamContext : public ParamContext
159{
160  public:
161    ExecutionTraceParamContext(const string &_iniSection)
162        : ParamContext(_iniSection)
163        {
164        }
165
166    void checkParams();	// defined at bottom of file
167};
168
169ExecutionTraceParamContext exeTraceParams("exetrace");
170
171Param<bool> exe_trace_spec(&exeTraceParams, "speculative",
172                           "capture speculative instructions", true);
173
174Param<bool> exe_trace_print_cycle(&exeTraceParams, "print_cycle",
175                                  "print cycle number", true);
176Param<bool> exe_trace_print_opclass(&exeTraceParams, "print_opclass",
177                                  "print op class", true);
178Param<bool> exe_trace_print_thread(&exeTraceParams, "print_thread",
179                                  "print thread number", true);
180Param<bool> exe_trace_print_effaddr(&exeTraceParams, "print_effaddr",
181                                  "print effective address", true);
182Param<bool> exe_trace_print_data(&exeTraceParams, "print_data",
183                                  "print result data", true);
184Param<bool> exe_trace_print_iregs(&exeTraceParams, "print_iregs",
185                                  "print all integer regs", false);
186Param<bool> exe_trace_print_fetchseq(&exeTraceParams, "print_fetchseq",
187                                  "print fetch sequence number", false);
188Param<bool> exe_trace_print_cp_seq(&exeTraceParams, "print_cpseq",
189                                  "print correct-path sequence number", false);
190Param<bool> exe_trace_intel_format(&exeTraceParams, "intel_format",
191                                   "print trace in intel compatible format", false);
192Param<string> exe_trace_system(&exeTraceParams, "trace_system",
193                                   "print trace of which system (client or server)",
194                                   "client");
195
196
197//
198// Helper function for ExecutionTraceParamContext::checkParams() just
199// to get us into the InstRecord namespace
200//
201void
202Trace::InstRecord::setParams()
203{
204    flags[TRACE_MISSPEC]     = exe_trace_spec;
205
206    flags[PRINT_CYCLE]       = exe_trace_print_cycle;
207    flags[PRINT_OP_CLASS]    = exe_trace_print_opclass;
208    flags[PRINT_THREAD_NUM]  = exe_trace_print_thread;
209    flags[PRINT_RESULT_DATA] = exe_trace_print_effaddr;
210    flags[PRINT_EFF_ADDR]    = exe_trace_print_data;
211    flags[PRINT_INT_REGS]    = exe_trace_print_iregs;
212    flags[PRINT_FETCH_SEQ]   = exe_trace_print_fetchseq;
213    flags[PRINT_CP_SEQ]      = exe_trace_print_cp_seq;
214    flags[INTEL_FORMAT]      = exe_trace_intel_format;
215    trace_system	     = exe_trace_system;
216}
217
218void
219ExecutionTraceParamContext::checkParams()
220{
221    Trace::InstRecord::setParams();
222}
223
224