2 * Copyright (c) 2001-2005 The Regents of The University of Michigan
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.
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.
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"
41 ////////////////////////////////////////////////////////////////////////
43 // Methods for the InstRecord object
48 Trace::InstRecord::dump(ostream
&outs
)
50 if (flags
[INTEL_FORMAT
]) {
52 bool is_trace_system
= (cpu
->system
->name() == trace_system
);
54 bool is_trace_system
= true;
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
;
62 } else if (staticInst
->isStore()) {
63 outs
<< "<WR 0x" << hex
<< addr
;
69 if (flags
[PRINT_CYCLE
])
70 ccprintf(outs
, "%7d: ", cycle
);
72 outs
<< cpu
->name() << " ";
74 if (flags
[TRACE_MISSPEC
])
75 outs
<< (misspeculating
? "-" : "+") << " ";
77 if (flags
[PRINT_THREAD_NUM
])
78 outs
<< "T" << thread
<< " : ";
84 && debugSymbolTable
->findNearestSymbol(PC
, sym_str
, sym_addr
)) {
86 sym_str
+= csprintf("+%d", PC
- sym_addr
);
87 outs
<< "@" << sym_str
<< " : ";
90 outs
<< "0x" << hex
<< PC
<< " : ";
94 // Print decoded instruction
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)
105 outs
<< setw(26) << left
<< staticInst
->disassemble(PC
, debugSymbolTable
);
110 if (flags
[PRINT_OP_CLASS
]) {
111 outs
<< opClassStrings
[staticInst
->opClass()] << " : ";
114 if (flags
[PRINT_RESULT_DATA
] && data_status
!= DataInvalid
) {
117 if (data_status
== DataDouble
)
118 ccprintf(outs
, "%f", data
.as_double
);
120 ccprintf(outs
, "%#018x", data
.as_int
);
122 ccprintf(outs
, "%#018x", data
.as_int
);
126 if (flags
[PRINT_EFF_ADDR
] && addr_valid
)
127 outs
<< " A=0x" << hex
<< addr
;
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" : " "));
137 if (flags
[PRINT_FETCH_SEQ
] && fetch_seq_valid
)
138 outs
<< " FetchSeq=" << dec
<< fetch_seq
;
140 if (flags
[PRINT_CP_SEQ
] && cp_seq_valid
)
141 outs
<< " CPSeq=" << dec
<< cp_seq
;
151 vector
<bool> Trace::InstRecord::flags(NUM_BITS
);
152 string
Trace::InstRecord::trace_system
;
154 ////////////////////////////////////////////////////////////////////////
156 // Parameter space for per-cycle execution address tracing options.
157 // Derive from ParamContext so we can override checkParams() function.
159 class ExecutionTraceParamContext
: public ParamContext
162 ExecutionTraceParamContext(const string
&_iniSection
)
163 : ParamContext(_iniSection
)
167 void checkParams(); // defined at bottom of file
170 ExecutionTraceParamContext
exeTraceParams("exetrace");
172 Param
<bool> exe_trace_spec(&exeTraceParams
, "speculative",
173 "capture speculative instructions", true);
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)",
199 // Helper function for ExecutionTraceParamContext::checkParams() just
200 // to get us into the InstRecord namespace
203 Trace::InstRecord::setParams()
205 flags
[TRACE_MISSPEC
] = exe_trace_spec
;
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
;
220 ExecutionTraceParamContext::checkParams()
222 Trace::InstRecord::setParams();