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

Side by Side Diff: experimental/linux_debug_server/debugger/oop_hooks.cc

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 /*
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7 #include "native_client/src/include/nacl_platform.h"
8 #include "native_client/src/trusted/service_runtime/nacl_oop_debugger_hooks.h"
9 #include "native_client/src/trusted/service_runtime/sel_ldr.h"
10 #include <unistd.h>
11 #include <sys/types.h>
12 #include <memory.h>
13 void SendMessageToDebuggerAndHalt(const char *fmt, ...);
14
15 void NaClOopDebuggerAppCreateHook(struct NaClApp *nap) {
16 if (NULL == nap)
17 return;
18 SendMessageToDebuggerAndHalt(
19 "-event AppCreate -nap %p -mem_start %p -user_entry_pt %p "
20 "-initial_entry_pt %p",
21 nap,
22 (void *) nap->mem_start,
23 (void *) nap->user_entry_pt,
24 (void *) nap->initial_entry_pt);
25 }
26
27 void NaClOopDebuggerThreadCreateHook(struct NaClAppThread *natp) {
28 SendMessageToDebuggerAndHalt("-event ThreadCreate -natp %p", natp);
29 }
30 void NaClOopDebuggerThreadExitHook(struct NaClAppThread *natp,
31 int exit_code) {
32 SendMessageToDebuggerAndHalt("-event ThreadExit -natp %p -exit_code %d",
33 natp,
34 exit_code);
35 }
36
37 void NaClOopDebuggerAppExitHook(int exit_code) {
38 SendMessageToDebuggerAndHalt("-event AppExit -exit_code %d", exit_code);
39 }
40
41 void OutputDebugString(const char* msg) {
42 asm ("movq %0, %%rax;"
43 "int $3;" // trap instruction
44 "nop;"
45 :
46 :"r"(msg)
47 :"%eax"
48 );
49 }
50
51 void SendMessageToDebuggerAndHalt(const char *fmt, ...) {
52 if (NULL == fmt) {
53 NaClLog(LOG_FATAL, "SendMessageToDebuggerAndHalt: fmt == NULL\n");
54 return;
55 }
56
57 #define kVarMsgSize 512
58 /*
59 * Prefix has GUID string specific to our OOP debugger, so that it
60 * can differentiate it from other uses of trap instruction.
61 */
62 char const prefix[] = "{7AA7C9CF-89EC-4ed3-8DAD-6DC84302AB11} -version 1 ";
63 char msg[sizeof(prefix) - 1 + kVarMsgSize];
64 char *post_pref_msg = msg + sizeof(prefix) - 1;
65 signed int res = 0;
66 va_list marker;
67 strcpy(msg, prefix);
68 va_start(marker, fmt);
69 res = vsnprintf(post_pref_msg, kVarMsgSize, fmt, marker);
70 if (-1 != res) {
71 /*
72 * Sends a string to the debugger by raising TRAP signal.
73 */
74 OutputDebugString(msg);
75 } else {
76 NaClLog(LOG_FATAL,
77 "SendMessageToDebuggerAndHalt: vsnprintf returned -1\n");
78 }
79 #undef kVarMsgSize
80 }
81
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698