2 * Win32 debugger functions
4 * Copyright (C) 1999 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/winbase16.h"
26 #include "wine/server.h"
27 #include "kernel_private.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(debugstr);
33 /******************************************************************************
34 * WaitForDebugEvent (KERNEL32.@)
36 * Waits for a debugging event to occur in a process being debugged before
37 * filling out the debug event structure.
40 * event [O] Address of structure for event information.
41 * timeout [I] Number of milliseconds to wait for event.
45 * Returns true if a debug event occurred and false if the call timed out.
47 BOOL WINAPI WaitForDebugEvent(
58 SERVER_START_REQ( wait_debug_event )
60 req->get_handle = (timeout != 0);
61 wine_server_set_reply( req, &data, sizeof(data) );
62 if (!(ret = !wine_server_call_err( req ))) goto done;
64 if (!wine_server_reply_size(reply)) /* timeout */
66 wait = wine_server_ptr_handle( reply->wait );
70 event->dwDebugEventCode = data.code;
71 event->dwProcessId = (DWORD)reply->pid;
72 event->dwThreadId = (DWORD)reply->tid;
75 case EXCEPTION_DEBUG_EVENT:
76 event->u.Exception.dwFirstChance = data.exception.first;
77 event->u.Exception.ExceptionRecord.ExceptionCode = data.exception.exc_code;
78 event->u.Exception.ExceptionRecord.ExceptionFlags = data.exception.flags;
79 event->u.Exception.ExceptionRecord.ExceptionRecord = wine_server_get_ptr( data.exception.record );
80 event->u.Exception.ExceptionRecord.ExceptionAddress = wine_server_get_ptr( data.exception.address );
81 event->u.Exception.ExceptionRecord.NumberParameters = data.exception.nb_params;
82 for (i = 0; i < data.exception.nb_params; i++)
83 event->u.Exception.ExceptionRecord.ExceptionInformation[i] = data.exception.params[i];
85 case CREATE_THREAD_DEBUG_EVENT:
86 event->u.CreateThread.hThread = wine_server_ptr_handle( data.create_thread.handle );
87 event->u.CreateThread.lpThreadLocalBase = wine_server_get_ptr( data.create_thread.teb );
88 event->u.CreateThread.lpStartAddress = wine_server_get_ptr( data.create_thread.start );
90 case CREATE_PROCESS_DEBUG_EVENT:
91 event->u.CreateProcessInfo.hFile = wine_server_ptr_handle( data.create_process.file );
92 event->u.CreateProcessInfo.hProcess = wine_server_ptr_handle( data.create_process.process );
93 event->u.CreateProcessInfo.hThread = wine_server_ptr_handle( data.create_process.thread );
94 event->u.CreateProcessInfo.lpBaseOfImage = wine_server_get_ptr( data.create_process.base );
95 event->u.CreateProcessInfo.dwDebugInfoFileOffset = data.create_process.dbg_offset;
96 event->u.CreateProcessInfo.nDebugInfoSize = data.create_process.dbg_size;
97 event->u.CreateProcessInfo.lpThreadLocalBase = wine_server_get_ptr( data.create_process.teb );
98 event->u.CreateProcessInfo.lpStartAddress = wine_server_get_ptr( data.create_process.start );
99 event->u.CreateProcessInfo.lpImageName = wine_server_get_ptr( data.create_process.name );
100 event->u.CreateProcessInfo.fUnicode = data.create_process.unicode;
102 case EXIT_THREAD_DEBUG_EVENT:
103 event->u.ExitThread.dwExitCode = data.exit.exit_code;
105 case EXIT_PROCESS_DEBUG_EVENT:
106 event->u.ExitProcess.dwExitCode = data.exit.exit_code;
108 case LOAD_DLL_DEBUG_EVENT:
109 event->u.LoadDll.hFile = wine_server_ptr_handle( data.load_dll.handle );
110 event->u.LoadDll.lpBaseOfDll = wine_server_get_ptr( data.load_dll.base );
111 event->u.LoadDll.dwDebugInfoFileOffset = data.load_dll.dbg_offset;
112 event->u.LoadDll.nDebugInfoSize = data.load_dll.dbg_size;
113 event->u.LoadDll.lpImageName = wine_server_get_ptr( data.load_dll.name );
114 event->u.LoadDll.fUnicode = data.load_dll.unicode;
116 case UNLOAD_DLL_DEBUG_EVENT:
117 event->u.UnloadDll.lpBaseOfDll = wine_server_get_ptr( data.unload_dll.base );
119 case OUTPUT_DEBUG_STRING_EVENT:
120 event->u.DebugString.lpDebugStringData = wine_server_get_ptr( data.output_string.string );
121 event->u.DebugString.fUnicode = data.output_string.unicode;
122 event->u.DebugString.nDebugStringLength = data.output_string.length;
125 event->u.RipInfo.dwError = data.rip_info.error;
126 event->u.RipInfo.dwType = data.rip_info.type;
133 if (ret) return TRUE;
135 res = WaitForSingleObject( wait, timeout );
137 if (res != STATUS_WAIT_0) break;
139 SetLastError( ERROR_SEM_TIMEOUT );
144 /**********************************************************************
145 * ContinueDebugEvent (KERNEL32.@)
147 * Enables a thread that previously produced a debug event to continue.
150 * pid [I] The id of the process to continue.
151 * tid [I] The id of the thread to continue.
152 * status [I] The rule to apply to unhandled exeptions.
156 * True if the debugger is listed as the processes owner and the process
157 * and thread are valid.
159 BOOL WINAPI ContinueDebugEvent(
165 SERVER_START_REQ( continue_debug_event )
169 req->status = status;
170 ret = !wine_server_call_err( req );
177 /**********************************************************************
178 * DebugActiveProcess (KERNEL32.@)
180 * Attempts to attach the debugger to a process.
183 * pid [I] The process to be debugged.
187 * True if the debugger was attached to process.
189 BOOL WINAPI DebugActiveProcess( DWORD pid )
192 SERVER_START_REQ( debug_process )
196 ret = !wine_server_call_err( req );
202 /**********************************************************************
203 * DebugActiveProcessStop (KERNEL32.@)
205 * Attempts to detach the debugger from a process.
208 * pid [I] The process to be detached.
212 * True if the debugger was detached from the process.
214 BOOL WINAPI DebugActiveProcessStop( DWORD pid )
217 SERVER_START_REQ( debug_process )
221 ret = !wine_server_call_err( req );
228 /***********************************************************************
229 * OutputDebugStringA (KERNEL32.@)
231 * Output by an application of an ascii string to a debugger (if attached)
235 * str [I] The message to be logged and given to the debugger.
241 void WINAPI OutputDebugStringA( LPCSTR str )
243 SERVER_START_REQ( output_debug_string )
245 req->string = wine_server_client_ptr( str );
247 req->length = strlen(str) + 1;
248 wine_server_call( req );
255 /***********************************************************************
256 * OutputDebugStringW (KERNEL32.@)
258 * Output by an application of a unicode string to a debugger (if attached)
262 * str [I] The message to be logged and given to the debugger.
268 void WINAPI OutputDebugStringW( LPCWSTR str )
270 SERVER_START_REQ( output_debug_string )
272 req->string = wine_server_client_ptr( str );
274 req->length = (lstrlenW(str) + 1) * sizeof(WCHAR);
275 wine_server_call( req );
278 WARN("%s\n", debugstr_w(str));
282 /***********************************************************************
283 * OutputDebugString (KERNEL.115)
285 * Output by a 16 bit application of an ascii string to a debugger (if attached)
289 * str [I] The message to be logged and given to the debugger.
293 void WINAPI OutputDebugString16( LPCSTR str )
295 OutputDebugStringA( str );
299 /***********************************************************************
300 * DebugBreak (KERNEL32.@)
302 * Raises an exception so that a debugger (if attached)
303 * can take some action.
309 void WINAPI DebugBreak(void)
314 /***********************************************************************
315 * DebugBreakProcess (KERNEL32.@)
317 * Raises an exception so that a debugger (if attached)
318 * can take some action. Same as DebugBreak, but applies to any process.
321 * hProc [I] Process to break into.
325 * True if successful.
327 BOOL WINAPI DebugBreakProcess(HANDLE hProc)
331 TRACE("(%p)\n", hProc);
333 SERVER_START_REQ( debug_break )
335 req->handle = wine_server_obj_handle( hProc );
336 ret = !wine_server_call_err( req );
337 self = ret && reply->self;
340 if (self) DbgBreakPoint();
345 /***********************************************************************
346 * DebugBreak (KERNEL.203)
348 * Raises an exception in a 16 bit application so that a debugger (if attached)
349 * can take some action.
357 * Only 386 compatible processors implemented.
359 void WINAPI DebugBreak16(
360 CONTEXT86 *context) /* [in/out] A pointer to the 386 compatible processor state. */
363 EXCEPTION_RECORD rec;
365 rec.ExceptionCode = EXCEPTION_BREAKPOINT;
366 rec.ExceptionFlags = 0;
367 rec.ExceptionRecord = NULL;
368 rec.ExceptionAddress = (LPVOID)context->Eip;
369 rec.NumberParameters = 0;
370 NtRaiseException( &rec, context, TRUE );
371 #endif /* defined(__i386__) */
375 /***********************************************************************
376 * IsDebuggerPresent (KERNEL32.@)
378 * Allows a process to determine if there is a debugger attached.
384 * True if there is a debugger attached.
386 BOOL WINAPI IsDebuggerPresent(void)
388 return NtCurrentTeb()->Peb->BeingDebugged;
391 /***********************************************************************
392 * CheckRemoteDebuggerPresent (KERNEL32.@)
394 * Allows a process to determine if there is a remote debugger
401 * TRUE because it is a stub.
403 BOOL WINAPI CheckRemoteDebuggerPresent(HANDLE process, PBOOL DebuggerPresent)
405 FIXME("(%p)->(%p): Stub!\n", process, DebuggerPresent);
406 *DebuggerPresent = FALSE;
410 /***********************************************************************
411 * DebugSetProcessKillOnExit (KERNEL32.@)
413 * Let a debugger decide whether a debuggee will be killed upon debugger
417 * kill [I] If set to true then kill the process on exit.
420 * True if successful, false otherwise.
422 BOOL WINAPI DebugSetProcessKillOnExit(BOOL kill)
426 SERVER_START_REQ( set_debugger_kill_on_exit )
428 req->kill_on_exit = kill;
429 ret = !wine_server_call_err( req );