gem5  v20.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 class ThreadContext;
43 
44 namespace Trace {
45 
46 class NativeTrace;
47 
49 {
50  protected:
52 
53  public:
55  Tick _when, ThreadContext *_thread,
56  const StaticInstPtr _staticInst, TheISA::PCState _pc,
57  const StaticInstPtr _macroStaticInst = NULL)
58  : ExeTracerRecord(_when, _thread, _staticInst, _pc, _macroStaticInst),
59  parent(_parent)
60  {
61  }
62 
63  void dump();
64 };
65 
66 class NativeTrace : public ExeTracer
67 {
68  protected:
69  int fd;
70 
72 
73  public:
74 
75  NativeTrace(const Params *p);
76  virtual ~NativeTrace() {}
77 
80  const StaticInstPtr staticInst, TheISA::PCState pc,
81  const StaticInstPtr macroStaticInst = NULL)
82  {
83  return new NativeTraceRecord(this, when, tc,
84  staticInst, pc, macroStaticInst);
85  }
86 
87  template<class T>
88  bool
89  checkReg(const char * regName, T &val, T &realVal)
90  {
91  if (val != realVal)
92  {
93  DPRINTFN("Register %s should be %#x but is %#x.\n",
94  regName, realVal, val);
95  return false;
96  }
97  return true;
98  }
99 
100  void
101  read(void *ptr, size_t size)
102  {
103  size_t soFar = 0;
104  while (soFar < size) {
105  ssize_t res = ::read(fd, (uint8_t *)ptr + soFar, size - soFar);
106  if (res < 0)
107  panic("Read call failed! %s\n", strerror(errno));
108  else
109  soFar += res;
110  }
111  }
112 
113  virtual void
114  check(NativeTraceRecord *record) = 0;
115 };
116 
117 } // namespace Trace
118 
119 #endif // __CPU_NATIVETRACE_HH__
Trace::NativeTrace::~NativeTrace
virtual ~NativeTrace()
Definition: nativetrace.hh:76
socket.hh
ListenSocket
Definition: socket.hh:32
Trace::NativeTrace::checkReg
bool checkReg(const char *regName, T &val, T &realVal)
Definition: nativetrace.hh:89
Trace
Definition: nativetrace.cc:52
Trace::ExeTracer
Definition: exetrace.hh:59
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
exetrace.hh
Trace::NativeTrace::fd
int fd
Definition: nativetrace.hh:69
Trace::ExeTracerRecord
Definition: exetrace.hh:44
Trace::NativeTraceRecord::parent
NativeTrace * parent
Definition: nativetrace.hh:51
Trace::NativeTrace::check
virtual void check(NativeTraceRecord *record)=0
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:240
Trace::NativeTraceRecord
Definition: nativetrace.hh:48
static_inst.hh
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
Trace::NativeTraceRecord::dump
void dump()
Definition: nativetrace.cc:57
MipsISA::PCState
GenericISA::DelaySlotPCState< MachInst > PCState
Definition: types.hh:41
types.hh
Trace::NativeTrace::NativeTrace
NativeTrace(const Params *p)
Definition: nativetrace.cc:40
Trace::NativeTrace::native_listener
ListenSocket native_listener
Definition: nativetrace.hh:71
RefCountingPtr< StaticInst >
trace.hh
DPRINTFN
#define DPRINTFN(...)
Definition: trace.hh:238
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
Trace::ExeTracer::Params
ExeTracerParams Params
Definition: exetrace.hh:62
Trace::NativeTrace::read
void read(void *ptr, size_t size)
Definition: nativetrace.hh:101
Trace::NativeTraceRecord::NativeTraceRecord
NativeTraceRecord(NativeTrace *_parent, Tick _when, ThreadContext *_thread, const StaticInstPtr _staticInst, TheISA::PCState _pc, const StaticInstPtr _macroStaticInst=NULL)
Definition: nativetrace.hh:54
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
Trace::NativeTrace::getInstRecord
NativeTraceRecord * getInstRecord(Tick when, ThreadContext *tc, const StaticInstPtr staticInst, TheISA::PCState pc, const StaticInstPtr macroStaticInst=NULL)
Definition: nativetrace.hh:79
Trace::NativeTrace
Definition: nativetrace.hh:66

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