ntdll: Implement few Dbg* functions.
Vitaliy Margolen
wine-patch at kievinfo.com
Sun Dec 18 12:51:04 CST 2005
ChangeLog:
ntdll: Implement few Dbg* functions.
kernel32: Use new Dbg* functions instead of server calls.
dlls/kernel/debugger.c | 47 ++++++++++++-------------
dlls/ntdll/debugbuffer.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++
dlls/ntdll/ntdll.spec | 6 ++-
include/winternl.h | 3 ++
server/debugger.c | 6 ++-
server/protocol.def | 2 +
6 files changed, 121 insertions(+), 30 deletions(-)
-------------- next part --------------
e05b254c45d9ef2ed5fd315ff67c4a3416208724
diff --git a/dlls/kernel/debugger.c b/dlls/kernel/debugger.c
index 2c583d0..6e85320 100644
--- a/dlls/kernel/debugger.c
+++ b/dlls/kernel/debugger.c
@@ -21,6 +21,8 @@
#include <stdio.h>
#include <string.h>
+#include "ntstatus.h"
+#define WIN32_NO_STATUS
#include "winerror.h"
#include "wine/winbase16.h"
#include "wine/server.h"
@@ -183,15 +185,16 @@ BOOL WINAPI ContinueDebugEvent(
*/
BOOL WINAPI DebugActiveProcess( DWORD pid )
{
- BOOL ret;
- SERVER_START_REQ( debug_process )
+ NTSTATUS status;
+ HANDLE hProc = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pid );
+
+ if (hProc != INVALID_HANDLE_VALUE)
{
- req->pid = pid;
- req->attach = 1;
- ret = !wine_server_call_err( req );
+ status = DbgUiDebugActiveProcess( hProc );
+ if (status == STATUS_SUCCESS) return TRUE;
+ SetLastError( RtlNtStatusToDosError(status) );
}
- SERVER_END_REQ;
- return ret;
+ return FALSE;
}
/**********************************************************************
@@ -208,15 +211,16 @@ BOOL WINAPI DebugActiveProcess( DWORD pi
*/
BOOL WINAPI DebugActiveProcessStop( DWORD pid )
{
- BOOL ret;
- SERVER_START_REQ( debug_process )
+ NTSTATUS status;
+ HANDLE hProc = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pid );
+
+ if (hProc != INVALID_HANDLE_VALUE)
{
- req->pid = pid;
- req->attach = 0;
- ret = !wine_server_call_err( req );
+ status = DbgUiStopDebugging( hProc );
+ if (status == STATUS_SUCCESS) return TRUE;
+ SetLastError( RtlNtStatusToDosError(status) );
}
- SERVER_END_REQ;
- return ret;
+ return FALSE;
}
@@ -321,19 +325,14 @@ void WINAPI DebugBreak(void)
*/
BOOL WINAPI DebugBreakProcess(HANDLE hProc)
{
- BOOL ret, self;
+ NTSTATUS status = DbgUiIssueRemoteBreakin( hProc );
- TRACE("(%p)\n", hProc);
-
- SERVER_START_REQ( debug_break )
+ if (status != STATUS_SUCCESS)
{
- req->handle = hProc;
- ret = !wine_server_call_err( req );
- self = ret && reply->self;
+ SetLastError( RtlNtStatusToDosError(status) );
+ return FALSE;
}
- SERVER_END_REQ;
- if (self) DbgBreakPoint();
- return ret;
+ return TRUE;
}
diff --git a/dlls/ntdll/debugbuffer.c b/dlls/ntdll/debugbuffer.c
index 600c7fa..1fb9f52 100644
--- a/dlls/ntdll/debugbuffer.c
+++ b/dlls/ntdll/debugbuffer.c
@@ -2,6 +2,7 @@
* NtDll debug buffer functions
*
* Copyright 2004 Raphael Junqueira
+ * Copyright 2005 Vitaliy Margolen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -34,6 +35,7 @@
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(debug_buffer);
+WINE_DECLARE_DEBUG_CHANNEL(debug);
static void dump_DEBUG_MODULE_INFORMATION(PDEBUG_MODULE_INFORMATION iBuf)
{
@@ -144,3 +146,88 @@ NTSTATUS WINAPI RtlQueryProcessDebugInfo
dump_DEBUG_BUFFER(iBuf);
return nts;
}
+
+/***********************************************************************
+ * DbgUiIssueRemoteBreakin (NTDLL.@)
+ *
+ * Raises an exception so that a debugger (if attached)
+ * can take some action. Same as DebugBreak, but applies to any process.
+ *
+ * PARAMS
+ * hProcess [I] Process handle to break into.
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS.
+ * Failure: An NTSTATUS error code.
+ */
+NTSTATUS WINAPI DbgUiIssueRemoteBreakin(HANDLE hProcess)
+{
+ NTSTATUS ret;
+ BOOL self;
+
+ TRACE_(debug)("(%p)\n", hProcess);
+ SERVER_START_REQ( debug_break )
+ {
+ req->handle = hProcess;
+ ret = wine_server_call( req );
+ self = reply->self;
+ }
+ SERVER_END_REQ;
+ if (!ret && self) DbgBreakPoint();
+ return ret;
+}
+
+/***********************************************************************
+ * DbgUiDebugActiveProcess (NTDLL.@)
+ *
+ * Attempts to attach the debugger to a process.
+ *
+ * PARAMS
+ * hProcess [I] The process to be debugged.
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS.
+ * Failure: An NTSTATUS error code.
+ */
+NTSTATUS WINAPI DbgUiDebugActiveProcess(HANDLE hProcess)
+{
+ NTSTATUS ret;
+
+ TRACE_(debug)("(%p)\n", hProcess);
+ SERVER_START_REQ( debug_process )
+ {
+ req->handle = hProcess;
+ req->attach = 1;
+ ret = wine_server_call( req );
+ }
+ SERVER_END_REQ;
+ return ret;
+}
+
+/***********************************************************************
+ * DbgUiStopDebugging (NTDLL.@)
+ *
+ * Attempts to detach the debugger from a process.
+ *
+ * PARAMS
+ * hProcess [I] The process to be detached from.
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS.
+ * Failure: An NTSTATUS error code.
+ */
+NTSTATUS WINAPI DbgUiStopDebugging(HANDLE hProcess)
+{
+ NTSTATUS ret;
+
+ TRACE_(debug)("(%p)\n", hProcess);
+ SERVER_START_REQ( debug_process )
+ {
+ req->handle = hProcess;
+ req->attach = 0;
+ ret = wine_server_call( req );
+ }
+ SERVER_END_REQ;
+ return ret;
+}
+
diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec
index b3efbe0..b4ec384 100644
--- a/dlls/ntdll/ntdll.spec
+++ b/dlls/ntdll/ntdll.spec
@@ -33,12 +33,12 @@
@ stub DbgUiConnectToDbg
@ stub DbgUiContinue
# @ stub DbgUiConvertStateChangeStructure
-# @ stub DbgUiDebugActiveProcess
+@ stdcall DbgUiDebugActiveProcess(long)
# @ stub DbgUiGetThreadDebugObject
-# @ stub DbgUiIssueRemoteBreakin
+@ stdcall DbgUiIssueRemoteBreakin(long)
# @ stub DbgUiRemoteBreakin
# @ stub DbgUiSetThreadDebugObject
-# @ stub DbgUiStopDebugging
+@ stdcall DbgUiStopDebugging(long)
@ stub DbgUiWaitStateChange
@ stdcall DbgUserBreakPoint()
# @ stub KiFastSystemCall
diff --git a/include/winternl.h b/include/winternl.h
index 2be14d3..f6f8b55 100644
--- a/include/winternl.h
+++ b/include/winternl.h
@@ -1697,6 +1697,9 @@ void WINAPI DbgUserBreakPoint(void);
#endif /* __i386__ && __GNUC__ */
NTSTATUS WINAPIV DbgPrint(LPCSTR fmt, ...);
NTSTATUS WINAPIV DbgPrintEx(ULONG iComponentId, ULONG Level, LPCSTR fmt, ...);
+NTSTATUS WINAPI DbgUiIssueRemoteBreakin(HANDLE);
+NTSTATUS WINAPI DbgUiDebugActiveProcess(HANDLE);
+NTSTATUS WINAPI DbgUiStopDebugging(HANDLE);
NTSTATUS WINAPI LdrAccessResource(HMODULE,const IMAGE_RESOURCE_DATA_ENTRY*,void**,PULONG);
NTSTATUS WINAPI LdrFindResourceDirectory_U(HMODULE,const LDR_RESOURCE_INFO*,ULONG,const IMAGE_RESOURCE_DIRECTORY**);
diff --git a/server/debugger.c b/server/debugger.c
index e326516..e14101e 100644
--- a/server/debugger.c
+++ b/server/debugger.c
@@ -607,8 +607,10 @@ DECL_HANDLER(continue_debug_event)
/* Start debugging an existing process */
DECL_HANDLER(debug_process)
{
- struct process *process = get_process_from_id( req->pid );
- if (!process) return;
+ struct process *process;
+
+ if (!(process = get_process_from_handle( req->handle, PROCESS_ALL_ACCESS )))
+ return;
if (!req->attach)
{
diff --git a/server/protocol.def b/server/protocol.def
index f3befce..5f83247 100644
--- a/server/protocol.def
+++ b/server/protocol.def
@@ -1209,7 +1209,7 @@ enum char_info_mode
/* Start/stop debugging an existing process */
@REQ(debug_process)
- process_id_t pid; /* id of the process to debug */
+ obj_handle_t handle; /* handle of the process to debug */
int attach; /* 1=attaching / 0=detaching from the process */
@END
More information about the wine-patches
mailing list