Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: experimental/visual_studio_plugin/src/NaClVsx.DebugHelpers/.GdbProxy.cpp-h5gwkn

Issue 10928195: First round of dead file removal (Closed) Base URL: https://github.com/samclegg/nativeclient-sdk.git@master
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #include "GdbProxy.h"
2 #include "third_party/nacl/native_client/src/trusted/debug_stub/debug_host.h"
3 #include <string>
4
5 using System::String;
6 using System::Byte;
7 using System::Int32;
8 using System::UInt32;
9 using System::UInt64;
10 using System::IntPtr;
11 using System::Collections::Generic::Dictionary;
12 using System::Diagnostics::Debug;
13 using System::Runtime::InteropServices::Marshal;
14 using System::Runtime::InteropServices::GCHandle;
15 using System::Runtime::InteropServices::GCHandleType;
16 using System::Runtime::InteropServices::OutAttribute;
17
18 using nacl_debug_conn::DebugHost;
19 using std::string;
20
21 namespace NaClVsx { namespace DebugHelpers {
22
23 ref class ClosureMap {
24 public:
25 static int AddClosure(GdbProxy::AsyncResponse^ closure, bool remove) {
26 int id = nextId_++;
27 closureHandleMap_[id] = closure;
28 closureRemovalMap_[id] = remove;
29 return id;
30 }
31
32 static GdbProxy::AsyncResponse^ GetClosure(int id) {
33 GdbProxy::AsyncResponse^ result = closureHandleMap_[id];
34 if (closureRemovalMap_[id]) {
35 closureHandleMap_[id] = nullptr;
36 }
37 return result;
38 }
39 private:
40 static Dictionary<int,GdbProxy::AsyncResponse^> closureHandleMap_;
41 static Dictionary<int,bool> closureRemovalMap_;
42 static int nextId_ = 0;
43 };
44
45 struct GdbProxyImpl {
46 DebugHost *pHost;
47
48 static void __stdcall DHAsync(DebugHost::DHResult res, void *obj);
49 static void __stdcall DHAsyncStr(DebugHost::DHResult res,
50 void *obj,
51 const char *str);
52 static void __stdcall DHAsyncMem(DebugHost::DHResult res,
53 void *obj,
54 void* data,
55 uint32_t len);
56 };
57
58 void __stdcall GdbProxyImpl::DHAsync(DebugHost::DHResult res, void *obj)
59 {
60 GdbProxy::AsyncResponse^ closure =
61 ClosureMap::GetClosure(reinterpret_cast<int>(obj));
62 if (closure != nullptr) {
63 closure((GdbProxy::ResultCode) res, nullptr, nullptr);
64 }
65 }
66
67 void __stdcall GdbProxyImpl::DHAsyncStr(DebugHost::DHResult res, void *obj, cons t char *str)
68 {
69 GdbProxy::AsyncResponse^ closure =
70 ClosureMap::GetClosure(reinterpret_cast<int>(obj));
71 closure((GdbProxy::ResultCode) res, gcnew String(str), nullptr);
72 }
73
74 void __stdcall GdbProxyImpl::DHAsyncMem(DebugHost::DHResult res, void *obj, void * data, uint32_t len)
75 {
76 GdbProxy::AsyncResponse^ closure =
77 ClosureMap::GetClosure(reinterpret_cast<int>(obj));
78 array<Byte>^ managedData = gcnew array<Byte>(len);
79 Marshal::Copy(IntPtr(data), managedData, 0, len);
80 closure((GdbProxy::ResultCode) res, nullptr, managedData);
81
82 }
83 GdbProxy::GdbProxy(void) : pimpl_(new GdbProxyImpl)
84 {
85 }
86
87 GdbProxy::~GdbProxy() {
88 delete pimpl_;
89 }
90
91 bool GdbProxy::CanConnect(String^ connectionString)
92 {
93 Debug::WriteLine(String::Format("TransportImpl::CanConnect({0})",
94 connectionString));
95
96 return true;
97 }
98
99 void GdbProxy::Open(String^ connectionString)
100 {
101 Debug::WriteLine(String::Format("Transport::Open({0})",
102 connectionString));
103
104 IntPtr hString = Marshal::StringToHGlobalAnsi(connectionString);
105 pimpl_->pHost = DebugHost::SocketConnect(
106 (char*)hString.ToPointer());
107 Marshal::FreeHGlobal(hString);
108
109 if(!pimpl_->pHost) {
110 throw gcnew System::IO::IOException(
111 String::Format("Failed to connect to {0}",connectionString));
112 }
113
114 connectionString_ = connectionString;
115 }
116
117 void GdbProxy::Close()
118 {
119 Debug::WriteLine(String::Format("Transport::Close"));
120
121
122 delete pimpl_->pHost;
123 pimpl_->pHost = NULL;
124 }
125
126 bool GdbProxy::IsRunning()
127 {
128 return pimpl_->pHost->IsRunning();
129 }
130
131 void GdbProxy::SetOutputAsync( AsyncResponse^ reply )
132 {
133 pimpl_->pHost->SetOutputAsync(
134 &GdbProxyImpl::DHAsyncStr,
135 reinterpret_cast<void*>(ClosureMap::AddClosure(reply,false)));
136 }
137
138 void GdbProxy::SetStopAsync( AsyncResponse^ reply )
139 {
140 pimpl_->pHost->SetStopAsync(
141 &GdbProxyImpl::DHAsync,
142 reinterpret_cast<void*>(ClosureMap::AddClosure(reply,false)));
143 }
144
145
146
147 GdbProxy::ResultCode GdbProxy::GetPath(AsyncResponse^ reply)
148 {
149 return static_cast<ResultCode>(pimpl_->pHost->GetPathAsync(
150 &GdbProxyImpl::DHAsyncStr,
151 reinterpret_cast<void*>(ClosureMap::AddClosure(reply, true))));
152 }
153
154 GdbProxy::ResultCode GdbProxy::GetArch(AsyncResponse^ reply)
155 {
156 return static_cast<ResultCode>(pimpl_->pHost->GetArchAsync(
157 &GdbProxyImpl::DHAsyncStr,
158 reinterpret_cast<void*>(ClosureMap::AddClosure(reply, true))));
159
160 }
161
162 GdbProxy::ResultCode GdbProxy::GetThreads(AsyncResponse^ reply)
163 {
164 return static_cast<ResultCode>(pimpl_->pHost->GetThreadsAsync(
165 &GdbProxyImpl::DHAsyncStr,
166 reinterpret_cast<void*>(ClosureMap::AddClosure(reply, true))));
167
168 }
169
170 GdbProxy::ResultCode GdbProxy::GetLastSig([Out]int% sig)
171 {
172 int lastSig = 0;
173 ResultCode result = ResultCode::DHR_FAILED;
174 result = static_cast<ResultCode>(pimpl_->pHost->GetLastSig(&lastSig));
175 sig = lastSig;
176 return result;
177 }
178
179 GdbProxy::ResultCode GdbProxy::GetMemory(System::UInt64 offs, System::Object^ da ta)
180 {
181 Int32 size = Marshal::SizeOf(data->GetType());
182 GCHandle^ hData = GCHandle::Alloc(data,GCHandleType::Pinned);
183 IntPtr pData = hData->AddrOfPinnedObject();
184 ResultCode result = static_cast<ResultCode>(
185 pimpl_->pHost->GetMemory(offs, pData.ToPointer(), size));
186 hData->Free();
187
188 return result;
189 }
190
191 GdbProxy::ResultCode GdbProxy::GetMemory( System::UInt64 offs, System::Array^ da ta, System::UInt32 count )
192 {
193 Int32 size = data->Length * Marshal::SizeOf(data->GetType()->GetElementType()) ;
194 Debug::Assert((UInt32)size >= count);
195 GCHandle^ hData = GCHandle::Alloc(data,GCHandleType::Pinned);
196 IntPtr pData = hData->AddrOfPinnedObject();
197 ResultCode result = static_cast<ResultCode>(
198 pimpl_->pHost->GetMemory(offs, pData.ToPointer(), count));
199 hData->Free();
200
201 return result;
202 }
203
204 GdbProxy::ResultCode GdbProxy::SetMemory( System::UInt64 offs, System::Array^ da ta, System::UInt32 count )
205 {
206 Int32 size = data->Length * Marshal::SizeOf(data->GetType()->GetElementType()) ;
207 Debug::Assert((UInt32)size >= count);
208 GCHandle^ hData = GCHandle::Alloc(data,GCHandleType::Pinned);
209 IntPtr pData = hData->AddrOfPinnedObject();
210 ResultCode result = static_cast<ResultCode>(
211 pimpl_->pHost->SetMemory(offs, pData.ToPointer(), count));
212 hData->Free();
213
214 return result;
215
216 }
217
218 GdbProxy::ResultCode GdbProxy::GetRegisters(RegsX86_64^% registers)
219 {
220 Int32 size = Marshal::SizeOf(registers->GetType());
221 GCHandle^ hRegisters = GCHandle::Alloc(registers,GCHandleType::Pinned);
222 IntPtr pRegisters = hRegisters->AddrOfPinnedObject();
223 ResultCode result = static_cast<ResultCode>(pimpl_->pHost->GetRegisters(pRegis ters.ToPointer(),size));
224 hRegisters->Free();
225
226 return result;
227 }
228
229 GdbProxy::ResultCode GdbProxy::SetRegisters(void *, System::UInt32 )
230 {
231 return ResultCode::DHR_FAILED;
232 }
233
234 GdbProxy::ResultCode GdbProxy::RequestBreak()
235 {
236 return static_cast<ResultCode>(pimpl_->pHost->RequestBreak());
237 }
238
239 GdbProxy::ResultCode GdbProxy::RequestContinueBackground()
240 {
241 return static_cast<ResultCode>(pimpl_->pHost->RequestContinueBackground());
242 }
243
244 GdbProxy::ResultCode GdbProxy::RequestContinue()
245 {
246 return static_cast<ResultCode>(pimpl_->pHost->RequestContinue());
247 }
248
249 GdbProxy::ResultCode GdbProxy::RequestStep()
250 {
251 return static_cast<ResultCode>(pimpl_->pHost->RequestStep());
252 }
253
254 bool GdbProxy::HasBreakpoint( System::UInt64 offs )
255 {
256 return pimpl_->pHost->HasBreakpoint(offs);
257 }
258
259 GdbProxy::ResultCode GdbProxy::AddBreakpoint( System::UInt64 offs )
260 {
261 return (GdbProxy::ResultCode)pimpl_->pHost->AddBreakpoint(offs);
262 }
263
264 GdbProxy::ResultCode GdbProxy::RemoveBreakpoint( System::UInt64 offs )
265 {
266 return (GdbProxy::ResultCode)pimpl_->pHost->RemoveBreakpoint(offs);
267 }
268
269 <<<<<<< c:\hg\nvs\src/NaClVsx.DebugHelpers/GdbProxy.cpp
270 GdbProxy::ResultCode GdbProxy::EnableBreakpoint( System::UInt64 offs )
271 {
272 return (GdbProxy::ResultCode)pimpl_->pHost->EnableBreakpoint(offs);
273 }
274
275 GdbProxy::ResultCode GdbProxy::DisableBreakpoint( System::UInt64 offs )
276 {
277 return (GdbProxy::ResultCode)pimpl_->pHost->DisableBreakpoint(offs);
278 }
279
280 GdbProxy::ResultCode GdbProxy::SuspendBreakpoint( System::UInt64 offs )
281 {
282 return (GdbProxy::ResultCode)pimpl_->pHost->SuspendBreakpoint(offs);
283 }
284
285 GdbProxy::ResultCode GdbProxy::ResumeBreakpoint( System::UInt64 offs )
286 {
287 return (GdbProxy::ResultCode)pimpl_->pHost->ResumeBreakpoint(offs);
288 }
289
290 bool GdbProxy::QueryBreakpoint( System::UInt64 offs )
291 {
292 DebugHost::BreakpointRecord dummy;
293 return (pimpl_->pHost->QueryBreakpoint(offs, &dummy) == DebugHost::DHR_OK);
294 }
295
296
297
298
299 =======
300 >>>>>>> c:\users\ilewis\appdata\local\temp\GdbProxy.cpp~other.-xjb9k
301 }} // namespace NaClVsx.DebugHelpers
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698