nativetrace.hh (6365:a3037fa327a0) nativetrace.hh (6409:6eaa041d043e)
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 * Authors: Gabe Black
29 */
30
31#ifndef __CPU_NATIVETRACE_HH__
32#define __CPU_NATIVETRACE_HH__
33
34#include <errno.h>
35#include <unistd.h>
36
37#include "base/socket.hh"
38#include "base/trace.hh"
39#include "base/types.hh"
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 * Authors: Gabe Black
29 */
30
31#ifndef __CPU_NATIVETRACE_HH__
32#define __CPU_NATIVETRACE_HH__
33
34#include <errno.h>
35#include <unistd.h>
36
37#include "base/socket.hh"
38#include "base/trace.hh"
39#include "base/types.hh"
40#include "cpu/exetrace.hh"
40#include "cpu/static_inst.hh"
41#include "cpu/static_inst.hh"
41#include "sim/insttracer.hh"
42
43class ThreadContext;
44
45namespace Trace {
46
47class NativeTrace;
48
42
43class ThreadContext;
44
45namespace Trace {
46
47class NativeTrace;
48
49class NativeTraceRecord : public InstRecord
49class NativeTraceRecord : public ExeTracerRecord
50{
51 protected:
52 NativeTrace * parent;
53
54 public:
55 NativeTraceRecord(NativeTrace * _parent,
56 Tick _when, ThreadContext *_thread,
57 const StaticInstPtr _staticInst, Addr _pc, bool spec,
58 const StaticInstPtr _macroStaticInst = NULL, MicroPC _upc = 0)
50{
51 protected:
52 NativeTrace * parent;
53
54 public:
55 NativeTraceRecord(NativeTrace * _parent,
56 Tick _when, ThreadContext *_thread,
57 const StaticInstPtr _staticInst, Addr _pc, bool spec,
58 const StaticInstPtr _macroStaticInst = NULL, MicroPC _upc = 0)
59 : InstRecord(_when, _thread, _staticInst, _pc, spec,
59 : ExeTracerRecord(_when, _thread, _staticInst, _pc, spec,
60 _macroStaticInst, _upc),
61 parent(_parent)
62 {
63 }
64
65 void dump();
66};
67
60 _macroStaticInst, _upc),
61 parent(_parent)
62 {
63 }
64
65 void dump();
66};
67
68class NativeTrace : public InstTracer
68class NativeTrace : public ExeTracer
69{
70 protected:
71 int fd;
72
73 ListenSocket native_listener;
74
75 public:
76
77 NativeTrace(const Params *p);
78 virtual ~NativeTrace() {}
79
80 NativeTraceRecord *
81 getInstRecord(Tick when, ThreadContext *tc,
82 const StaticInstPtr staticInst, Addr pc,
83 const StaticInstPtr macroStaticInst = NULL, MicroPC upc = 0)
84 {
85 if (tc->misspeculating())
86 return NULL;
87
88 return new NativeTraceRecord(this, when, tc,
89 staticInst, pc, tc->misspeculating(), macroStaticInst, upc);
90 }
91
92 template<class T>
93 bool
94 checkReg(const char * regName, T &val, T &realVal)
95 {
96 if(val != realVal)
97 {
98 DPRINTFN("Register %s should be %#x but is %#x.\n",
99 regName, realVal, val);
100 return false;
101 }
102 return true;
103 }
104
105 void
106 read(void *ptr, size_t size)
107 {
108 size_t soFar = 0;
109 while (soFar < size) {
110 size_t res = ::read(fd, (uint8_t *)ptr + soFar, size - soFar);
111 if (res < 0)
112 panic("Read call failed! %s\n", strerror(errno));
113 else
114 soFar += res;
115 }
116 }
117
118 virtual void
119 check(NativeTraceRecord *record) = 0;
120};
121
122} /* namespace Trace */
123
124#endif // __CPU_NATIVETRACE_HH__
69{
70 protected:
71 int fd;
72
73 ListenSocket native_listener;
74
75 public:
76
77 NativeTrace(const Params *p);
78 virtual ~NativeTrace() {}
79
80 NativeTraceRecord *
81 getInstRecord(Tick when, ThreadContext *tc,
82 const StaticInstPtr staticInst, Addr pc,
83 const StaticInstPtr macroStaticInst = NULL, MicroPC upc = 0)
84 {
85 if (tc->misspeculating())
86 return NULL;
87
88 return new NativeTraceRecord(this, when, tc,
89 staticInst, pc, tc->misspeculating(), macroStaticInst, upc);
90 }
91
92 template<class T>
93 bool
94 checkReg(const char * regName, T &val, T &realVal)
95 {
96 if(val != realVal)
97 {
98 DPRINTFN("Register %s should be %#x but is %#x.\n",
99 regName, realVal, val);
100 return false;
101 }
102 return true;
103 }
104
105 void
106 read(void *ptr, size_t size)
107 {
108 size_t soFar = 0;
109 while (soFar < size) {
110 size_t res = ::read(fd, (uint8_t *)ptr + soFar, size - soFar);
111 if (res < 0)
112 panic("Read call failed! %s\n", strerror(errno));
113 else
114 soFar += res;
115 }
116 }
117
118 virtual void
119 check(NativeTraceRecord *record) = 0;
120};
121
122} /* namespace Trace */
123
124#endif // __CPU_NATIVETRACE_HH__