Alexandre Julliard : kernel32: Move the initial process breakpoint to LdrInitializeThunk().
Alexandre Julliard
julliard at winehq.org
Mon Aug 31 17:16:54 CDT 2020
Module: wine
Branch: master
Commit: 2b40969c58a099f958c58909b666915991a42979
URL: https://source.winehq.org/git/wine.git/?a=commit;h=2b40969c58a099f958c58909b666915991a42979
Author: Alexandre Julliard <julliard at winehq.org>
Date: Mon Aug 31 11:30:41 2020 +0200
kernel32: Move the initial process breakpoint to LdrInitializeThunk().
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/kernel32/process.c | 16 --------------
dlls/ntdll/loader.c | 24 ++++++++++++++++++++
dlls/ntdll/tests/exception.c | 52 ++++++++++++++++++++++++++++++++++++++++----
3 files changed, 72 insertions(+), 20 deletions(-)
diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c
index bf8f056ada..9d725e1a43 100644
--- a/dlls/kernel32/process.c
+++ b/dlls/kernel32/process.c
@@ -136,8 +136,6 @@ void CDECL start_process( LPTHREAD_START_ROUTINE entry, PEB *peb )
void CDECL __wine_start_process( LPTHREAD_START_ROUTINE entry, PEB *peb )
#endif
{
- BOOL being_debugged;
-
if (!entry)
{
ERR( "%s doesn't have an entry point, it cannot be executed\n",
@@ -148,20 +146,6 @@ void CDECL __wine_start_process( LPTHREAD_START_ROUTINE entry, PEB *peb )
TRACE_(relay)( "\1Starting process %s (entryproc=%p)\n",
debugstr_w(peb->ProcessParameters->ImagePathName.Buffer), entry );
- __TRY
- {
- if (!CheckRemoteDebuggerPresent( GetCurrentProcess(), &being_debugged ))
- being_debugged = FALSE;
-
- SetLastError( 0 ); /* clear error code */
- if (being_debugged) DbgBreakPoint();
- }
- __EXCEPT_ALL
- {
- /* do nothing */
- }
- __ENDTRY
-
__TRY
{
ExitThread( call_process_entry( peb, entry ));
diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index 8e76e39fa5..57fc75cef4 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -3407,6 +3407,29 @@ PIMAGE_NT_HEADERS WINAPI RtlImageNtHeader(HMODULE hModule)
return ret;
}
+/***********************************************************************
+ * process_breakpoint
+ *
+ * Trigger a debug breakpoint if the process is being debugged.
+ */
+static void process_breakpoint(void)
+{
+ DWORD_PTR port = 0;
+
+ NtQueryInformationProcess( GetCurrentProcess(), ProcessDebugPort, &port, sizeof(port), NULL );
+ if (!port) return;
+
+ __TRY
+ {
+ DbgBreakPoint();
+ }
+ __EXCEPT_ALL
+ {
+ /* do nothing */
+ }
+ __ENDTRY
+}
+
/******************************************************************
* LdrInitializeThunk (NTDLL.@)
@@ -3494,6 +3517,7 @@ void WINAPI LdrInitializeThunk( CONTEXT *context, ULONG_PTR unknown2, ULONG_PTR
if (wm->ldr.TlsIndex != -1) call_tls_callbacks( wm->ldr.DllBase, DLL_PROCESS_ATTACH );
if (wm->ldr.Flags & LDR_WINE_INTERNAL) unix_funcs->init_builtin_dll( wm->ldr.DllBase );
if (wm->ldr.ActivationContext) RtlDeactivateActivationContext( 0, cookie );
+ process_breakpoint();
}
else
{
diff --git a/dlls/ntdll/tests/exception.c b/dlls/ntdll/tests/exception.c
index ca0dec2a62..a9b32f0586 100644
--- a/dlls/ntdll/tests/exception.c
+++ b/dlls/ntdll/tests/exception.c
@@ -1049,7 +1049,18 @@ static void test_debugger(void)
ok(FALSE, "got way too many exceptions, probably caught in an infinite loop, terminating child\n");
pNtTerminateProcess(pi.hProcess, 1);
}
- else if (counter >= 2) /* skip startup breakpoint */
+ else if (counter < 2) /* startup breakpoint */
+ {
+ /* breakpoint is inside ntdll */
+ void *ntdll = GetModuleHandleA( "ntdll.dll" );
+ IMAGE_NT_HEADERS *nt = RtlImageNtHeader( ntdll );
+
+ ok( (char *)ctx.Eip >= (char *)ntdll &&
+ (char *)ctx.Eip < (char *)ntdll + nt->OptionalHeader.SizeOfImage,
+ "wrong eip %p ntdll %p-%p\n", (void *)ctx.Eip, ntdll,
+ (char *)ntdll + nt->OptionalHeader.SizeOfImage );
+ }
+ else
{
if (stage == 1)
{
@@ -3223,7 +3234,18 @@ static void test_debugger(void)
ok(FALSE, "got way too many exceptions, probably caught in an infinite loop, terminating child\n");
pNtTerminateProcess(pi.hProcess, 1);
}
- else if (counter >= 2) /* skip startup breakpoint */
+ else if (counter < 2) /* startup breakpoint */
+ {
+ /* breakpoint is inside ntdll */
+ void *ntdll = GetModuleHandleA( "ntdll.dll" );
+ IMAGE_NT_HEADERS *nt = RtlImageNtHeader( ntdll );
+
+ ok( (char *)ctx.Rip >= (char *)ntdll &&
+ (char *)ctx.Rip < (char *)ntdll + nt->OptionalHeader.SizeOfImage,
+ "wrong rip %p ntdll %p-%p\n", (void *)ctx.Rip, ntdll,
+ (char *)ntdll + nt->OptionalHeader.SizeOfImage );
+ }
+ else
{
if (stage == 1)
{
@@ -4083,7 +4105,18 @@ static void test_debugger(void)
ok(FALSE, "got way too many exceptions, probably caught in an infinite loop, terminating child\n");
pNtTerminateProcess(pi.hProcess, 1);
}
- else if (counter >= 2) /* skip startup breakpoint */
+ else if (counter < 2) /* startup breakpoint */
+ {
+ /* breakpoint is inside ntdll */
+ void *ntdll = GetModuleHandleA( "ntdll.dll" );
+ IMAGE_NT_HEADERS *nt = RtlImageNtHeader( ntdll );
+
+ ok( (char *)ctx.Pc >= (char *)ntdll &&
+ (char *)ctx.Pc < (char *)ntdll + nt->OptionalHeader.SizeOfImage,
+ "wrong pc %p ntdll %p-%p\n", (void *)ctx.Pc, ntdll,
+ (char *)ntdll + nt->OptionalHeader.SizeOfImage );
+ }
+ else
{
#if 0 /* RtlRaiseException test disabled for now */
if (stage == 1)
@@ -5010,7 +5043,18 @@ static void test_debugger(void)
ok(FALSE, "got way too many exceptions, probably caught in an infinite loop, terminating child\n");
pNtTerminateProcess(pi.hProcess, 1);
}
- else if (counter >= 2) /* skip startup breakpoint */
+ else if (counter < 2) /* startup breakpoint */
+ {
+ /* breakpoint is inside ntdll */
+ void *ntdll = GetModuleHandleA( "ntdll.dll" );
+ IMAGE_NT_HEADERS *nt = RtlImageNtHeader( ntdll );
+
+ ok( (char *)ctx.Pc >= (char *)ntdll &&
+ (char *)ctx.Pc < (char *)ntdll + nt->OptionalHeader.SizeOfImage,
+ "wrong pc %p ntdll %p-%p\n", (void *)ctx.Pc, ntdll,
+ (char *)ntdll + nt->OptionalHeader.SizeOfImage );
+ }
+ else
{
#if 0 /* RtlRaiseException test disabled for now */
if (stage == 1)
More information about the wine-cvs
mailing list