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