OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 The Native Client Authors. All rights reserved. | 2 * Copyright 2010 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can | 3 * Use of this source code is governed by a BSD-style license that can |
4 * be found in the LICENSE file. | 4 * be found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 #include <map> | 9 #include <map> |
10 | 10 |
11 /* | 11 /* |
12 * NaCl Functions for intereacting with debuggers | 12 * NaCl Functions for intereacting with debuggers |
13 */ | 13 */ |
14 | 14 |
15 #include "native_client/src/trusted/gdb_rsp/session.h" | 15 #include "native_client/src/trusted/gdb_rsp/session.h" |
16 #include "native_client/src/trusted/gdb_rsp/target.h" | 16 #include "native_client/src/trusted/gdb_rsp/target.h" |
17 #include "native_client/src/trusted/port/platform.h" | 17 #include "native_client/src/trusted/port/platform.h" |
18 #include "native_client/src/trusted/port/thread.h" | 18 #include "native_client/src/trusted/port/thread.h" |
19 | 19 |
20 #include "native_client/src/include/nacl_string.h" | 20 #include "native_client/src/include/nacl_string.h" |
21 #include "native_client/src/shared/platform/nacl_log.h" | 21 #include "native_client/src/shared/platform/nacl_log.h" |
22 #include "native_client/src/shared/platform/nacl_threads.h" | 22 #include "native_client/src/shared/platform/nacl_threads.h" |
23 #include "native_client/src/trusted/debug_stub/debug_stub.h" | 23 #include "native_client/src/trusted/debug_stub/debug_stub.h" |
24 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h" | 24 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h" |
25 #include "native_client/src/trusted/service_runtime/nacl_debug.h" | 25 #include "native_client/src/trusted/service_runtime/nacl_debug.h" |
26 #include "native_client/src/trusted/service_runtime/sel_ldr.h" | 26 #include "native_client/src/trusted/service_runtime/sel_ldr.h" |
27 | 27 |
28 /* To enable debuggging */ | 28 /* To enable debuggging */ |
29 // #define NACL_DEBUG_STUB 1 | 29 /* #define NACL_DEBUG_STUB 1 */ |
30 | 30 |
31 using port::IPlatform; | 31 using port::IPlatform; |
32 using port::IThread; | 32 using port::IThread; |
33 using port::ITransport; | 33 using port::ITransport; |
34 | 34 |
35 using gdb_rsp::Session; | 35 using gdb_rsp::Session; |
36 using gdb_rsp::Target; | 36 using gdb_rsp::Target; |
37 | 37 |
38 #ifdef WIN32 | 38 #ifdef WIN32 |
39 /* Disable warning for unwind disabled when exceptions used */ | 39 /* Disable warning for unwind disabled when exceptions used */ |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 #else | 169 #else |
170 UNREFERENCED_PARAMETER(ptr); | 170 UNREFERENCED_PARAMETER(ptr); |
171 #endif | 171 #endif |
172 } | 172 } |
173 | 173 |
174 void NaClExceptionCatcher(uint32_t id, int8_t sig, void *cookie) { | 174 void NaClExceptionCatcher(uint32_t id, int8_t sig, void *cookie) { |
175 #ifdef NACL_DEBUG_STUB | 175 #ifdef NACL_DEBUG_STUB |
176 Target* targ = static_cast<Target*>(cookie); | 176 Target* targ = static_cast<Target*>(cookie); |
177 | 177 |
178 /* Signal the target that we caught something */ | 178 /* Signal the target that we caught something */ |
179 IPlatform::LogWarning("<huh-b-4> Caught signal %d on thread %Xh.\n", sig, id); | 179 IPlatform::LogWarning("Caught signal %d on thread %Xh.\n", sig, id); |
180 targ->Signal(id, sig, true); | 180 targ->Signal(id, sig, true); |
181 #else | 181 #else |
182 UNREFERENCED_PARAMETER(id); | 182 UNREFERENCED_PARAMETER(id); |
183 UNREFERENCED_PARAMETER(sig); | 183 UNREFERENCED_PARAMETER(sig); |
184 UNREFERENCED_PARAMETER(cookie); | 184 UNREFERENCED_PARAMETER(cookie); |
185 #endif | 185 #endif |
186 } | 186 } |
187 | 187 |
188 | 188 |
189 int NaClDebugIsEnabled(void) throw() { | 189 int NaClDebugIsEnabled(void) throw() { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 } | 233 } |
234 | 234 |
235 void NaClDebugThreadPrepDebugging(struct NaClAppThread *natp) throw() { | 235 void NaClDebugThreadPrepDebugging(struct NaClAppThread *natp) throw() { |
236 UNREFERENCED_PARAMETER(natp); | 236 UNREFERENCED_PARAMETER(natp); |
237 | 237 |
238 #ifdef NACL_DEBUG_STUB | 238 #ifdef NACL_DEBUG_STUB |
239 if (NaClDebugIsEnabled()) { | 239 if (NaClDebugIsEnabled()) { |
240 NaClDebugState *state = NaClDebugGetState(); | 240 NaClDebugState *state = NaClDebugGetState(); |
241 uint32_t id = IPlatform::GetCurrentThread(); | 241 uint32_t id = IPlatform::GetCurrentThread(); |
242 IThread* thread = IThread::Acquire(id, true); | 242 IThread* thread = IThread::Acquire(id, true); |
243 state->target_->SetMemoryBase(natp->nap->mem_start); | |
244 state->target_->TrackThread(thread); | 243 state->target_->TrackThread(thread); |
245 | 244 |
246 /* | 245 /* |
247 * TODO(noelallen) We need to associate the natp with this thread | 246 * TODO(noelallen) We need to associate the natp with this thread |
248 * so we can get to the untrusted context preserved on a syscall. | 247 * so we can get to the untrusted context preserved on a syscall. |
249 */ | 248 */ |
250 } | 249 } |
251 #endif | 250 #endif |
252 } | 251 } |
253 | 252 |
(...skipping 19 matching lines...) Expand all Loading... |
273 | 272 |
274 | 273 |
275 int NaClDebugStart(void) throw() { | 274 int NaClDebugStart(void) throw() { |
276 #ifdef NACL_DEBUG_STUB | 275 #ifdef NACL_DEBUG_STUB |
277 if (NaClDebugIsEnabled()) { | 276 if (NaClDebugIsEnabled()) { |
278 NaClThread *thread = new NaClThread; | 277 NaClThread *thread = new NaClThread; |
279 | 278 |
280 if (NULL == thread) return false; | 279 if (NULL == thread) return false; |
281 NaClDebugState *state = NaClDebugGetState(); | 280 NaClDebugState *state = NaClDebugGetState(); |
282 | 281 |
283 /* Add a temp breakpoint. */ | 282 /* If break on start has been requested, add a temp breakpoint. */ |
284 struct NaClApp* app = state->app_; | 283 if (state->break_) { |
285 state->target_->AddTemporaryBreakpoint(app->entry_pt + app->mem_start); | 284 struct NaClApp* app = state->app_; |
| 285 state->target_->AddTemporaryBreakpoint(app->entry_pt + app->mem_start); |
| 286 } |
286 | 287 |
287 NaClLog(LOG_WARNING, "nacl_debug(%d) : Debugging started.\n", __LINE__); | 288 NaClLog(LOG_WARNING, "nacl_debug(%d) : Debugging started.\n", __LINE__); |
288 IThread::SetExceptionCatch(NaClExceptionCatcher, state->target_); | 289 IThread::SetExceptionCatch(NaClExceptionCatcher, state->target_); |
289 return NaClThreadCtor(thread, NaClStubThread, state->target_, | 290 return NaClThreadCtor(thread, NaClStubThread, state->target_, |
290 NACL_KERN_STACK_SIZE); | 291 NACL_KERN_STACK_SIZE); |
291 } | 292 } |
292 #endif | 293 #endif |
293 return 0; | 294 return 0; |
294 } | 295 } |
295 | 296 |
296 void NaClDebugStop(int ErrCode) throw() { | 297 void NaClDebugStop(int ErrCode) throw() { |
297 #ifdef NACL_DEBUG_STUB | 298 #ifdef NACL_DEBUG_STUB |
298 | 299 |
299 /* | 300 /* |
300 * We check if debugging is enabled since this check is the only | 301 * We check if debugging is enabled since this check is the only |
301 * mechanism for allocating the state object. We free the | 302 * mechanism for allocating the state object. We free the |
302 * resources but not the object itself. Instead we mark it as | 303 * resources but not the object itself. Instead we mark it as |
303 * STOPPED to prevent it from getting recreated. | 304 * STOPPED to prevent it from getting recreated. |
304 */ | 305 */ |
305 if (NaClDebugIsEnabled()) { | 306 if (NaClDebugIsEnabled()) { |
306 NaClDebugGetState()->status_ = NDS_STOPPED; | 307 NaClDebugGetState()->status_ = NDS_STOPPED; |
307 NaClDebugGetState()->errCode_ = ErrCode; | 308 NaClDebugGetState()->errCode_ = ErrCode; |
308 } | 309 } |
309 #else | 310 #else |
310 UNREFERENCED_PARAMETER(ErrCode); | 311 UNREFERENCED_PARAMETER(ErrCode); |
311 #endif | 312 #endif |
312 } | 313 } |
313 | 314 |
OLD | NEW |