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

Generated on Fri Feb 28 2020 16:26:59 for gem5 by doxygen 1.8.13