2 * Win32 debugger functions
4 * Copyright (C) 1999 Alexandre Julliard
11 #include "debugtools.h"
13 DEFAULT_DEBUG_CHANNEL(debugstr);
16 /******************************************************************************
17 * WaitForDebugEvent (KERNEL32.720)
19 * Waits for a debugging event to occur in a process being debugged
22 * event [I] Address of structure for event information
23 * timeout [I] Number of milliseconds to wait for event
27 BOOL WINAPI WaitForDebugEvent( LPDEBUG_EVENT event, DWORD timeout )
33 struct wait_debug_event_request *req = server_alloc_req( sizeof(*req), sizeof(*data) );
35 req->timeout = timeout;
36 if (!(ret = !server_call( REQ_WAIT_DEBUG_EVENT ))) goto done;
38 if (!server_data_size(req)) /* timeout */
40 SetLastError( ERROR_SEM_TIMEOUT );
44 data = server_data_ptr(req);
45 event->dwDebugEventCode = data->code;
46 event->dwProcessId = (DWORD)req->pid;
47 event->dwThreadId = (DWORD)req->tid;
50 case EXCEPTION_DEBUG_EVENT:
51 event->u.Exception.ExceptionRecord = data->info.exception.record;
52 event->u.Exception.dwFirstChance = data->info.exception.first;
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;
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;
72 case EXIT_THREAD_DEBUG_EVENT:
73 event->u.ExitThread.dwExitCode = data->info.exit.exit_code;
75 case EXIT_PROCESS_DEBUG_EVENT:
76 event->u.ExitProcess.dwExitCode = data->info.exit.exit_code;
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;
87 case UNLOAD_DLL_DEBUG_EVENT:
88 event->u.UnloadDll.lpBaseOfDll = data->info.unload_dll.base;
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;
96 event->u.RipInfo.dwError = data->info.rip_info.error;
97 event->u.RipInfo.dwType = data->info.rip_info.type;
100 server_protocol_error( "WaitForDebugEvent: bad code %d\n", data->code );
109 /**********************************************************************
110 * ContinueDebugEvent (KERNEL32.146)
112 BOOL WINAPI ContinueDebugEvent( DWORD pid, DWORD tid, DWORD status )
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 );
128 /**********************************************************************
129 * DebugActiveProcess (KERNEL32.180)
131 BOOL WINAPI DebugActiveProcess( DWORD pid )
136 struct debug_process_request *req = server_alloc_req( sizeof(*req), 0 );
137 req->pid = (void *)pid;
138 ret = !server_call( REQ_DEBUG_PROCESS );
145 /***********************************************************************
146 * OutputDebugStringA (KERNEL32.548)
148 void WINAPI OutputDebugStringA( LPCSTR str )
152 struct output_debug_string_request *req = server_alloc_req( sizeof(*req), 0 );
153 req->string = (void *)str;
155 req->length = strlen(str) + 1;
156 server_call_noerr( REQ_OUTPUT_DEBUG_STRING );
163 /***********************************************************************
164 * OutputDebugStringW (KERNEL32.549)
166 void WINAPI OutputDebugStringW( LPCWSTR str )
170 struct output_debug_string_request *req = server_alloc_req( sizeof(*req), 0 );
171 req->string = (void *)str;
173 req->length = (lstrlenW(str) + 1) * sizeof(WCHAR);
174 server_call_noerr( REQ_OUTPUT_DEBUG_STRING );
177 WARN("%s\n", debugstr_w(str));
181 /***********************************************************************
182 * OutputDebugString16 (KERNEL.115)
184 void WINAPI OutputDebugString16( LPCSTR str )
186 OutputDebugStringA( str );
190 /***********************************************************************
191 * DebugBreak (KERNEL32.181)
193 void WINAPI DebugBreak(void)
199 /***********************************************************************
200 * DebugBreak16 (KERNEL.203)
202 void WINAPI DebugBreak16( CONTEXT86 *context )
205 EXCEPTION_RECORD rec;
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__) */
217 /***********************************************************************
218 * IsDebuggerPresent (KERNEL32)
220 BOOL WINAPI IsDebuggerPresent(void)
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;