Implemented VK_PRIOR and VK_NEXT processing (merged from Corel tree).
[wine] / dlls / kernel / debugger.c
1 /*
2  * Win32 debugger functions
3  *
4  * Copyright (C) 1999 Alexandre Julliard
5  */
6
7 #include <string.h>
8
9 #include "winerror.h"
10 #include "server.h"
11 #include "debugtools.h"
12
13 DEFAULT_DEBUG_CHANNEL(debugstr);
14
15
16 /******************************************************************************
17  *           WaitForDebugEvent   (KERNEL32.720)
18  *
19  * Waits for a debugging event to occur in a process being debugged
20  *
21  * PARAMS
22  *    event   [I] Address of structure for event information
23  *    timeout [I] Number of milliseconds to wait for event
24  *
25  * RETURNS STD
26  */
27 BOOL WINAPI WaitForDebugEvent( LPDEBUG_EVENT event, DWORD timeout )
28 {
29     BOOL ret;
30     SERVER_START_REQ
31     {
32         debug_event_t *data;
33         struct wait_debug_event_request *req = server_alloc_req( sizeof(*req), sizeof(*data) );
34
35         req->timeout = timeout;
36         if (!(ret = !server_call( REQ_WAIT_DEBUG_EVENT ))) goto done;
37
38         if (!server_data_size(req))  /* timeout */
39         {
40             SetLastError( ERROR_SEM_TIMEOUT );
41             ret = FALSE;
42             goto done;
43         }
44         data = server_data_ptr(req);
45         event->dwDebugEventCode = data->code;
46         event->dwProcessId      = (DWORD)req->pid;
47         event->dwThreadId       = (DWORD)req->tid;
48         switch(data->code)
49         {
50         case EXCEPTION_DEBUG_EVENT:
51             event->u.Exception.ExceptionRecord = data->info.exception.record;
52             event->u.Exception.dwFirstChance   = data->info.exception.first;
53             break;
54         case CREATE_THREAD_DEBUG_EVENT:
55             event->u.CreateThread.hThread           = data->info.create_thread.handle;
56             event->u.CreateThread.lpThreadLocalBase = data->info.create_thread.teb;
57             event->u.CreateThread.lpStartAddress    = data->info.create_thread.start;
58             break;
59         case CREATE_PROCESS_DEBUG_EVENT:
60             event->u.CreateProcessInfo.hFile                 = data->info.create_process.file;
61             event->u.CreateProcessInfo.hProcess              = data->info.create_process.process;
62             event->u.CreateProcessInfo.hThread               = data->info.create_process.thread;
63             event->u.CreateProcessInfo.lpBaseOfImage         = data->info.create_process.base;
64             event->u.CreateProcessInfo.dwDebugInfoFileOffset = data->info.create_process.dbg_offset;
65             event->u.CreateProcessInfo.nDebugInfoSize        = data->info.create_process.dbg_size;
66             event->u.CreateProcessInfo.lpThreadLocalBase     = data->info.create_process.teb;
67             event->u.CreateProcessInfo.lpStartAddress        = data->info.create_process.start;
68             event->u.CreateProcessInfo.lpImageName           = data->info.create_process.name;
69             event->u.CreateProcessInfo.fUnicode              = data->info.create_process.unicode;
70             if (data->info.create_process.file == -1) event->u.CreateProcessInfo.hFile = 0;
71             break;
72         case EXIT_THREAD_DEBUG_EVENT:
73             event->u.ExitThread.dwExitCode = data->info.exit.exit_code;
74             break;
75         case EXIT_PROCESS_DEBUG_EVENT:
76             event->u.ExitProcess.dwExitCode = data->info.exit.exit_code;
77             break;
78         case LOAD_DLL_DEBUG_EVENT:
79             event->u.LoadDll.hFile                 = data->info.load_dll.handle;
80             event->u.LoadDll.lpBaseOfDll           = data->info.load_dll.base;
81             event->u.LoadDll.dwDebugInfoFileOffset = data->info.load_dll.dbg_offset;
82             event->u.LoadDll.nDebugInfoSize        = data->info.load_dll.dbg_size;
83             event->u.LoadDll.lpImageName           = data->info.load_dll.name;
84             event->u.LoadDll.fUnicode              = data->info.load_dll.unicode;
85             if (data->info.load_dll.handle == -1) event->u.LoadDll.hFile = 0;
86             break;
87         case UNLOAD_DLL_DEBUG_EVENT:
88             event->u.UnloadDll.lpBaseOfDll = data->info.unload_dll.base;
89             break;
90         case OUTPUT_DEBUG_STRING_EVENT:
91             event->u.DebugString.lpDebugStringData  = data->info.output_string.string;
92             event->u.DebugString.fUnicode           = data->info.output_string.unicode;
93             event->u.DebugString.nDebugStringLength = data->info.output_string.length;
94             break;
95         case RIP_EVENT:
96             event->u.RipInfo.dwError = data->info.rip_info.error;
97             event->u.RipInfo.dwType  = data->info.rip_info.type;
98             break;
99         default:
100             server_protocol_error( "WaitForDebugEvent: bad code %d\n", data->code );
101         }
102     done:
103     }
104     SERVER_END_REQ;
105     return ret;
106 }
107
108
109 /**********************************************************************
110  *           ContinueDebugEvent   (KERNEL32.146)
111  */
112 BOOL WINAPI ContinueDebugEvent( DWORD pid, DWORD tid, DWORD status )
113 {
114     BOOL ret;
115     SERVER_START_REQ
116     {
117         struct continue_debug_event_request *req = server_alloc_req( sizeof(*req), 0 );
118         req->pid    = (void *)pid;
119         req->tid    = (void *)tid;
120         req->status = status;
121         ret = !server_call( REQ_CONTINUE_DEBUG_EVENT );
122     }
123     SERVER_END_REQ;
124     return ret;
125 }
126
127
128 /**********************************************************************
129  *           DebugActiveProcess   (KERNEL32.180)
130  */
131 BOOL WINAPI DebugActiveProcess( DWORD pid )
132 {
133     BOOL ret;
134     SERVER_START_REQ
135     {
136         struct debug_process_request *req = server_alloc_req( sizeof(*req), 0 );
137         req->pid = (void *)pid;
138         ret = !server_call( REQ_DEBUG_PROCESS );
139     }
140     SERVER_END_REQ;
141     return ret;
142 }
143
144
145 /***********************************************************************
146  *           OutputDebugStringA   (KERNEL32.548)
147  */
148 void WINAPI OutputDebugStringA( LPCSTR str )
149 {
150     SERVER_START_REQ
151     {
152         struct output_debug_string_request *req = server_alloc_req( sizeof(*req), 0 );
153         req->string  = (void *)str;
154         req->unicode = 0;
155         req->length  = strlen(str) + 1;
156         server_call_noerr( REQ_OUTPUT_DEBUG_STRING );
157     }
158     SERVER_END_REQ;
159     WARN("%s\n", str);
160 }
161
162
163 /***********************************************************************
164  *           OutputDebugStringW   (KERNEL32.549)
165  */
166 void WINAPI OutputDebugStringW( LPCWSTR str )
167 {
168     SERVER_START_REQ
169     {
170         struct output_debug_string_request *req = server_alloc_req( sizeof(*req), 0 );
171         req->string  = (void *)str;
172         req->unicode = 1;
173         req->length  = (lstrlenW(str) + 1) * sizeof(WCHAR);
174         server_call_noerr( REQ_OUTPUT_DEBUG_STRING );
175     }
176     SERVER_END_REQ;
177     WARN("%s\n", debugstr_w(str));
178 }
179
180
181 /***********************************************************************
182  *           OutputDebugString16   (KERNEL.115)
183  */
184 void WINAPI OutputDebugString16( LPCSTR str )
185 {
186     OutputDebugStringA( str );
187 }
188
189
190 /***********************************************************************
191  *           DebugBreak   (KERNEL32.181)
192  */
193 void WINAPI DebugBreak(void)
194 {
195     DbgBreakPoint();
196 }
197
198
199 /***********************************************************************
200  *           DebugBreak16   (KERNEL.203)
201  */
202 void WINAPI DebugBreak16( CONTEXT86 *context )
203 {
204 #ifdef __i386__
205     EXCEPTION_RECORD rec;
206
207     rec.ExceptionCode    = EXCEPTION_BREAKPOINT;
208     rec.ExceptionFlags   = 0;
209     rec.ExceptionRecord  = NULL;
210     rec.ExceptionAddress = GET_IP(context); 
211     rec.NumberParameters = 0;
212     NtRaiseException( &rec, context, TRUE );
213 #endif  /* defined(__i386__) */
214 }
215
216
217 /***********************************************************************
218  *           IsDebuggerPresent   (KERNEL32)
219  */
220 BOOL WINAPI IsDebuggerPresent(void)
221 {
222     BOOL ret = FALSE;
223     SERVER_START_REQ
224     {
225         struct get_process_info_request *req = server_alloc_req( sizeof(*req), 0 );
226         req->handle = GetCurrentProcess();
227         if (!server_call( REQ_GET_PROCESS_INFO )) ret = req->debugged;
228     }
229     SERVER_END_REQ;
230     return ret;
231 }