nativetrace.hh (4776:8c8407243a2c) nativetrace.hh (4830:aad1410a2b79)
1/*
2 * Copyright (c) 2001-2005 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;

--- 22 unchanged lines hidden (view full) ---

31
32#ifndef __NATIVETRACE_HH__
33#define __NATIVETRACE_HH__
34
35#include "base/trace.hh"
36#include "cpu/static_inst.hh"
37#include "sim/host.hh"
38#include "sim/insttracer.hh"
1/*
2 * Copyright (c) 2001-2005 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;

--- 22 unchanged lines hidden (view full) ---

31
32#ifndef __NATIVETRACE_HH__
33#define __NATIVETRACE_HH__
34
35#include "base/trace.hh"
36#include "cpu/static_inst.hh"
37#include "sim/host.hh"
38#include "sim/insttracer.hh"
39#include "arch/x86/intregs.hh"
39
40class ThreadContext;
41
42
43namespace Trace {
44
45class NativeTrace;
46
47class NativeTraceRecord : public InstRecord
48{
49 protected:
50 NativeTrace * parent;
51
40
41class ThreadContext;
42
43
44namespace Trace {
45
46class NativeTrace;
47
48class NativeTraceRecord : public InstRecord
49{
50 protected:
51 NativeTrace * parent;
52
52 bool
53 checkIntReg(const char * regName, int index, int size);
54
55 bool
56 checkPC(const char * regName, int size);
57
58 public:
59 NativeTraceRecord(NativeTrace * _parent,
60 Tick _when, ThreadContext *_thread,
61 const StaticInstPtr &_staticInst, Addr _pc, bool spec)
62 : InstRecord(_when, _thread, _staticInst, _pc, spec), parent(_parent)
63 {
64 }
65
66 void dump();
67};
68
69class NativeTrace : public InstTracer
70{
71 protected:
72 int fd;
73
74 ListenSocket native_listener;
75
53 public:
54 NativeTraceRecord(NativeTrace * _parent,
55 Tick _when, ThreadContext *_thread,
56 const StaticInstPtr &_staticInst, Addr _pc, bool spec)
57 : InstRecord(_when, _thread, _staticInst, _pc, spec), parent(_parent)
58 {
59 }
60
61 void dump();
62};
63
64class NativeTrace : public InstTracer
65{
66 protected:
67 int fd;
68
69 ListenSocket native_listener;
70
71 bool checkRcx;
72 bool checkR11;
73 uint64_t oldRcxVal, oldR11Val;
74 uint64_t oldRealRcxVal, oldRealR11Val;
75
76 struct ThreadState {
77 uint64_t rax;
78 uint64_t rcx;
79 uint64_t rdx;
80 uint64_t rbx;
81 uint64_t rsp;
82 uint64_t rbp;
83 uint64_t rsi;
84 uint64_t rdi;
85 uint64_t r8;
86 uint64_t r9;
87 uint64_t r10;
88 uint64_t r11;
89 uint64_t r12;
90 uint64_t r13;
91 uint64_t r14;
92 uint64_t r15;
93 uint64_t rip;
94
95 void update(int fd)
96 {
97 int bytesLeft = sizeof(ThreadState);
98 int bytesRead = 0;
99 do
100 {
101 int res = read(fd, ((char *)this) + bytesRead, bytesLeft);
102 if(res < 0)
103 panic("Read call failed! %s\n", strerror(errno));
104 bytesLeft -= res;
105 bytesRead += res;
106 } while(bytesLeft);
107 rax = TheISA::gtoh(rax);
108 rcx = TheISA::gtoh(rcx);
109 rdx = TheISA::gtoh(rdx);
110 rbx = TheISA::gtoh(rbx);
111 rsp = TheISA::gtoh(rsp);
112 rbp = TheISA::gtoh(rbp);
113 rsi = TheISA::gtoh(rsi);
114 rdi = TheISA::gtoh(rdi);
115 r8 = TheISA::gtoh(r8);
116 r9 = TheISA::gtoh(r9);
117 r10 = TheISA::gtoh(r10);
118 r11 = TheISA::gtoh(r11);
119 r12 = TheISA::gtoh(r12);
120 r13 = TheISA::gtoh(r13);
121 r14 = TheISA::gtoh(r14);
122 r15 = TheISA::gtoh(r15);
123 rip = TheISA::gtoh(rip);
124 }
125
126 void update(ThreadContext * tc)
127 {
128 rax = tc->readIntReg(X86ISA::INTREG_RAX);
129 rcx = tc->readIntReg(X86ISA::INTREG_RCX);
130 rdx = tc->readIntReg(X86ISA::INTREG_RDX);
131 rbx = tc->readIntReg(X86ISA::INTREG_RBX);
132 rsp = tc->readIntReg(X86ISA::INTREG_RSP);
133 rbp = tc->readIntReg(X86ISA::INTREG_RBP);
134 rsi = tc->readIntReg(X86ISA::INTREG_RSI);
135 rdi = tc->readIntReg(X86ISA::INTREG_RDI);
136 r8 = tc->readIntReg(X86ISA::INTREG_R8);
137 r9 = tc->readIntReg(X86ISA::INTREG_R9);
138 r10 = tc->readIntReg(X86ISA::INTREG_R10);
139 r11 = tc->readIntReg(X86ISA::INTREG_R11);
140 r12 = tc->readIntReg(X86ISA::INTREG_R12);
141 r13 = tc->readIntReg(X86ISA::INTREG_R13);
142 r14 = tc->readIntReg(X86ISA::INTREG_R14);
143 r15 = tc->readIntReg(X86ISA::INTREG_R15);
144 rip = tc->readNextPC();
145 }
146
147 };
148
149 ThreadState nState;
150 ThreadState mState;
151
152
76 public:
77
153 public:
154
155 template<class T>
156 bool
157 checkReg(const char * regName, T &val, T &realVal)
158 {
159 if(val != realVal)
160 {
161 DPRINTFN("Register %s should be %#x but is %#x.\n",
162 regName, realVal, val);
163 return false;
164 }
165 return true;
166 }
167
168 bool
169 checkRcxReg(const char * regName, uint64_t &, uint64_t &);
170
171 bool
172 checkR11Reg(const char * regName, uint64_t &, uint64_t &);
173
78 NativeTrace(const std::string & name);
79
80 NativeTraceRecord *
81 getInstRecord(Tick when, ThreadContext *tc,
82 const StaticInstPtr staticInst, Addr pc)
83 {
84 if (tc->misspeculating())
85 return NULL;
86
87 return new NativeTraceRecord(this, when, tc,
88 staticInst, pc, tc->misspeculating());
89 }
90
174 NativeTrace(const std::string & name);
175
176 NativeTraceRecord *
177 getInstRecord(Tick when, ThreadContext *tc,
178 const StaticInstPtr staticInst, Addr pc)
179 {
180 if (tc->misspeculating())
181 return NULL;
182
183 return new NativeTraceRecord(this, when, tc,
184 staticInst, pc, tc->misspeculating());
185 }
186
187 void
188 check(ThreadContext *, bool syscall);
189
91 friend class NativeTraceRecord;
92};
93
94/* namespace Trace */ }
95
96#endif // __EXETRACE_HH__
190 friend class NativeTraceRecord;
191};
192
193/* namespace Trace */ }
194
195#endif // __EXETRACE_HH__