1999-05-23 21:57:42 +02:00
|
|
|
/*
|
|
|
|
* Win32 debugger functions
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999 Alexandre Julliard
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1999-05-23 21:57:42 +02:00
|
|
|
*/
|
|
|
|
|
2000-11-26 23:39:50 +01:00
|
|
|
#include <stdio.h>
|
1999-07-31 19:36:48 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2010-03-14 21:53:28 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2000-03-08 13:01:30 +01:00
|
|
|
#include "winerror.h"
|
2001-07-19 02:39:09 +02:00
|
|
|
#include "wine/server.h"
|
2005-05-16 16:45:18 +02:00
|
|
|
#include "kernel_private.h"
|
2019-05-14 12:30:46 +02:00
|
|
|
#include "wine/asm.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2014-06-14 09:39:24 +02:00
|
|
|
#include "wine/exception.h"
|
1999-05-23 21:57:42 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(debugstr);
|
1999-05-23 21:57:42 +02:00
|
|
|
|
2020-09-28 16:34:11 +02:00
|
|
|
void *dummy = RtlUnwind; /* force importing RtlUnwind from ntdll */
|
|
|
|
|
2019-12-16 12:00:36 +01:00
|
|
|
static LONG WINAPI debug_exception_handler( EXCEPTION_POINTERS *eptr )
|
|
|
|
{
|
|
|
|
EXCEPTION_RECORD *rec = eptr->ExceptionRecord;
|
|
|
|
return (rec->ExceptionCode == DBG_PRINTEXCEPTION_C) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* OutputDebugStringA (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Duplicate since IMVU doesn't like it if we call kernelbase.OutputDebugStringA.
|
|
|
|
*/
|
|
|
|
void WINAPI DECLSPEC_HOTPATCH OutputDebugStringA( LPCSTR str )
|
|
|
|
{
|
|
|
|
static HANDLE DBWinMutex = NULL;
|
|
|
|
static BOOL mutex_inited = FALSE;
|
|
|
|
BOOL caught_by_dbg = TRUE;
|
|
|
|
|
|
|
|
if (!str) str = "";
|
|
|
|
WARN( "%s\n", debugstr_a(str) );
|
|
|
|
|
|
|
|
/* raise exception, WaitForDebugEvent() will generate a corresponding debug event */
|
|
|
|
__TRY
|
|
|
|
{
|
|
|
|
ULONG_PTR args[2];
|
|
|
|
args[0] = strlen(str) + 1;
|
|
|
|
args[1] = (ULONG_PTR)str;
|
|
|
|
RaiseException( DBG_PRINTEXCEPTION_C, 0, 2, args );
|
|
|
|
}
|
|
|
|
__EXCEPT(debug_exception_handler)
|
|
|
|
{
|
|
|
|
caught_by_dbg = FALSE;
|
|
|
|
}
|
|
|
|
__ENDTRY
|
|
|
|
if (caught_by_dbg) return;
|
|
|
|
|
|
|
|
/* send string to a system-wide monitor */
|
|
|
|
if (!mutex_inited)
|
|
|
|
{
|
|
|
|
/* first call to OutputDebugString, initialize mutex handle */
|
2020-11-17 00:55:16 +01:00
|
|
|
HANDLE mutex = CreateMutexExW( NULL, L"DBWinMutex", 0, SYNCHRONIZE );
|
2019-12-16 12:00:36 +01:00
|
|
|
if (mutex)
|
|
|
|
{
|
|
|
|
if (InterlockedCompareExchangePointer( &DBWinMutex, mutex, 0 ) != 0)
|
|
|
|
/* someone beat us here... */
|
|
|
|
CloseHandle( mutex );
|
|
|
|
}
|
|
|
|
mutex_inited = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DBWinMutex)
|
|
|
|
{
|
|
|
|
HANDLE mapping;
|
|
|
|
|
2020-11-17 00:55:16 +01:00
|
|
|
mapping = OpenFileMappingW( FILE_MAP_WRITE, FALSE, L"DBWIN_BUFFER" );
|
2019-12-16 12:00:36 +01:00
|
|
|
if (mapping)
|
|
|
|
{
|
|
|
|
LPVOID buffer;
|
|
|
|
HANDLE eventbuffer, eventdata;
|
|
|
|
|
|
|
|
buffer = MapViewOfFile( mapping, FILE_MAP_WRITE, 0, 0, 0 );
|
2020-11-17 00:55:16 +01:00
|
|
|
eventbuffer = OpenEventW( SYNCHRONIZE, FALSE, L"DBWIN_BUFFER_READY" );
|
|
|
|
eventdata = OpenEventW( EVENT_MODIFY_STATE, FALSE, L"DBWIN_DATA_READY" );
|
2019-12-16 12:00:36 +01:00
|
|
|
|
|
|
|
if (buffer && eventbuffer && eventdata)
|
|
|
|
{
|
|
|
|
/* monitor is present, synchronize with other OutputDebugString invocations */
|
|
|
|
WaitForSingleObject( DBWinMutex, INFINITE );
|
|
|
|
|
|
|
|
/* acquire control over the buffer */
|
|
|
|
if (WaitForSingleObject( eventbuffer, 10000 ) == WAIT_OBJECT_0)
|
|
|
|
{
|
|
|
|
int str_len = strlen( str );
|
|
|
|
struct _mon_buffer_t
|
|
|
|
{
|
|
|
|
DWORD pid;
|
|
|
|
char buffer[1];
|
|
|
|
} *mon_buffer = (struct _mon_buffer_t*) buffer;
|
|
|
|
|
|
|
|
if (str_len > (4096 - sizeof(DWORD) - 1)) str_len = 4096 - sizeof(DWORD) - 1;
|
|
|
|
mon_buffer->pid = GetCurrentProcessId();
|
|
|
|
memcpy( mon_buffer->buffer, str, str_len );
|
|
|
|
mon_buffer->buffer[str_len] = 0;
|
|
|
|
|
|
|
|
/* signal data ready */
|
|
|
|
SetEvent( eventdata );
|
|
|
|
}
|
|
|
|
ReleaseMutex( DBWinMutex );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buffer) UnmapViewOfFile( buffer );
|
|
|
|
if (eventbuffer) CloseHandle( eventbuffer );
|
|
|
|
if (eventdata) CloseHandle( eventdata );
|
|
|
|
CloseHandle( mapping );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-27 02:28:30 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* DebugBreakProcess (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Raises an exception so that a debugger (if attached)
|
|
|
|
* can take some action. Same as DebugBreak, but applies to any process.
|
2004-08-26 20:22:17 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hProc [I] Process to break into.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
*
|
|
|
|
* True if successful.
|
2002-02-27 02:28:30 +01:00
|
|
|
*/
|
2019-07-05 13:21:37 +02:00
|
|
|
BOOL WINAPI DebugBreakProcess(HANDLE process)
|
2002-02-27 02:28:30 +01:00
|
|
|
{
|
2020-05-26 12:29:06 +02:00
|
|
|
return set_ntstatus( DbgUiIssueRemoteBreakin( process ));
|
2002-02-27 02:28:30 +01:00
|
|
|
}
|
|
|
|
|
2000-03-08 17:41:37 +01:00
|
|
|
|
2002-02-27 02:28:30 +01:00
|
|
|
/***********************************************************************
|
2002-03-11 02:17:26 +01:00
|
|
|
* DebugSetProcessKillOnExit (KERNEL32.@)
|
2002-02-27 02:28:30 +01:00
|
|
|
*
|
2004-01-16 22:26:08 +01:00
|
|
|
* Let a debugger decide whether a debuggee will be killed upon debugger
|
2004-08-26 20:22:17 +02:00
|
|
|
* termination.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* kill [I] If set to true then kill the process on exit.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* True if successful, false otherwise.
|
2002-02-27 02:28:30 +01:00
|
|
|
*/
|
|
|
|
BOOL WINAPI DebugSetProcessKillOnExit(BOOL kill)
|
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
SERVER_START_REQ( set_debugger_kill_on_exit )
|
|
|
|
{
|
|
|
|
req->kill_on_exit = kill;
|
|
|
|
ret = !wine_server_call_err( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|