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

Side by Side Diff: src/trusted/service_runtime/win/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
« no previous file with comments | « src/trusted/service_runtime/service_runtime.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
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/trusted/service_runtime/nacl_oop_debugger_hooks.h"
8 #include "native_client/src/trusted/service_runtime/sel_ldr.h"
9
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, ...)
18 ATTRIBUTE_FORMAT_PRINTF(1, 2);
19
20 void NaClOopDebuggerAppCreateHook(struct NaClApp *nap) {
21 if (NULL == nap)
22 return;
23 SendMessageToDebuggerAndHalt(
24 "-event AppCreate -nap %p -mem_start %p -user_entry_pt %p "
25 "-initial_entry_pt %p",
26 nap,
27 (void *) nap->mem_start,
28 (void *) nap->user_entry_pt,
29 (void *) nap->initial_entry_pt);
30 }
31
32 void NaClOopDebuggerThreadCreateHook(struct NaClAppThread *natp) {
33 SendMessageToDebuggerAndHalt("-event ThreadCreate -natp %p", natp);
34 }
35
36 void NaClOopDebuggerThreadExitHook(struct NaClAppThread *natp, int exit_code) {
37 SendMessageToDebuggerAndHalt("-event ThreadExit -natp %p -exit_code %d",
38 natp,
39 exit_code);
40 }
41
42 void NaClOopDebuggerAppExitHook(int exit_code) {
43 SendMessageToDebuggerAndHalt("-event AppExit -exit_code %d", exit_code);
44 }
45
46 void SendMessageToDebuggerAndHalt(const char *fmt, ...) {
47 if (NULL == fmt) {
48 NaClLog(LOG_FATAL, "SendMessageToDebuggerAndHalt: fmt == NULL\n");
49 return;
50 }
51
52 #define kVarMsgSize 512
53 /*
54 * Determines whether the calling process is being debugged by a debugger.
55 * IsDebuggerPresent() is a member of Windows Debugging API:
56 * http://msdn.microsoft.com/en-us/library/ms680345%28v=VS.85%29.aspx
57 */
58 if (IsDebuggerPresent()) {
59 /*
60 * Prefix has GUID string specific to our OOP debugger, so that it
61 * can differentiate it from other uses of 'OutputDebugString'.
62 */
63 char const prefix[] = "{7AA7C9CF-89EC-4ed3-8DAD-6DC84302AB11} -version 1 ";
64 char msg[sizeof(prefix) - 1 + kVarMsgSize];
65 char *post_pref_msg = msg + sizeof(prefix) - 1;
66 signed int res = 0;
67 va_list marker;
68
69 strcpy(msg, prefix);
70 va_start(marker, fmt);
71 res = _vsnprintf_s(post_pref_msg, kVarMsgSize, _TRUNCATE, fmt, marker);
72 if (-1 != res) {
73 /*
74 * Sends a string to the debugger by raising OUTPUT_DEBUG_STRING_EVENT.
75 * OutputDebugString() is a member of Windows Debugging API:
76 * http://msdn.microsoft.com/en-us/library/aa363362%28v=VS.85%29.aspx
77 *
78 * It's conceptually eqvivalent to:
79 * ::RaiseException(MY_OWN_EXCEPTION_CODE, 0, 1, &msg);
80 * The difference is, raising MY_OWN_EXCEPTION_CODE can cause program
81 * to crash (if there's no VEH handler and no debugger; or can cause
82 * debugger to stop program (if debugger does not know about
83 * MY_OWN_EXCEPTION_CODE).
84 *
85 * On the contrary, using OutputDebugString() is safe, cc from MSDN page:
86 * "If the application has no debugger and the system debugger is not
87 * active, OutputDebugString does nothing."
88 */
89 OutputDebugStringA(msg);
90 }
91 }
92 #undef kVarMsgSize
93 }
94 /* Example of captured sel_ldr -> debugger messages:
95
96 11.62454796 [6060] {7AA7C9CF-89EC-4ed3-8DAD-6DC84302AB11} -version 1 \
97 -event AppCreate -nap 00000000001CD3F0 -mem_start 0000000C00000000 \
98 -user_entry_pt 0000000000020080 -initial_entry_pt 0000000008000080
99 11.62480354 [6060] {7AA7C9CF-89EC-4ed3-8DAD-6DC84302AB11} -version 1 \
100 -event ThreadCreate -natp 0000000002304C50
101 ...
102 23.96814728 [6060] {7AA7C9CF-89EC-4ed3-8DAD-6DC84302AB11} -version 1 \
103 -event ThreadExit -natp 0000000002304C50 -exit_code 1
104 23.96838570 [6060] {7AA7C9CF-89EC-4ed3-8DAD-6DC84302AB11} -version 1 \
105 -event AppExit -exit_code 1
106 */
107
OLDNEW
« no previous file with comments | « src/trusted/service_runtime/service_runtime.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698