gem5  v20.1.0.0
exetrace.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, 2019 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2001-2005 The Regents of The University of Michigan
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  */
40 
41 #include "cpu/exetrace.hh"
42 
43 #include <iomanip>
44 #include <sstream>
45 
46 #include "arch/utility.hh"
47 #include "base/loader/symtab.hh"
48 #include "config/the_isa.hh"
49 #include "cpu/base.hh"
50 #include "cpu/static_inst.hh"
51 #include "cpu/thread_context.hh"
52 #include "debug/ExecAll.hh"
53 #include "debug/FmtTicksOff.hh"
54 #include "enums/OpClass.hh"
55 
56 using namespace std;
57 using namespace TheISA;
58 
59 namespace Trace {
60 
61 void
63 {
64  std::stringstream outs;
65 
66  if (!Debug::ExecUser || !Debug::ExecKernel) {
67  bool in_user_mode = TheISA::inUserMode(thread);
68  if (in_user_mode && !Debug::ExecUser) return;
69  if (!in_user_mode && !Debug::ExecKernel) return;
70  }
71 
72  if (Debug::ExecAsid)
73  outs << "A" << dec << TheISA::getExecutingAsid(thread) << " ";
74 
75  if (Debug::ExecThread)
76  outs << "T" << thread->threadId() << " : ";
77 
78  Addr cur_pc = pc.instAddr();
80  if (Debug::ExecSymbol && (!FullSystem || !inUserMode(thread)) &&
81  (it = Loader::debugSymbolTable.findNearest(cur_pc)) !=
83  Addr delta = cur_pc - it->address;
84  if (delta)
85  ccprintf(outs, "@%s+%d", it->name, delta);
86  else
87  ccprintf(outs, "@%s", it->name);
88  } else {
89  ccprintf(outs, "%#x", cur_pc);
90  }
91 
92  if (inst->isMicroop()) {
93  ccprintf(outs, ".%2d", pc.microPC());
94  } else {
95  ccprintf(outs, " ");
96  }
97 
98  ccprintf(outs, " : ");
99 
100  //
101  // Print decoded instruction
102  //
103 
104  outs << setw(26) << left;
105  outs << inst->disassemble(cur_pc, &Loader::debugSymbolTable);
106 
107  if (ran) {
108  outs << " : ";
109 
110  if (Debug::ExecOpClass) {
111  outs << Enums::OpClassStrings[inst->opClass()] << " : ";
112  }
113 
114  if (Debug::ExecResult && !predicate) {
115  outs << "Predicated False";
116  }
117 
118  if (Debug::ExecResult && data_status != DataInvalid) {
119  switch (data_status) {
120  case DataVec:
121  {
122  ccprintf(outs, " D=0x[");
123  auto dv = data.as_vec->as<uint32_t>();
124  for (int i = TheISA::VecRegSizeBytes / 4 - 1; i >= 0;
125  i--) {
126  ccprintf(outs, "%08x", dv[i]);
127  if (i != 0) {
128  ccprintf(outs, "_");
129  }
130  }
131  ccprintf(outs, "]");
132  }
133  break;
134  case DataVecPred:
135  {
136  ccprintf(outs, " D=0b[");
137  auto pv = data.as_pred->as<uint8_t>();
138  for (int i = TheISA::VecPredRegSizeBits - 1; i >= 0; i--) {
139  ccprintf(outs, pv[i] ? "1" : "0");
140  if (i != 0 && i % 4 == 0) {
141  ccprintf(outs, "_");
142  }
143  }
144  ccprintf(outs, "]");
145  }
146  break;
147  default:
148  ccprintf(outs, " D=%#018x", data.as_int);
149  break;
150  }
151  }
152 
153  if (Debug::ExecEffAddr && getMemValid())
154  outs << " A=0x" << hex << addr;
155 
156  if (Debug::ExecFetchSeq && fetch_seq_valid)
157  outs << " FetchSeq=" << dec << fetch_seq;
158 
159  if (Debug::ExecCPSeq && cp_seq_valid)
160  outs << " CPSeq=" << dec << cp_seq;
161 
162  if (Debug::ExecFlags) {
163  outs << " flags=(";
164  inst->printFlags(outs, "|");
165  outs << ")";
166  }
167  }
168 
169  //
170  // End of line...
171  //
172  outs << endl;
173 
175  when, thread->getCpuPtr()->name(), "ExecEnable", "%s",
176  outs.str().c_str());
177 }
178 
179 void
181 {
182  /*
183  * The behavior this check tries to achieve is that if ExecMacro is on,
184  * the macroop will be printed. If it's on and microops are also on, it's
185  * printed before the microops start printing to give context. If the
186  * microops aren't printed, then it's printed only when the final microop
187  * finishes. Macroops then behave like regular instructions and don't
188  * complete/print when they fault.
189  */
190  if (Debug::ExecMacro && staticInst->isMicroop() &&
191  ((Debug::ExecMicro &&
192  macroStaticInst && staticInst->isFirstMicroop()) ||
193  (!Debug::ExecMicro &&
194  macroStaticInst && staticInst->isLastMicroop()))) {
195  traceInst(macroStaticInst, false);
196  }
197  if (Debug::ExecMicro || !staticInst->isMicroop()) {
198  traceInst(staticInst, true);
199  }
200 }
201 
202 } // namespace Trace
203 
205 //
206 // ExeTracer Simulation Object
207 //
209 ExeTracerParams::create()
210 {
211  return new Trace::ExeTracer(this);
212 }
Trace::ExeTracerRecord::dump
void dump()
Definition: exetrace.cc:180
ArmISA::VecRegSizeBytes
constexpr unsigned VecRegSizeBytes
Definition: types.hh:818
data
const char data[]
Definition: circlebuf.test.cc:42
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
Trace
Definition: nativetrace.cc:52
TheISA
Definition: decode_cache.hh:37
Trace::ExeTracer
Definition: exetrace.hh:59
exetrace.hh
Trace::getDebugLogger
Logger * getDebugLogger()
Get the current global debug logger.
Definition: trace.cc:67
FullSystem
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:132
StaticInst::opClass
OpClass opClass() const
Operation class. Used to select appropriate function unit in issue.
Definition: static_inst.hh:225
Trace::Logger::dprintf_flag
void dprintf_flag(Tick when, const std::string &name, const std::string &flag, const char *fmt, const Args &...args)
Log a single message with a flag prefix.
Definition: trace.hh:64
Loader::debugSymbolTable
SymbolTable debugSymbolTable
Global unified debugging symbol table (for target).
Definition: symtab.cc:47
StaticInst::printFlags
void printFlags(std::ostream &outs, const std::string &separator) const
Print a separator separated list of this instruction's set flag names on the given stream.
Definition: static_inst.cc:130
MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:240
static_inst.hh
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
ArmISA::VecPredRegSizeBits
constexpr unsigned VecPredRegSizeBits
Definition: types.hh:819
StaticInst::isMicroop
bool isMicroop() const
Definition: static_inst.hh:199
Loader::SymbolTable::const_iterator
SymbolVector::const_iterator const_iterator
Definition: symtab.hh:123
base.hh
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
StaticInst::disassemble
virtual const std::string & disassemble(Addr pc, const Loader::SymbolTable *symtab=nullptr) const
Return string representation of disassembled instruction.
Definition: static_inst.cc:121
ArmISA::getExecutingAsid
uint64_t getExecutingAsid(ThreadContext *tc)
Definition: utility.hh:414
addr
ip6_addr_t addr
Definition: inet.hh:423
ccprintf
void ccprintf(cp::Print &print)
Definition: cprintf.hh:127
RefCountingPtr< StaticInst >
symtab.hh
ArmISA::inUserMode
static bool inUserMode(CPSR cpsr)
Definition: utility.hh:108
Trace::ExeTracerRecord::traceInst
void traceInst(const StaticInstPtr &inst, bool ran)
Definition: exetrace.cc:62
thread_context.hh

Generated on Wed Sep 30 2020 14:02:08 for gem5 by doxygen 1.8.17