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