From: Eric Pouech <eric.pouech(a)gmail.com> Signed-off-by: Eric Pouech <eric.pouech(a)gmail.com> --- dlls/kernel32/tests/debugger.c | 28 ++++++++++++++++++++-------- include/wine/test.h | 17 +++++++++++++++++ 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/dlls/kernel32/tests/debugger.c b/dlls/kernel32/tests/debugger.c index 513db658222..a69d46e7c64 100644 --- a/dlls/kernel32/tests/debugger.c +++ b/dlls/kernel32/tests/debugger.c @@ -38,7 +38,7 @@ static int myARGC; static char** myARGV; -static BOOL is_wow64; +static BOOL is_wow64; static BOOL (WINAPI *pCheckRemoteDebuggerPresent)(HANDLE,PBOOL); @@ -860,12 +860,13 @@ static void test_RemoteDebugger(void) struct child_blackbox { + DWORD64 main_teb; LONG failures; }; static void doChild(int argc, char **argv) { - struct child_blackbox blackbox; + struct child_blackbox blackbox = {(ULONG_PTR)NtCurrentTeb(), 0}; const char *blackbox_file; WCHAR path[MAX_PATH]; HMODULE mod; @@ -960,13 +961,15 @@ done: static HMODULE ole32_mod, oleaut32_mod, oleacc_mod; -static void check_dll_event( HANDLE process, DEBUG_EVENT *ev ) +static void* check_dll_event( HANDLE process, DEBUG_EVENT *ev ) { WCHAR *p, module[MAX_PATH]; + void* ret = NULL; switch (ev->dwDebugEventCode) { case CREATE_PROCESS_DEBUG_EVENT: + ret = ev->u.CreateProcessInfo.lpThreadLocalBase; break; case LOAD_DLL_DEBUG_EVENT: if (!pGetMappedFileNameW( process, ev->u.LoadDll.lpBaseOfDll, module, MAX_PATH )) module[0] = 0; @@ -982,9 +985,10 @@ static void check_dll_event( HANDLE process, DEBUG_EVENT *ev ) if (ev->u.UnloadDll.lpBaseOfDll == oleacc_mod) oleacc_mod = (HMODULE)1; break; } + return ret; } -static void test_debug_loop(int argc, char **argv) +static void test_debug_loop(int argc, char **argv, const char *argv0) { const char *arguments = " debugger child "; struct child_blackbox blackbox; @@ -995,6 +999,7 @@ static void test_debug_loop(int argc, char **argv) DWORD pid; char *cmd; BOOL ret; + void* main_teb = NULL; if (!pCheckRemoteDebuggerPresent) { @@ -1007,8 +1012,8 @@ static void test_debug_loop(int argc, char **argv) ok(!ret, "DebugActiveProcess() succeeded on own process.\n"); get_file_name(blackbox_file); - cmd = HeapAlloc(GetProcessHeap(), 0, strlen(argv[0]) + strlen(arguments) + strlen(blackbox_file) + 2 + 10); - sprintf(cmd, "%s%s%08lx \"%s\"", argv[0], arguments, pid, blackbox_file); + cmd = HeapAlloc(GetProcessHeap(), 0, strlen(argv0) + strlen(arguments) + strlen(blackbox_file) + 2 + 10); + sprintf(cmd, "%s%s%08lx \"%s\"", argv0, arguments, pid, blackbox_file); memset(&si, 0, sizeof(si)); si.cb = sizeof(si); @@ -1024,13 +1029,15 @@ static void test_debug_loop(int argc, char **argv) for (;;) { DEBUG_EVENT ev; + void* teb; ret = WaitForDebugEvent(&ev, INFINITE); ok(ret, "WaitForDebugEvent failed, last error %#lx.\n", GetLastError()); if (!ret) break; if (ev.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT) break; - check_dll_event( pi.hProcess, &ev ); + teb = check_dll_event( pi.hProcess, &ev ); + if (!main_teb && teb) main_teb = teb; #if defined(__i386__) || defined(__x86_64__) if (ev.dwDebugEventCode == EXCEPTION_DEBUG_EVENT && ev.u.Exception.ExceptionRecord.ExceptionCode == EXCEPTION_BREAKPOINT) @@ -1062,6 +1069,10 @@ static void test_debug_loop(int argc, char **argv) load_blackbox(blackbox_file, &blackbox, sizeof(blackbox)); ok(!blackbox.failures, "Got %ld failures from child process.\n", blackbox.failures); + if (argv0 == winetest_wow64_alt) + ok(main_teb && (ULONG_PTR)main_teb + 0x2000 == blackbox.main_teb, "Got wrong teb %p instead of %I64x)\n", main_teb, blackbox.main_teb); + else + ok(main_teb && (ULONG_PTR)main_teb == blackbox.main_teb, "Got wrong teb %p instead of %I64x)\n", main_teb, blackbox.main_teb); ret = DeleteFileA(blackbox_file); ok(ret, "DeleteFileA failed, last error %#lx.\n", GetLastError()); } @@ -2251,7 +2262,8 @@ START_TEST(debugger) { test_ExitCode(); test_RemoteDebugger(); - test_debug_loop(myARGC, myARGV); + test_debug_loop(myARGC, myARGV, myARGV[0]); + if (winetest_wow64_alt) test_debug_loop(myARGC, myARGV, winetest_wow64_alt); test_debug_children(myARGV[0], DEBUG_PROCESS, TRUE, FALSE); test_debug_children(myARGV[0], DEBUG_ONLY_THIS_PROCESS, FALSE, FALSE); test_debug_children(myARGV[0], DEBUG_PROCESS|DEBUG_ONLY_THIS_PROCESS, FALSE, FALSE); diff --git a/include/wine/test.h b/include/wine/test.h index c28128d9f0c..47ba34eb9c1 100644 --- a/include/wine/test.h +++ b/include/wine/test.h @@ -56,6 +56,9 @@ extern int winetest_mute_threshold; /* current platform */ extern const char *winetest_platform; +/* alternate (32bit) test instance */ +extern const char *winetest_wow64_alt; + extern void winetest_set_location( const char* file, int line ); extern void winetest_subtest( const char* name ); extern void winetest_ignore_exceptions( BOOL ignore ); @@ -225,6 +228,9 @@ static HANDLE winetest_mutex; static int winetest_argc; static char** winetest_argv; +/* alternate (32bit) test instance */ +const char *winetest_wow64_alt; + static const struct test *current_test; /* test currently being run */ static LONG successes; /* number of successful tests */ @@ -783,6 +789,7 @@ int main( int argc, char **argv ) { char p[128]; + DWORD sz; setvbuf (stdout, NULL, _IONBF, 0); winetest_mutex = CreateMutexA(NULL, FALSE, "winetest_print_mutex"); @@ -814,6 +821,16 @@ int main( int argc, char **argv ) if (GetEnvironmentVariableA( "WINETEST_REPORT_FLAKY", p, sizeof(p) )) winetest_report_flaky = atoi(p); if (GetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", p, sizeof(p) )) winetest_report_success = atoi(p); if (GetEnvironmentVariableA( "WINETEST_TIME", p, sizeof(p) )) winetest_time = atoi(p); + if (sizeof(void*) == 8 && (sz = GetEnvironmentVariableA( "WINETEST_WOW64_ALT", p, sizeof(p)))) + { + char *ptr; + if (sz < sizeof(p)) winetest_wow64_alt = strdup(p); + else if ((ptr = malloc(sz)) && GetEnvironmentVariableA( "WINETEST_WOW64_ALT", ptr, sz)) + winetest_wow64_alt = ptr; + else + free(ptr); + } + winetest_last_time = winetest_start_time = GetTickCount(); if (!strcmp( winetest_platform, "windows" )) SetUnhandledExceptionFilter( exc_filter ); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/2002