gem5  v22.1.0.0
nativetrace.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006-2009 The Regents of The University of Michigan
3  * All rights reserved.
4  *
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.
15  *
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.
27  */
28 
29 #ifndef __CPU_NATIVETRACE_HH__
30 #define __CPU_NATIVETRACE_HH__
31 
32 #include <unistd.h>
33 
34 #include <cerrno>
35 
36 #include "base/socket.hh"
37 #include "base/trace.hh"
38 #include "base/types.hh"
39 #include "cpu/exetrace.hh"
40 #include "cpu/static_inst.hh"
41 
42 namespace gem5
43 {
44 
45 class ThreadContext;
46 
47 namespace trace {
48 
49 class NativeTrace;
50 
52 {
53  protected:
55 
56  public:
58  Tick _when, ThreadContext *_thread,
59  const StaticInstPtr _staticInst, const PCStateBase &_pc,
60  const StaticInstPtr _macroStaticInst=nullptr)
61  : ExeTracerRecord(_when, _thread, _staticInst, _pc, _macroStaticInst),
62  parent(_parent)
63  {
64  }
65 
66  void dump();
67 };
68 
69 class NativeTrace : public ExeTracer
70 {
71  protected:
72  int fd;
73 
75 
76  public:
77 
78  NativeTrace(const Params &p);
79  virtual ~NativeTrace() {}
80 
83  const StaticInstPtr staticInst, const PCStateBase &pc,
84  const StaticInstPtr macroStaticInst=nullptr) override
85  {
86  return new NativeTraceRecord(this, when, tc,
87  staticInst, pc, macroStaticInst);
88  }
89 
90  template<class T>
91  bool
92  checkReg(const char * regName, T &val, T &realVal)
93  {
94  if (val != realVal)
95  {
96  DPRINTFN("Register %s should be %#x but is %#x.\n",
97  regName, realVal, val);
98  return false;
99  }
100  return true;
101  }
102 
103  void
104  read(void *ptr, size_t size)
105  {
106  size_t soFar = 0;
107  while (soFar < size) {
108  ssize_t res = ::read(fd, (uint8_t *)ptr + soFar, size - soFar);
109  if (res < 0)
110  panic("Read call failed! %s\n", strerror(errno));
111  else
112  soFar += res;
113  }
114  }
115 
116  virtual void
117  check(NativeTraceRecord *record) = 0;
118 };
119 
120 } // namespace trace
121 } // namespace gem5
122 
123 #endif // __CPU_NATIVETRACE_HH__
#define DPRINTFN(...)
Definition: trace.hh:214
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
ThreadContext is the external interface to all thread state for anything outside of the CPU.
ExeTracerParams Params
Definition: exetrace.hh:65
NativeTraceRecord(NativeTrace *_parent, Tick _when, ThreadContext *_thread, const StaticInstPtr _staticInst, const PCStateBase &_pc, const StaticInstPtr _macroStaticInst=nullptr)
Definition: nativetrace.hh:57
bool checkReg(const char *regName, T &val, T &realVal)
Definition: nativetrace.hh:92
NativeTrace(const Params &p)
Definition: nativetrace.cc:41
NativeTraceRecord * getInstRecord(Tick when, ThreadContext *tc, const StaticInstPtr staticInst, const PCStateBase &pc, const StaticInstPtr macroStaticInst=nullptr) override
Definition: nativetrace.hh:82
void read(void *ptr, size_t size)
Definition: nativetrace.hh:104
ListenSocket native_listener
Definition: nativetrace.hh:74
virtual void check(NativeTraceRecord *record)=0
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
Bitfield< 4 > pc
Bitfield< 54 > p
Definition: pagetable.hh:70
Bitfield< 63 > val
Definition: misc.hh:776
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t Tick
Tick count type.
Definition: types.hh:58

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