gem5  v22.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 "base/loader/symtab.hh"
47 #include "cpu/base.hh"
48 #include "cpu/static_inst.hh"
49 #include "cpu/thread_context.hh"
50 #include "debug/ExecAll.hh"
51 #include "debug/FmtTicksOff.hh"
52 #include "enums/OpClass.hh"
53 
54 namespace gem5
55 {
56 
57 namespace trace {
58 
59 void
61 {
62  std::stringstream outs;
63 
64  const bool in_user_mode = thread->getIsaPtr()->inUserMode();
65  if (in_user_mode && !debug::ExecUser)
66  return;
67  if (!in_user_mode && !debug::ExecKernel)
68  return;
69 
70  if (debug::ExecAsid) {
71  outs << "A" << std::dec <<
72  thread->getIsaPtr()->getExecutingAsid() << " ";
73  }
74 
75  if (debug::ExecThread)
76  outs << "T" << thread->threadId() << " : ";
77 
78  Addr cur_pc = pc->instAddr();
80  ccprintf(outs, "%#x", cur_pc);
81  if (debug::ExecSymbol && (!FullSystem || !in_user_mode) &&
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  }
90 
91  if (inst->isMicroop()) {
92  ccprintf(outs, ".%2d", pc->microPC());
93  } else {
94  ccprintf(outs, " ");
95  }
96 
97  ccprintf(outs, " : ");
98 
99  //
100  // Print decoded instruction
101  //
102 
103  outs << std::setw(26) << std::left;
104  outs << inst->disassemble(cur_pc, &loader::debugSymbolTable);
105 
106  if (ran) {
107  outs << " : ";
108 
109  if (debug::ExecOpClass) {
110  outs << enums::OpClassStrings[inst->opClass()] << " : ";
111  }
112 
113  if (debug::ExecResult && !predicate) {
114  outs << "Predicated False";
115  }
116 
117  if (debug::ExecResult && dataStatus != DataInvalid) {
118  if (dataStatus == DataReg)
119  ccprintf(outs, " D=%s", data.asReg.asString());
120  else
121  ccprintf(outs, " D=%#018x", data.asInt);
122  }
123 
124  if (debug::ExecEffAddr && getMemValid())
125  outs << " A=0x" << std::hex << addr;
126 
127  if (debug::ExecFetchSeq && fetch_seq_valid)
128  outs << " FetchSeq=" << std::dec << fetch_seq;
129 
130  if (debug::ExecCPSeq && cp_seq_valid)
131  outs << " CPSeq=" << std::dec << cp_seq;
132 
133  if (debug::ExecFlags) {
134  outs << " flags=(";
135  inst->printFlags(outs, "|");
136  outs << ")";
137  }
138  }
139 
140  //
141  // End of line...
142  //
143  outs << std::endl;
144 
146  when, thread->getCpuPtr()->name(), "ExecEnable", "%s",
147  outs.str().c_str());
148 }
149 
150 void
152 {
153  /*
154  * The behavior this check tries to achieve is that if ExecMacro is on,
155  * the macroop will be printed. If it's on and microops are also on, it's
156  * printed before the microops start printing to give context. If the
157  * microops aren't printed, then it's printed only when the final microop
158  * finishes. Macroops then behave like regular instructions and don't
159  * complete/print when they fault.
160  */
161  if (debug::ExecMacro && staticInst->isMicroop() &&
162  ((debug::ExecMicro &&
164  (!debug::ExecMicro &&
166  traceInst(macroStaticInst, false);
167  }
168  if (debug::ExecMicro || !staticInst->isMicroop()) {
169  traceInst(staticInst, true);
170  }
171 }
172 
173 } // namespace trace
174 } // namespace gem5
virtual bool inUserMode() const =0
virtual uint64_t getExecutingAsid() const
Definition: isa.hh:82
std::string asString() const
Definition: inst_res.hh:170
virtual std::string name() const
Definition: named.hh:47
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:71
virtual const std::string & disassemble(Addr pc, const loader::SymbolTable *symtab=nullptr) const
Return string representation of disassembled instruction.
Definition: static_inst.cc:60
OpClass opClass() const
Operation class. Used to select appropriate function unit in issue.
Definition: static_inst.hh:210
bool isFirstMicroop() const
Definition: static_inst.hh:189
bool isLastMicroop() const
Definition: static_inst.hh:188
bool isMicroop() const
Definition: static_inst.hh:186
virtual BaseISA * getIsaPtr() const =0
virtual BaseCPU * getCpuPtr()=0
virtual int threadId() const =0
SymbolVector::const_iterator const_iterator
Definition: symtab.hh:170
void traceInst(const StaticInstPtr &inst, bool ran)
Definition: exetrace.cc:60
Addr addr
The address that was accessed.
Definition: insttracer.hh:85
StaticInstPtr staticInst
Definition: insttracer.hh:70
StaticInstPtr macroStaticInst
Definition: insttracer.hh:72
bool getMemValid() const
Definition: insttracer.hh:274
ThreadContext * thread
Definition: insttracer.hh:67
std::unique_ptr< PCStateBase > pc
Definition: insttracer.hh:71
bool predicate
is the predicate for execution this inst true or false (not execed)?
Definition: insttracer.hh:150
union gem5::trace::InstRecord::Data data
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:75
bool cp_seq_valid
Are the commit sequence number fields valid?
Definition: insttracer.hh:146
enum gem5::trace::InstRecord::DataStatus dataStatus
bool fetch_seq_valid
Are the fetch sequence number fields valid?
Definition: insttracer.hh:142
SymbolTable debugSymbolTable
Global unified debugging symbol table (for target).
Definition: symtab.cc:44
Logger * getDebugLogger()
Get the current global debug logger.
Definition: trace.cc:69
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:220
void ccprintf(cp::Print &print)
Definition: cprintf.hh:130

Generated on Wed Dec 21 2022 10:22:30 for gem5 by doxygen 1.9.1