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