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