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

Side by Side Diff: src/trusted/service_runtime/nacl_oop_debugger_hooks.c

Issue 6995160: Hooks for out-of-process (OOP) debugger. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: '' Created 9 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 /* Copyright (c) 2011 The Native Client Authors. All rights reserved.
bsy 2011/06/13 20:36:49 /* * as before */
garianov1 2011/06/13 20:52:32 Done.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
6 #include "native_client/src/trusted/service_runtime/nacl_oop_debugger_hooks.h"
7 #include "native_client/src/trusted/service_runtime/sel_ldr.h"
8
9 #ifdef NACL_WINDOWS
bsy 2011/06/13 20:36:49 this file has enough OS-conditionalizing that it i
garianov1 2011/06/13 20:52:32 Right now I have only Windows code, so I'd like to
10 /*
11 * Note: this function does not do anything if program
12 * is not running under debugger.
13 * If program (sel_ldr) is running under debugger, calling this function
14 * gives debugger a chance to modify state of the debuggee before
15 * resuming debuggee execution.
16 */
17 void SendMessageToDebuggerAndHalt(const char *fmt, ...);
bsy 2011/06/13 20:36:49 suggest adding ATTRIBUTE_FORMAT_PRINTF from native
garianov1 2011/06/13 20:52:32 Done.
18
19 void NaClOopDebuggerAppCreateHook(struct NaClApp *nap) {
20 if (NULL == nap)
21 return;
22 SendMessageToDebuggerAndHalt(
23 "-event AppCreate -nap %p -mem_start %p -user_entry_pt %p "
24 "-initial_entry_pt %p",
25 nap,
26 (void *)nap->mem_start,
bsy 2011/06/13 20:36:49 prevailing style is "(target_type) expression" (sp
garianov1 2011/06/13 20:52:32 Done.
27 (void *)nap->user_entry_pt,
28 (void *)nap->initial_entry_pt);
29 }
30
31 void NaClOopDebuggerThreadCreateHook(struct NaClAppThread *natp) {
32 SendMessageToDebuggerAndHalt("-event ThreadCreate -natp %p", natp);
33 }
34
35 void NaClOopDebuggerThreadExitHook(struct NaClAppThread *natp, int exit_code) {
36 SendMessageToDebuggerAndHalt("-event ThreadExit -natp %p -exit_code %d",
37 natp,
38 exit_code);
39 }
40
41 void NaClOopDebuggerAppExitHook(int exit_code) {
42 SendMessageToDebuggerAndHalt("-event AppExit -exit_code %d", exit_code);
43 }
44
45 #else
46 /* placeholders for OOP debugger hooks on other platforms */
47 void NaClOopDebuggerAppCreateHook(struct NaClApp *nap) {
48 UNREFERENCED_PARAMETER(nap);
49 }
50
51 void NaClOopDebuggerThreadCreateHook(struct NaClAppThread *natp,
52 int exit_code) {
53 UNREFERENCED_PARAMETER(natp);
54 UNREFERENCED_PARAMETER(exit_code);
55 }
56 void NaClOopDebuggerThreadExitHook(struct NaClAppThread *natp,
57 int exit_code) {
58 UNREFERENCED_PARAMETER(natp);
59 UNREFERENCED_PARAMETER(exit_code);
60 }
61
62 void NaClOopDebuggerAppExitHook(int exit_code) {
63 }
64 #endif
65
66 #ifdef NACL_WINDOWS
67 void SendMessageToDebuggerAndHalt(const char *fmt, ...) {
68 #define kVarMsgSize 2048
69 /*
70 * Determines whether the calling process is being debugged by a debugger.
71 * IsDebuggerPresent() is a member of Windows Debugging API:
72 * http://msdn.microsoft.com/en-us/library/ms680345%28v=VS.85%29.aspx
73 */
74 if (IsDebuggerPresent()) {
75 /*
76 * Prefix has GUID string specific to our OOP debugger, so that it
77 * can differentiate it from other uses of 'OutputDebugString'.
78 */
79 char prefix[] = "{7AA7C9CF-89EC-4ed3-8DAD-6DC84302AB11} -version 1 ";
80 char msg[sizeof(prefix) + kVarMsgSize];
81 char *post_pref_msg = msg + sizeof(prefix) - 1;
82 signed int res = 0;
83 va_list marker;
84
85 strcpy(msg, prefix);
86 va_start(marker, fmt);
87 res = _vsnprintf_s(post_pref_msg, kVarMsgSize, _TRUNCATE, fmt, marker);
88 if (-1 != res) {
89 /*
90 * Sends a string to the debugger by raising OUTPUT_DEBUG_STRING_EVENT.
91 * OutputDebugString() is a member of Windows Debugging API:
92 * http://msdn.microsoft.com/en-us/library/aa363362%28v=VS.85%29.aspx
93 *
94 * It's conceptually eqvivalent to:
95 * ::RaiseException(MY_OWN_EXCEPTION_CODE, 0, 1, &msg);
96 * The difference is, raising MY_OWN_EXCEPTION_CODE can cause program
97 * to crash (if there's no VEH handler and no debugger; or can cause
98 * debugger to stop program (if debugger does not know about
99 * MY_OWN_EXCEPTION_CODE).
100 *
101 * On the contrary, using OutputDebugString() is safe, cc from MSDN page:
102 * "If the application has no debugger and the system debugger is not
103 * active, OutputDebugString does nothing."
104 */
105 OutputDebugStringA(msg);
106 }
107 }
108 #undef kVarMsgSize
109 }
110 /* Example of captured sel_ldr -> debugger messages:
111
112 11.62454796 [6060] {7AA7C9CF-89EC-4ed3-8DAD-6DC84302AB11} -version 1 \
113 -event AppCreate -nap 00000000001CD3F0 -mem_start 0000000C00000000 \
114 -user_entry_pt 0000000000020080 -initial_entry_pt 0000000008000080
115 11.62480354 [6060] {7AA7C9CF-89EC-4ed3-8DAD-6DC84302AB11} -version 1 \
116 -event ThreadCreate -natp 0000000002304C50
117 ...
118 23.96814728 [6060] {7AA7C9CF-89EC-4ed3-8DAD-6DC84302AB11} -version 1 \
119 -event ThreadExit -natp 0000000002304C50 -exit_code 1
120 23.96838570 [6060] {7AA7C9CF-89EC-4ed3-8DAD-6DC84302AB11} -version 1 \
121 -event AppExit -exit_code 1
122 */
123 #endif
124
OLDNEW
« no previous file with comments | « src/trusted/service_runtime/nacl_oop_debugger_hooks.h ('k') | src/trusted/service_runtime/sel_ldr_standard.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698