Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Win32 debugger functions |
| 3 | * |
| 4 | * Copyright (C) 1999 Alexandre Julliard |
| 5 | */ |
| 6 | |
Alexandre Julliard | 5b971f0 | 2000-11-26 22:39:50 +0000 | [diff] [blame] | 7 | #include <stdio.h> |
Patrik Stridvall | 2c68408 | 1999-07-31 17:36:48 +0000 | [diff] [blame] | 8 | #include <string.h> |
| 9 | |
Alexandre Julliard | ff81d78 | 2000-03-08 12:01:30 +0000 | [diff] [blame] | 10 | #include "winerror.h" |
Alexandre Julliard | 5b971f0 | 2000-11-26 22:39:50 +0000 | [diff] [blame] | 11 | #include "wine/winbase16.h" |
Alexandre Julliard | 37e9503 | 2001-07-19 00:39:09 +0000 | [diff] [blame] | 12 | #include "wine/server.h" |
Alexandre Julliard | 5b971f0 | 2000-11-26 22:39:50 +0000 | [diff] [blame] | 13 | #include "stackframe.h" |
Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 14 | #include "debugtools.h" |
| 15 | |
Alexandre Julliard | 3e2517c | 2000-01-20 18:59:03 +0000 | [diff] [blame] | 16 | DEFAULT_DEBUG_CHANNEL(debugstr); |
Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 17 | |
| 18 | |
Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 19 | /****************************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 20 | * WaitForDebugEvent (KERNEL32.@) |
Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 21 | * |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 22 | * Waits for a debugging event to occur in a process being debugged before |
| 23 | * filling out the debug event structure. |
Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 24 | * |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 25 | * RETURNS |
Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 26 | * |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 27 | * Returns true if a debug event occurred and false if the call timed out. |
Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 28 | */ |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 29 | BOOL WINAPI WaitForDebugEvent( |
Patrik Stridvall | bca4a8d | 2001-02-12 03:49:57 +0000 | [diff] [blame] | 30 | LPDEBUG_EVENT event, /* [out] Address of structure for event information. */ |
| 31 | DWORD timeout) /* [in] Number of milliseconds to wait for event. */ |
Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 32 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 33 | BOOL ret; |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 34 | DWORD res; |
| 35 | |
| 36 | for (;;) |
Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 37 | { |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 38 | HANDLE wait = 0; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 39 | debug_event_t data; |
| 40 | SERVER_START_REQ( wait_debug_event ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 41 | { |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 42 | req->get_handle = (timeout != 0); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 43 | wine_server_set_reply( req, &data, sizeof(data) ); |
| 44 | if (!(ret = !wine_server_call_err( req ))) goto done; |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 45 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 46 | if (!wine_server_reply_size(reply)) /* timeout */ |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 47 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 48 | wait = reply->wait; |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 49 | ret = FALSE; |
| 50 | goto done; |
| 51 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 52 | event->dwDebugEventCode = data.code; |
| 53 | event->dwProcessId = (DWORD)reply->pid; |
| 54 | event->dwThreadId = (DWORD)reply->tid; |
| 55 | switch(data.code) |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 56 | { |
| 57 | case EXCEPTION_DEBUG_EVENT: |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 58 | event->u.Exception.ExceptionRecord = data.info.exception.record; |
| 59 | event->u.Exception.dwFirstChance = data.info.exception.first; |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 60 | break; |
| 61 | case CREATE_THREAD_DEBUG_EVENT: |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 62 | event->u.CreateThread.hThread = data.info.create_thread.handle; |
| 63 | event->u.CreateThread.lpThreadLocalBase = data.info.create_thread.teb; |
| 64 | event->u.CreateThread.lpStartAddress = data.info.create_thread.start; |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 65 | break; |
| 66 | case CREATE_PROCESS_DEBUG_EVENT: |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 67 | event->u.CreateProcessInfo.hFile = data.info.create_process.file; |
| 68 | event->u.CreateProcessInfo.hProcess = data.info.create_process.process; |
| 69 | event->u.CreateProcessInfo.hThread = data.info.create_process.thread; |
| 70 | event->u.CreateProcessInfo.lpBaseOfImage = data.info.create_process.base; |
| 71 | event->u.CreateProcessInfo.dwDebugInfoFileOffset = data.info.create_process.dbg_offset; |
| 72 | event->u.CreateProcessInfo.nDebugInfoSize = data.info.create_process.dbg_size; |
| 73 | event->u.CreateProcessInfo.lpThreadLocalBase = data.info.create_process.teb; |
| 74 | event->u.CreateProcessInfo.lpStartAddress = data.info.create_process.start; |
| 75 | event->u.CreateProcessInfo.lpImageName = data.info.create_process.name; |
| 76 | event->u.CreateProcessInfo.fUnicode = data.info.create_process.unicode; |
| 77 | if (data.info.create_process.file == -1) event->u.CreateProcessInfo.hFile = 0; |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 78 | break; |
| 79 | case EXIT_THREAD_DEBUG_EVENT: |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 80 | event->u.ExitThread.dwExitCode = data.info.exit.exit_code; |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 81 | break; |
| 82 | case EXIT_PROCESS_DEBUG_EVENT: |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 83 | event->u.ExitProcess.dwExitCode = data.info.exit.exit_code; |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 84 | break; |
| 85 | case LOAD_DLL_DEBUG_EVENT: |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 86 | event->u.LoadDll.hFile = data.info.load_dll.handle; |
| 87 | event->u.LoadDll.lpBaseOfDll = data.info.load_dll.base; |
| 88 | event->u.LoadDll.dwDebugInfoFileOffset = data.info.load_dll.dbg_offset; |
| 89 | event->u.LoadDll.nDebugInfoSize = data.info.load_dll.dbg_size; |
| 90 | event->u.LoadDll.lpImageName = data.info.load_dll.name; |
| 91 | event->u.LoadDll.fUnicode = data.info.load_dll.unicode; |
| 92 | if (data.info.load_dll.handle == -1) event->u.LoadDll.hFile = 0; |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 93 | break; |
| 94 | case UNLOAD_DLL_DEBUG_EVENT: |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 95 | event->u.UnloadDll.lpBaseOfDll = data.info.unload_dll.base; |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 96 | break; |
| 97 | case OUTPUT_DEBUG_STRING_EVENT: |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 98 | event->u.DebugString.lpDebugStringData = data.info.output_string.string; |
| 99 | event->u.DebugString.fUnicode = data.info.output_string.unicode; |
| 100 | event->u.DebugString.nDebugStringLength = data.info.output_string.length; |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 101 | break; |
| 102 | case RIP_EVENT: |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 103 | event->u.RipInfo.dwError = data.info.rip_info.error; |
| 104 | event->u.RipInfo.dwType = data.info.rip_info.type; |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 105 | break; |
| 106 | } |
| 107 | done: |
James Juran | 49c779a | 2001-11-19 02:24:14 +0000 | [diff] [blame] | 108 | /* nothing */ ; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 109 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 110 | SERVER_END_REQ; |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 111 | if (ret) return TRUE; |
| 112 | if (!wait) break; |
| 113 | res = WaitForSingleObject( wait, timeout ); |
| 114 | CloseHandle( wait ); |
| 115 | if (res != STATUS_WAIT_0) break; |
Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 116 | } |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 117 | SetLastError( ERROR_SEM_TIMEOUT ); |
| 118 | return FALSE; |
Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | |
| 122 | /********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 123 | * ContinueDebugEvent (KERNEL32.@) |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 124 | * |
| 125 | * Enables a thread that previously produced a debug event to continue. |
| 126 | * |
| 127 | * RETURNS |
| 128 | * |
| 129 | * True if the debugger is listed as the processes owner and the process |
| 130 | * and thread are valid. |
Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 131 | */ |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 132 | BOOL WINAPI ContinueDebugEvent( |
Patrik Stridvall | bca4a8d | 2001-02-12 03:49:57 +0000 | [diff] [blame] | 133 | DWORD pid, /* [in] The id of the process to continue. */ |
| 134 | DWORD tid, /* [in] The id of the thread to continue. */ |
| 135 | DWORD status) /* [in] The rule to apply to unhandled exeptions. */ |
Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 136 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 137 | BOOL ret; |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 138 | SERVER_START_REQ( continue_debug_event ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 139 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 140 | req->pid = (void *)pid; |
| 141 | req->tid = (void *)tid; |
| 142 | req->status = status; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 143 | ret = !wine_server_call_err( req ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 144 | } |
| 145 | SERVER_END_REQ; |
| 146 | return ret; |
Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | |
| 150 | /********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 151 | * DebugActiveProcess (KERNEL32.@) |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 152 | * |
Eric Pouech | fbccb38 | 2002-02-27 01:28:30 +0000 | [diff] [blame^] | 153 | * Attempts to attach the debugger to a process. |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 154 | * |
| 155 | * RETURNS |
| 156 | * |
| 157 | * True if the debugger was attached to process. |
Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 158 | */ |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 159 | BOOL WINAPI DebugActiveProcess( |
Patrik Stridvall | bca4a8d | 2001-02-12 03:49:57 +0000 | [diff] [blame] | 160 | DWORD pid) /* [in] The process to be debugged. */ |
Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 161 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 162 | BOOL ret; |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 163 | SERVER_START_REQ( debug_process ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 164 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 165 | req->pid = (void *)pid; |
Eric Pouech | fbccb38 | 2002-02-27 01:28:30 +0000 | [diff] [blame^] | 166 | req->attach = 1; |
| 167 | ret = !wine_server_call_err( req ); |
| 168 | } |
| 169 | SERVER_END_REQ; |
| 170 | return ret; |
| 171 | } |
| 172 | |
| 173 | /********************************************************************** |
| 174 | * DebugActiveProcessStop (KERNEL32.@) |
| 175 | * |
| 176 | * Attempts to detach the debugger from a process. |
| 177 | * |
| 178 | * RETURNS |
| 179 | * |
| 180 | * True if the debugger was detached from the process. |
| 181 | */ |
| 182 | BOOL WINAPI DebugActiveProcessStop( |
| 183 | DWORD pid) /* [in] The process to be detached. */ |
| 184 | { |
| 185 | BOOL ret; |
| 186 | SERVER_START_REQ( debug_process ) |
| 187 | { |
| 188 | req->pid = (void *)pid; |
| 189 | req->attach = 0; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 190 | ret = !wine_server_call_err( req ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 191 | } |
| 192 | SERVER_END_REQ; |
| 193 | return ret; |
Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | |
| 197 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 198 | * OutputDebugStringA (KERNEL32.@) |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 199 | * |
| 200 | * Output by an application of a unicode string to a debugger (if attached) |
| 201 | * and program log. |
Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 202 | */ |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 203 | void WINAPI OutputDebugStringA( |
Patrik Stridvall | bca4a8d | 2001-02-12 03:49:57 +0000 | [diff] [blame] | 204 | LPCSTR str) /* [in] The message to be logged and given to the debugger. */ |
Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 205 | { |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 206 | SERVER_START_REQ( output_debug_string ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 207 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 208 | req->string = (void *)str; |
| 209 | req->unicode = 0; |
| 210 | req->length = strlen(str) + 1; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 211 | wine_server_call( req ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 212 | } |
| 213 | SERVER_END_REQ; |
Andreas Mohr | cd13237 | 2000-05-23 01:13:07 +0000 | [diff] [blame] | 214 | WARN("%s\n", str); |
Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | |
| 218 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 219 | * OutputDebugStringW (KERNEL32.@) |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 220 | * |
| 221 | * Output by an appliccation of a unicode string to a debugger (if attached) |
| 222 | * and program log. |
Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 223 | */ |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 224 | void WINAPI OutputDebugStringW( |
Patrik Stridvall | bca4a8d | 2001-02-12 03:49:57 +0000 | [diff] [blame] | 225 | LPCWSTR str) /* [in] The message to be logged and given to the debugger. */ |
Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 226 | { |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 227 | SERVER_START_REQ( output_debug_string ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 228 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 229 | req->string = (void *)str; |
| 230 | req->unicode = 1; |
| 231 | req->length = (lstrlenW(str) + 1) * sizeof(WCHAR); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 232 | wine_server_call( req ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 233 | } |
| 234 | SERVER_END_REQ; |
Andreas Mohr | cd13237 | 2000-05-23 01:13:07 +0000 | [diff] [blame] | 235 | WARN("%s\n", debugstr_w(str)); |
Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | |
| 239 | /*********************************************************************** |
Patrik Stridvall | c01c193 | 2001-06-19 03:36:23 +0000 | [diff] [blame] | 240 | * OutputDebugString (KERNEL.115) |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 241 | * |
| 242 | * Output by a 16 bit application of an ascii string to a debugger (if attached) |
| 243 | * and program log. |
Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 244 | */ |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 245 | void WINAPI OutputDebugString16( |
Patrik Stridvall | bca4a8d | 2001-02-12 03:49:57 +0000 | [diff] [blame] | 246 | LPCSTR str) /* [in] The message to be logged and given to the debugger. */ |
Alexandre Julliard | 4cc1b33 | 1999-05-23 19:57:42 +0000 | [diff] [blame] | 247 | { |
| 248 | OutputDebugStringA( str ); |
| 249 | } |
Alexandre Julliard | 00641d5 | 2000-03-08 16:41:37 +0000 | [diff] [blame] | 250 | |
| 251 | |
| 252 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 253 | * DebugBreak (KERNEL32.@) |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 254 | * |
| 255 | * Raises an exception so that a debugger (if attached) |
| 256 | * can take some action. |
Alexandre Julliard | 00641d5 | 2000-03-08 16:41:37 +0000 | [diff] [blame] | 257 | */ |
| 258 | void WINAPI DebugBreak(void) |
| 259 | { |
| 260 | DbgBreakPoint(); |
| 261 | } |
| 262 | |
Eric Pouech | fbccb38 | 2002-02-27 01:28:30 +0000 | [diff] [blame^] | 263 | /*********************************************************************** |
| 264 | * DebugBreakProcess (KERNEL32.@) |
| 265 | * |
| 266 | * Raises an exception so that a debugger (if attached) |
| 267 | * can take some action. Same as DebugBreak, but applies to any process. |
| 268 | */ |
| 269 | BOOL WINAPI DebugBreakProcess(HANDLE hProc) |
| 270 | { |
| 271 | #if 0 /* FIXME: not correct */ |
| 272 | int res; |
| 273 | int pid; |
| 274 | |
| 275 | TRACE("(%08lx)\n", (DWORD)hProc); |
| 276 | |
| 277 | SERVER_START_REQ( get_process_info ) |
| 278 | { |
| 279 | req->handle = hProc; |
| 280 | res = wine_server_call_err( req ); |
| 281 | pid = (int)reply->pid; |
| 282 | } |
| 283 | SERVER_END_REQ; |
| 284 | return !res && kill(pid, SIGINT) == 0; |
| 285 | #endif |
| 286 | return FALSE; |
| 287 | } |
| 288 | |
Alexandre Julliard | 00641d5 | 2000-03-08 16:41:37 +0000 | [diff] [blame] | 289 | |
| 290 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 291 | * DebugBreak (KERNEL.203) |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 292 | * |
| 293 | * Raises an expection in a 16 bit application so that a debugger (if attached) |
| 294 | * can take some action. |
| 295 | * |
| 296 | * BUGS |
| 297 | * |
| 298 | * Only 386 compatible processors implemented. |
Alexandre Julliard | 00641d5 | 2000-03-08 16:41:37 +0000 | [diff] [blame] | 299 | */ |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 300 | void WINAPI DebugBreak16( |
Patrik Stridvall | bca4a8d | 2001-02-12 03:49:57 +0000 | [diff] [blame] | 301 | CONTEXT86 *context) /* [in/out] A pointer to the 386 compatible processor state. */ |
Alexandre Julliard | 00641d5 | 2000-03-08 16:41:37 +0000 | [diff] [blame] | 302 | { |
| 303 | #ifdef __i386__ |
| 304 | EXCEPTION_RECORD rec; |
| 305 | |
| 306 | rec.ExceptionCode = EXCEPTION_BREAKPOINT; |
| 307 | rec.ExceptionFlags = 0; |
| 308 | rec.ExceptionRecord = NULL; |
Alexandre Julliard | dfd3d4a | 2000-11-25 23:56:20 +0000 | [diff] [blame] | 309 | rec.ExceptionAddress = (LPVOID)context->Eip; |
Alexandre Julliard | 00641d5 | 2000-03-08 16:41:37 +0000 | [diff] [blame] | 310 | rec.NumberParameters = 0; |
| 311 | NtRaiseException( &rec, context, TRUE ); |
| 312 | #endif /* defined(__i386__) */ |
| 313 | } |
| 314 | |
| 315 | |
| 316 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 317 | * IsDebuggerPresent (KERNEL32.@) |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 318 | * |
| 319 | * Allows a process to determine if there is a debugger attached. |
| 320 | * |
| 321 | * RETURNS |
| 322 | * |
| 323 | * True if there is a debugger attached. |
Alexandre Julliard | 00641d5 | 2000-03-08 16:41:37 +0000 | [diff] [blame] | 324 | */ |
| 325 | BOOL WINAPI IsDebuggerPresent(void) |
| 326 | { |
| 327 | BOOL ret = FALSE; |
Alexandre Julliard | 67a7499 | 2001-02-27 02:09:16 +0000 | [diff] [blame] | 328 | SERVER_START_REQ( get_process_info ) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 329 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 330 | req->handle = GetCurrentProcess(); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 331 | if (!wine_server_call_err( req )) ret = reply->debugged; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 332 | } |
| 333 | SERVER_END_REQ; |
Alexandre Julliard | 00641d5 | 2000-03-08 16:41:37 +0000 | [diff] [blame] | 334 | return ret; |
| 335 | } |
Alexandre Julliard | 5b971f0 | 2000-11-26 22:39:50 +0000 | [diff] [blame] | 336 | |
| 337 | |
| 338 | /*********************************************************************** |
| 339 | * _DebugOutput (KERNEL.328) |
| 340 | */ |
| 341 | void WINAPIV _DebugOutput( void ) |
| 342 | { |
| 343 | VA_LIST16 valist; |
| 344 | WORD flags; |
| 345 | SEGPTR spec; |
| 346 | char caller[101]; |
| 347 | |
| 348 | /* Decode caller address */ |
| 349 | if (!GetModuleName16( GetExePtr(CURRENT_STACK16->cs), caller, sizeof(caller) )) |
| 350 | sprintf( caller, "%04X:%04X", CURRENT_STACK16->cs, CURRENT_STACK16->ip ); |
| 351 | |
| 352 | /* Build debug message string */ |
| 353 | VA_START16( valist ); |
| 354 | flags = VA_ARG16( valist, WORD ); |
| 355 | spec = VA_ARG16( valist, SEGPTR ); |
| 356 | /* FIXME: cannot use wvsnprintf16 from kernel */ |
Alexandre Julliard | 982a223 | 2000-12-13 20:20:09 +0000 | [diff] [blame] | 357 | /* wvsnprintf16( temp, sizeof(temp), MapSL(spec), valist ); */ |
Alexandre Julliard | 5b971f0 | 2000-11-26 22:39:50 +0000 | [diff] [blame] | 358 | |
| 359 | /* Output */ |
Alexandre Julliard | 982a223 | 2000-12-13 20:20:09 +0000 | [diff] [blame] | 360 | FIXME("%s %04x %s\n", caller, flags, debugstr_a(MapSL(spec)) ); |
Alexandre Julliard | 5b971f0 | 2000-11-26 22:39:50 +0000 | [diff] [blame] | 361 | } |
Eric Pouech | fbccb38 | 2002-02-27 01:28:30 +0000 | [diff] [blame^] | 362 | |
| 363 | /*********************************************************************** |
| 364 | * DebugSetProcessKillOnExit (KERNEL.328) |
| 365 | * |
| 366 | * Let a debugger decide wether a debuggee will be killed upon debugger |
| 367 | * termination |
| 368 | */ |
| 369 | BOOL WINAPI DebugSetProcessKillOnExit(BOOL kill) |
| 370 | { |
| 371 | BOOL ret = FALSE; |
| 372 | |
| 373 | SERVER_START_REQ( set_debugger_kill_on_exit ) |
| 374 | { |
| 375 | req->kill_on_exit = kill; |
| 376 | ret = !wine_server_call_err( req ); |
| 377 | } |
| 378 | SERVER_END_REQ; |
| 379 | return ret; |
| 380 | } |
| 381 | |