gem5  v20.0.0.2
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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/isa_traits.hh"
47 #include "arch/utility.hh"
48 #include "base/loader/symtab.hh"
49 #include "config/the_isa.hh"
50 #include "cpu/base.hh"
51 #include "cpu/static_inst.hh"
52 #include "cpu/thread_context.hh"
53 #include "debug/ExecAll.hh"
54 #include "debug/FmtTicksOff.hh"
55 #include "enums/OpClass.hh"
56 
57 using namespace std;
58 using namespace TheISA;
59 
60 namespace Trace {
61 
62 void
64 {
65  std::stringstream outs;
66 
67  if (!Debug::ExecUser || !Debug::ExecKernel) {
68  bool in_user_mode = TheISA::inUserMode(thread);
69  if (in_user_mode && !Debug::ExecUser) return;
70  if (!in_user_mode && !Debug::ExecKernel) return;
71  }
72 
73  if (Debug::ExecAsid)
74  outs << "A" << dec << TheISA::getExecutingAsid(thread) << " ";
75 
76  if (Debug::ExecThread)
77  outs << "T" << thread->threadId() << " : ";
78 
79  Addr cur_pc = pc.instAddr();
81  if (Debug::ExecSymbol && (!FullSystem || !inUserMode(thread)) &&
82  (it = Loader::debugSymbolTable.findNearest(cur_pc)) !=
84  Addr delta = cur_pc - it->address;
85  if (delta)
86  ccprintf(outs, "@%s+%d", it->name, delta);
87  else
88  ccprintf(outs, "@%s", it->name);
89  } else {
90  ccprintf(outs, "%#x", cur_pc);
91  }
92 
93  if (inst->isMicroop()) {
94  ccprintf(outs, ".%2d", pc.microPC());
95  } else {
96  ccprintf(outs, " ");
97  }
98 
99  ccprintf(outs, " : ");
100 
101  //
102  // Print decoded instruction
103  //
104 
105  outs << setw(26) << left;
106  outs << inst->disassemble(cur_pc, &Loader::debugSymbolTable);
107 
108  if (ran) {
109  outs << " : ";
110 
111  if (Debug::ExecOpClass) {
112  outs << Enums::OpClassStrings[inst->opClass()] << " : ";
113  }
114 
115  if (Debug::ExecResult && !predicate) {
116  outs << "Predicated False";
117  }
118 
119  if (Debug::ExecResult && data_status != DataInvalid) {
120  switch (data_status) {
121  case DataVec:
122  {
123  ccprintf(outs, " D=0x[");
124  auto dv = data.as_vec->as<uint32_t>();
125  for (int i = TheISA::VecRegSizeBytes / 4 - 1; i >= 0;
126  i--) {
127  ccprintf(outs, "%08x", dv[i]);
128  if (i != 0) {
129  ccprintf(outs, "_");
130  }
131  }
132  ccprintf(outs, "]");
133  }
134  break;
135  case DataVecPred:
136  {
137  ccprintf(outs, " D=0b[");
138  auto pv = data.as_pred->as<uint8_t>();
139  for (int i = TheISA::VecPredRegSizeBits - 1; i >= 0; i--) {
140  ccprintf(outs, pv[i] ? "1" : "0");
141  if (i != 0 && i % 4 == 0) {
142  ccprintf(outs, "_");
143  }
144  }
145  ccprintf(outs, "]");
146  }
147  break;
148  default:
149  ccprintf(outs, " D=%#018x", data.as_int);
150  break;
151  }
152  }
153 
154  if (Debug::ExecEffAddr && getMemValid())
155  outs << " A=0x" << hex << addr;
156 
157  if (Debug::ExecFetchSeq && fetch_seq_valid)
158  outs << " FetchSeq=" << dec << fetch_seq;
159 
160  if (Debug::ExecCPSeq && cp_seq_valid)
161  outs << " CPSeq=" << dec << cp_seq;
162 
163  if (Debug::ExecFlags) {
164  outs << " flags=(";
165  inst->printFlags(outs, "|");
166  outs << ")";
167  }
168  }
169 
170  //
171  // End of line...
172  //
173  outs << endl;
174 
176  when, thread->getCpuPtr()->name(), "ExecEnable", "%s",
177  outs.str().c_str());
178 }
179 
180 void
182 {
183  /*
184  * The behavior this check tries to achieve is that if ExecMacro is on,
185  * the macroop will be printed. If it's on and microops are also on, it's
186  * printed before the microops start printing to give context. If the
187  * microops aren't printed, then it's printed only when the final microop
188  * finishes. Macroops then behave like regular instructions and don't
189  * complete/print when they fault.
190  */
191  if (Debug::ExecMacro && staticInst->isMicroop() &&
192  ((Debug::ExecMicro &&
193  macroStaticInst && staticInst->isFirstMicroop()) ||
194  (!Debug::ExecMicro &&
195  macroStaticInst && staticInst->isLastMicroop()))) {
196  traceInst(macroStaticInst, false);
197  }
198  if (Debug::ExecMicro || !staticInst->isMicroop()) {
199  traceInst(staticInst, true);
200  }
201 }
202 
203 } // namespace Trace
204 
206 //
207 // ExeTracer Simulation Object
208 //
210 ExeTracerParams::create()
211 {
212  return new Trace::ExeTracer(this);
213 }
void ccprintf(cp::Print &print)
Definition: cprintf.hh:127
virtual const std::string & disassemble(Addr pc, const Loader::SymbolTable *symtab=nullptr) const
Return string representation of disassembled instruction.
Definition: static_inst.cc:121
constexpr unsigned VecRegSizeBytes
Definition: types.hh:770
Bitfield< 7 > i
ip6_addr_t addr
Definition: inet.hh:330
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:132
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
SymbolTable debugSymbolTable
Global unified debugging symbol table (for target).
Definition: symtab.cc:47
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
Bitfield< 4 > pc
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
OpClass opClass() const
Operation class. Used to select appropriate function unit in issue.
Definition: static_inst.hh:213
static bool inUserMode(CPSR cpsr)
Definition: utility.hh:108
void printFlags(std::ostream &outs, const std::string &separator) const
Print a separator separated list of this instruction&#39;s set flag names on the given stream...
Definition: static_inst.cc:130
Logger * getDebugLogger()
Get the current global debug logger.
Definition: trace.cc:67
SymbolVector::const_iterator const_iterator
Definition: symtab.hh:123
uint64_t getExecutingAsid(ThreadContext *tc)
Definition: utility.hh:402
constexpr unsigned VecPredRegSizeBits
Definition: types.hh:771
void traceInst(const StaticInstPtr &inst, bool ran)
Definition: exetrace.cc:63
const char data[]
bool isMicroop() const
Definition: static_inst.hh:199

Generated on Mon Jun 8 2020 15:45:08 for gem5 by doxygen 1.8.13