1999-05-23 21:57:42 +02:00
|
|
|
/*
|
|
|
|
* Win32 debugger functions
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999 Alexandre Julliard
|
|
|
|
*/
|
|
|
|
|
1999-07-31 19:36:48 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
1999-05-23 21:57:42 +02:00
|
|
|
#include "process.h"
|
|
|
|
#include "thread.h"
|
|
|
|
#include "server.h"
|
|
|
|
#include "debugtools.h"
|
|
|
|
|
1999-10-24 02:06:17 +02:00
|
|
|
DECLARE_DEBUG_CHANNEL(debugstr)
|
1999-05-23 21:57:42 +02:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* DEBUG_SendEvent
|
|
|
|
*
|
|
|
|
* Internal helper to send a debug event request to the server.
|
|
|
|
*/
|
|
|
|
static DWORD DEBUG_SendEvent( int code, void *data, int size )
|
|
|
|
{
|
1999-06-26 10:43:26 +02:00
|
|
|
DWORD ret = 0;
|
|
|
|
struct send_debug_event_request *req = get_req_buffer();
|
|
|
|
req->code = code;
|
|
|
|
memcpy( req + 1, data, size );
|
|
|
|
if (!server_call( REQ_SEND_DEBUG_EVENT )) ret = req->status;
|
|
|
|
return ret;
|
1999-05-23 21:57:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* DEBUG_SendExceptionEvent
|
|
|
|
*
|
|
|
|
* Send an EXCEPTION_DEBUG_EVENT event to the current process debugger.
|
|
|
|
*/
|
|
|
|
DWORD DEBUG_SendExceptionEvent( EXCEPTION_RECORD *rec, BOOL first_chance )
|
|
|
|
{
|
|
|
|
struct debug_event_exception event;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
event.code = rec->ExceptionCode;
|
|
|
|
event.flags = rec->ExceptionFlags;
|
|
|
|
event.record = rec->ExceptionRecord;
|
|
|
|
event.addr = rec->ExceptionAddress;
|
|
|
|
event.nb_params = rec->NumberParameters;
|
|
|
|
for (i = 0; i < event.nb_params; i++) event.params[i] = rec->ExceptionInformation[i];
|
|
|
|
event.first_chance = first_chance;
|
|
|
|
return DEBUG_SendEvent( EXCEPTION_DEBUG_EVENT, &event, sizeof(event) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* DEBUG_SendCreateProcessEvent
|
|
|
|
*
|
|
|
|
* Send an CREATE_PROCESS_DEBUG_EVENT event to the current process debugger.
|
|
|
|
* Must be called from the context of the new process.
|
|
|
|
*/
|
|
|
|
DWORD DEBUG_SendCreateProcessEvent( HFILE file, HMODULE module, void *entry )
|
|
|
|
{
|
|
|
|
struct debug_event_create_process event;
|
|
|
|
|
|
|
|
event.file = file;
|
|
|
|
event.process = 0; /* will be filled by server */
|
|
|
|
event.thread = 0; /* will be filled by server */
|
|
|
|
event.base = (void *)module;
|
|
|
|
event.dbg_offset = 0; /* FIXME */
|
|
|
|
event.dbg_size = 0; /* FIXME */
|
|
|
|
event.teb = NtCurrentTeb();
|
|
|
|
event.start = entry;
|
|
|
|
event.name = 0; /* FIXME */
|
|
|
|
event.unicode = 0; /* FIXME */
|
|
|
|
return DEBUG_SendEvent( CREATE_PROCESS_DEBUG_EVENT, &event, sizeof(event) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* DEBUG_SendCreateThreadEvent
|
|
|
|
*
|
|
|
|
* Send an CREATE_THREAD_DEBUG_EVENT event to the current process debugger.
|
|
|
|
* Must be called from the context of the new thread.
|
|
|
|
*/
|
|
|
|
DWORD DEBUG_SendCreateThreadEvent( void *entry )
|
|
|
|
{
|
|
|
|
struct debug_event_create_thread event;
|
|
|
|
|
|
|
|
event.handle = 0; /* will be filled by server */
|
|
|
|
event.teb = NtCurrentTeb();
|
|
|
|
event.start = entry;
|
|
|
|
return DEBUG_SendEvent( CREATE_THREAD_DEBUG_EVENT, &event, sizeof(event) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* DEBUG_SendLoadDLLEvent
|
|
|
|
*
|
|
|
|
* Send an LOAD_DLL_DEBUG_EVENT event to the current process debugger.
|
|
|
|
*/
|
|
|
|
DWORD DEBUG_SendLoadDLLEvent( HFILE file, HMODULE module, LPSTR name )
|
|
|
|
{
|
|
|
|
struct debug_event_load_dll event;
|
|
|
|
|
|
|
|
event.handle = file;
|
|
|
|
event.base = (void *)module;
|
|
|
|
event.dbg_offset = 0; /* FIXME */
|
|
|
|
event.dbg_size = 0; /* FIXME */
|
|
|
|
event.name = name;
|
|
|
|
event.unicode = 0;
|
|
|
|
return DEBUG_SendEvent( LOAD_DLL_DEBUG_EVENT, &event, sizeof(event) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* DEBUG_SendUnloadDLLEvent
|
|
|
|
*
|
|
|
|
* Send an UNLOAD_DLL_DEBUG_EVENT event to the current process debugger.
|
|
|
|
*/
|
|
|
|
DWORD DEBUG_SendUnloadDLLEvent( HMODULE module )
|
|
|
|
{
|
|
|
|
struct debug_event_unload_dll event;
|
|
|
|
|
|
|
|
event.base = (void *)module;
|
|
|
|
return DEBUG_SendEvent( UNLOAD_DLL_DEBUG_EVENT, &event, sizeof(event) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* WaitForDebugEvent (KERNEL32.720)
|
|
|
|
*
|
|
|
|
* Waits for a debugging event to occur in a process being debugged
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* event [I] Address of structure for event information
|
|
|
|
* timeout [I] Number of milliseconds to wait for event
|
|
|
|
*
|
|
|
|
* RETURNS STD
|
|
|
|
*/
|
|
|
|
BOOL WINAPI WaitForDebugEvent( LPDEBUG_EVENT event, DWORD timeout )
|
|
|
|
{
|
1999-06-26 10:43:26 +02:00
|
|
|
struct wait_debug_event_request *req = get_req_buffer();
|
|
|
|
union debug_event_data *data = (union debug_event_data *)(req + 1);
|
|
|
|
int i;
|
1999-05-23 21:57:42 +02:00
|
|
|
|
1999-06-26 10:43:26 +02:00
|
|
|
req->timeout = timeout;
|
|
|
|
if (server_call( REQ_WAIT_DEBUG_EVENT )) return FALSE;
|
|
|
|
if ((req->code < 0) || (req->code > RIP_EVENT))
|
|
|
|
server_protocol_error( "WaitForDebugEvent: bad code %d\n", req->code );
|
1999-05-23 21:57:42 +02:00
|
|
|
|
1999-06-26 10:43:26 +02:00
|
|
|
event->dwDebugEventCode = req->code;
|
|
|
|
event->dwProcessId = (DWORD)req->pid;
|
|
|
|
event->dwThreadId = (DWORD)req->tid;
|
|
|
|
switch(req->code)
|
1999-05-23 21:57:42 +02:00
|
|
|
{
|
|
|
|
case EXCEPTION_DEBUG_EVENT:
|
1999-06-26 10:43:26 +02:00
|
|
|
event->u.Exception.ExceptionRecord.ExceptionCode = data->exception.code;
|
|
|
|
event->u.Exception.ExceptionRecord.ExceptionFlags = data->exception.flags;
|
|
|
|
event->u.Exception.ExceptionRecord.ExceptionRecord = data->exception.record;
|
|
|
|
event->u.Exception.ExceptionRecord.ExceptionAddress = data->exception.addr;
|
|
|
|
event->u.Exception.ExceptionRecord.NumberParameters = data->exception.nb_params;
|
|
|
|
for (i = 0; i < data->exception.nb_params; i++)
|
|
|
|
event->u.Exception.ExceptionRecord.ExceptionInformation[i] = data->exception.params[i];
|
|
|
|
event->u.Exception.dwFirstChance = data->exception.first_chance;
|
1999-05-23 21:57:42 +02:00
|
|
|
break;
|
|
|
|
case CREATE_THREAD_DEBUG_EVENT:
|
1999-06-26 10:43:26 +02:00
|
|
|
event->u.CreateThread.hThread = data->create_thread.handle;
|
|
|
|
event->u.CreateThread.lpThreadLocalBase = data->create_thread.teb;
|
|
|
|
event->u.CreateThread.lpStartAddress = data->create_thread.start;
|
1999-05-23 21:57:42 +02:00
|
|
|
break;
|
|
|
|
case CREATE_PROCESS_DEBUG_EVENT:
|
1999-06-26 10:43:26 +02:00
|
|
|
event->u.CreateProcessInfo.hFile = data->create_process.file;
|
|
|
|
event->u.CreateProcessInfo.hProcess = data->create_process.process;
|
|
|
|
event->u.CreateProcessInfo.hThread = data->create_process.thread;
|
|
|
|
event->u.CreateProcessInfo.lpBaseOfImage = data->create_process.base;
|
|
|
|
event->u.CreateProcessInfo.dwDebugInfoFileOffset = data->create_process.dbg_offset;
|
|
|
|
event->u.CreateProcessInfo.nDebugInfoSize = data->create_process.dbg_size;
|
|
|
|
event->u.CreateProcessInfo.lpThreadLocalBase = data->create_process.teb;
|
|
|
|
event->u.CreateProcessInfo.lpStartAddress = data->create_process.start;
|
|
|
|
event->u.CreateProcessInfo.lpImageName = data->create_process.name;
|
|
|
|
event->u.CreateProcessInfo.fUnicode = data->create_process.unicode;
|
|
|
|
if (data->create_process.file == -1) event->u.CreateProcessInfo.hFile = 0;
|
1999-05-23 21:57:42 +02:00
|
|
|
break;
|
|
|
|
case EXIT_THREAD_DEBUG_EVENT:
|
1999-06-26 10:43:26 +02:00
|
|
|
event->u.ExitThread.dwExitCode = data->exit.exit_code;
|
1999-05-23 21:57:42 +02:00
|
|
|
break;
|
|
|
|
case EXIT_PROCESS_DEBUG_EVENT:
|
1999-06-26 10:43:26 +02:00
|
|
|
event->u.ExitProcess.dwExitCode = data->exit.exit_code;
|
1999-05-23 21:57:42 +02:00
|
|
|
break;
|
|
|
|
case LOAD_DLL_DEBUG_EVENT:
|
1999-06-26 10:43:26 +02:00
|
|
|
event->u.LoadDll.hFile = data->load_dll.handle;
|
|
|
|
event->u.LoadDll.lpBaseOfDll = data->load_dll.base;
|
|
|
|
event->u.LoadDll.dwDebugInfoFileOffset = data->load_dll.dbg_offset;
|
|
|
|
event->u.LoadDll.nDebugInfoSize = data->load_dll.dbg_size;
|
|
|
|
event->u.LoadDll.lpImageName = data->load_dll.name;
|
|
|
|
event->u.LoadDll.fUnicode = data->load_dll.unicode;
|
|
|
|
if (data->load_dll.handle == -1) event->u.LoadDll.hFile = 0;
|
1999-05-23 21:57:42 +02:00
|
|
|
break;
|
|
|
|
case UNLOAD_DLL_DEBUG_EVENT:
|
1999-06-26 10:43:26 +02:00
|
|
|
event->u.UnloadDll.lpBaseOfDll = data->unload_dll.base;
|
1999-05-23 21:57:42 +02:00
|
|
|
break;
|
|
|
|
case OUTPUT_DEBUG_STRING_EVENT:
|
1999-06-26 10:43:26 +02:00
|
|
|
event->u.DebugString.lpDebugStringData = data->output_string.string;
|
|
|
|
event->u.DebugString.fUnicode = data->output_string.unicode;
|
|
|
|
event->u.DebugString.nDebugStringLength = data->output_string.length;
|
1999-05-23 21:57:42 +02:00
|
|
|
break;
|
|
|
|
case RIP_EVENT:
|
1999-06-26 10:43:26 +02:00
|
|
|
event->u.RipInfo.dwError = data->rip_info.error;
|
|
|
|
event->u.RipInfo.dwType = data->rip_info.type;
|
1999-05-23 21:57:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* ContinueDebugEvent (KERNEL32.146)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI ContinueDebugEvent( DWORD pid, DWORD tid, DWORD status )
|
|
|
|
{
|
1999-06-26 10:43:26 +02:00
|
|
|
struct continue_debug_event_request *req = get_req_buffer();
|
|
|
|
req->pid = (void *)pid;
|
|
|
|
req->tid = (void *)tid;
|
|
|
|
req->status = status;
|
|
|
|
return !server_call( REQ_CONTINUE_DEBUG_EVENT );
|
1999-05-23 21:57:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* DebugActiveProcess (KERNEL32.180)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DebugActiveProcess( DWORD pid )
|
|
|
|
{
|
1999-06-26 10:43:26 +02:00
|
|
|
struct debug_process_request *req = get_req_buffer();
|
|
|
|
req->pid = (void *)pid;
|
|
|
|
return !server_call( REQ_DEBUG_PROCESS );
|
1999-05-23 21:57:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* OutputDebugStringA (KERNEL32.548)
|
|
|
|
*/
|
|
|
|
void WINAPI OutputDebugStringA( LPCSTR str )
|
|
|
|
{
|
|
|
|
if (PROCESS_Current()->flags & PDB32_DEBUGGED)
|
|
|
|
{
|
|
|
|
struct debug_event_output_string event;
|
|
|
|
event.string = (void *)str;
|
|
|
|
event.unicode = 0;
|
|
|
|
event.length = strlen(str) + 1;
|
|
|
|
DEBUG_SendEvent( OUTPUT_DEBUG_STRING_EVENT, &event, sizeof(event) );
|
|
|
|
}
|
1999-10-24 02:06:17 +02:00
|
|
|
|
|
|
|
TRACE_(debugstr)("%s\n", str);
|
1999-05-23 21:57:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* OutputDebugStringW (KERNEL32.549)
|
|
|
|
*/
|
|
|
|
void WINAPI OutputDebugStringW( LPCWSTR str )
|
|
|
|
{
|
|
|
|
if (PROCESS_Current()->flags & PDB32_DEBUGGED)
|
|
|
|
{
|
|
|
|
struct debug_event_output_string event;
|
|
|
|
event.string = (void *)str;
|
|
|
|
event.unicode = 1;
|
|
|
|
event.length = (lstrlenW(str) + 1) * sizeof(WCHAR);
|
|
|
|
DEBUG_SendEvent( OUTPUT_DEBUG_STRING_EVENT, &event, sizeof(event) );
|
|
|
|
}
|
1999-10-24 02:06:17 +02:00
|
|
|
|
|
|
|
TRACE_(debugstr)("%s\n", debugstr_w(str));
|
1999-05-23 21:57:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* OutputDebugString16 (KERNEL.115)
|
|
|
|
*/
|
|
|
|
void WINAPI OutputDebugString16( LPCSTR str )
|
|
|
|
{
|
|
|
|
OutputDebugStringA( str );
|
|
|
|
}
|