2008-05-09 17:35:45 +00:00
|
|
|
/*
|
|
|
|
* Unit tests for the debugger facility
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007 Francois Gouget for CodeWeavers
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
2008-12-23 20:02:47 +00:00
|
|
|
|
2008-05-09 17:35:45 +00:00
|
|
|
#include <windows.h>
|
2015-03-14 14:02:06 +00:00
|
|
|
#include <wine/winternl.h>
|
2008-05-09 17:35:45 +00:00
|
|
|
#include <winreg.h>
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
|
|
|
#ifndef STATUS_DEBUGGER_INACTIVE
|
|
|
|
#define STATUS_DEBUGGER_INACTIVE ((NTSTATUS) 0xC0000354)
|
|
|
|
#endif
|
|
|
|
|
2010-03-06 13:36:22 +00:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#define PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
|
|
|
|
#else
|
|
|
|
#define PRINTF_ATTR(fmt,args)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define child_ok (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : test_child_ok
|
|
|
|
|
2008-05-09 17:35:45 +00:00
|
|
|
static int myARGC;
|
|
|
|
static char** myARGV;
|
|
|
|
|
2009-10-25 16:21:40 +00:00
|
|
|
static BOOL (WINAPI *pCheckRemoteDebuggerPresent)(HANDLE,PBOOL);
|
2008-05-09 17:35:45 +00:00
|
|
|
static BOOL (WINAPI *pDebugActiveProcessStop)(DWORD);
|
|
|
|
static BOOL (WINAPI *pDebugSetProcessKillOnExit)(BOOL);
|
2010-04-22 08:47:47 +00:00
|
|
|
static BOOL (WINAPI *pIsDebuggerPresent)(void);
|
|
|
|
static struct _TEB * (WINAPI *pNtCurrentTeb)(void);
|
2008-05-09 17:35:45 +00:00
|
|
|
|
2010-03-06 13:36:22 +00:00
|
|
|
static LONG child_failures;
|
|
|
|
|
|
|
|
static void PRINTF_ATTR(2, 3) test_child_ok(int condition, const char *msg, ...)
|
|
|
|
{
|
|
|
|
va_list valist;
|
|
|
|
|
|
|
|
va_start(valist, msg);
|
|
|
|
winetest_vok(condition, msg, valist);
|
|
|
|
va_end(valist);
|
|
|
|
if (!condition) ++child_failures;
|
|
|
|
}
|
|
|
|
|
2008-05-09 17:35:45 +00:00
|
|
|
/* Copied from the process test */
|
|
|
|
static void get_file_name(char* buf)
|
|
|
|
{
|
|
|
|
char path[MAX_PATH];
|
|
|
|
|
|
|
|
buf[0] = '\0';
|
|
|
|
GetTempPathA(sizeof(path), path);
|
|
|
|
GetTempFileNameA(path, "wt", 0, buf);
|
|
|
|
}
|
|
|
|
|
2009-05-17 07:05:22 +00:00
|
|
|
typedef struct tag_reg_save_value
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
DWORD type;
|
|
|
|
BYTE *data;
|
|
|
|
DWORD size;
|
|
|
|
} reg_save_value;
|
|
|
|
|
|
|
|
static DWORD save_value(HKEY hkey, const char *value, reg_save_value *saved)
|
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
saved->name=value;
|
|
|
|
saved->data=0;
|
|
|
|
saved->size=0;
|
|
|
|
ret=RegQueryValueExA(hkey, value, NULL, &saved->type, NULL, &saved->size);
|
|
|
|
if (ret == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
saved->data=HeapAlloc(GetProcessHeap(), 0, saved->size);
|
|
|
|
RegQueryValueExA(hkey, value, NULL, &saved->type, saved->data, &saved->size);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void restore_value(HKEY hkey, reg_save_value *saved)
|
|
|
|
{
|
|
|
|
if (saved->data)
|
|
|
|
{
|
|
|
|
RegSetValueExA(hkey, saved->name, 0, saved->type, saved->data, saved->size);
|
|
|
|
HeapFree(GetProcessHeap(), 0, saved->data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
RegDeleteValueA(hkey, saved->name);
|
|
|
|
}
|
|
|
|
|
2008-05-09 17:35:45 +00:00
|
|
|
static void get_events(const char* name, HANDLE *start_event, HANDLE *done_event)
|
|
|
|
{
|
|
|
|
const char* basename;
|
|
|
|
char* event_name;
|
|
|
|
|
|
|
|
basename=strrchr(name, '\\');
|
|
|
|
basename=(basename ? basename+1 : name);
|
|
|
|
event_name=HeapAlloc(GetProcessHeap(), 0, 6+strlen(basename)+1);
|
|
|
|
|
|
|
|
sprintf(event_name, "start_%s", basename);
|
2014-04-18 22:50:27 +00:00
|
|
|
*start_event=CreateEventA(NULL, 0,0, event_name);
|
2008-05-09 17:35:45 +00:00
|
|
|
sprintf(event_name, "done_%s", basename);
|
2014-04-18 22:50:27 +00:00
|
|
|
*done_event=CreateEventA(NULL, 0,0, event_name);
|
2008-05-09 17:35:45 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, event_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void save_blackbox(const char* logfile, void* blackbox, int size)
|
|
|
|
{
|
|
|
|
HANDLE hFile;
|
|
|
|
DWORD written;
|
|
|
|
|
|
|
|
hFile=CreateFileA(logfile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
|
|
|
return;
|
|
|
|
WriteFile(hFile, blackbox, size, &written, NULL);
|
|
|
|
CloseHandle(hFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int load_blackbox(const char* logfile, void* blackbox, int size)
|
|
|
|
{
|
|
|
|
HANDLE hFile;
|
|
|
|
DWORD read;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
hFile=CreateFileA(logfile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
ok(0, "unable to open '%s'\n", logfile);
|
|
|
|
return 0;
|
|
|
|
}
|
Sync advapi32, comctl32, crypt32, cryptui, cryptnet, fusion, gdi32, gdiplus, hlink, imm32, jscript, kernel32, localspl, msacm32, mscms, msi, mstask, msvcrtd, msxml3, ntdll, ole32, pdh, psapi, quartz, rasapi32, riched20 AND rsaenh Winetests.
TBD mshtml, shell32, oleaut32 which still fail to build here
svn path=/trunk/; revision=47931
2010-07-03 12:45:23 +00:00
|
|
|
SetLastError(0xdeadbeef);
|
2008-05-09 17:35:45 +00:00
|
|
|
ret=ReadFile(hFile, blackbox, size, &read, NULL);
|
Sync advapi32, comctl32, crypt32, cryptui, cryptnet, fusion, gdi32, gdiplus, hlink, imm32, jscript, kernel32, localspl, msacm32, mscms, msi, mstask, msvcrtd, msxml3, ntdll, ole32, pdh, psapi, quartz, rasapi32, riched20 AND rsaenh Winetests.
TBD mshtml, shell32, oleaut32 which still fail to build here
svn path=/trunk/; revision=47931
2010-07-03 12:45:23 +00:00
|
|
|
ok(ret, "ReadFile failed: %d\n", GetLastError());
|
2008-05-09 17:35:45 +00:00
|
|
|
ok(read == size, "wrong size for '%s': read=%d\n", logfile, read);
|
|
|
|
CloseHandle(hFile);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
DWORD pid;
|
|
|
|
} crash_blackbox_t;
|
|
|
|
|
|
|
|
static void doCrash(int argc, char** argv)
|
|
|
|
{
|
2015-11-23 16:10:53 +00:00
|
|
|
volatile char* p;
|
2008-05-09 17:35:45 +00:00
|
|
|
|
2011-10-03 17:58:01 +00:00
|
|
|
/* make sure the exception gets to the debugger */
|
|
|
|
SetErrorMode( 0 );
|
|
|
|
SetUnhandledExceptionFilter( NULL );
|
|
|
|
|
2008-05-09 17:35:45 +00:00
|
|
|
if (argc >= 4)
|
|
|
|
{
|
|
|
|
crash_blackbox_t blackbox;
|
|
|
|
blackbox.pid=GetCurrentProcessId();
|
|
|
|
save_blackbox(argv[3], &blackbox, sizeof(blackbox));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Just crash */
|
|
|
|
trace("child: crashing...\n");
|
|
|
|
p=NULL;
|
|
|
|
*p=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int argc;
|
|
|
|
DWORD pid;
|
|
|
|
BOOL debug_rc;
|
|
|
|
DWORD debug_err;
|
|
|
|
BOOL attach_rc;
|
|
|
|
DWORD attach_err;
|
|
|
|
BOOL nokill_rc;
|
|
|
|
DWORD nokill_err;
|
|
|
|
BOOL detach_rc;
|
|
|
|
DWORD detach_err;
|
|
|
|
} debugger_blackbox_t;
|
|
|
|
|
|
|
|
static void doDebugger(int argc, char** argv)
|
|
|
|
{
|
|
|
|
const char* logfile;
|
|
|
|
debugger_blackbox_t blackbox;
|
2009-05-17 07:05:22 +00:00
|
|
|
HANDLE start_event = 0, done_event = 0, debug_event;
|
2008-05-09 17:35:45 +00:00
|
|
|
|
|
|
|
blackbox.argc=argc;
|
|
|
|
logfile=(argc >= 4 ? argv[3] : NULL);
|
|
|
|
blackbox.pid=(argc >= 5 ? atol(argv[4]) : 0);
|
|
|
|
|
2008-12-23 20:02:47 +00:00
|
|
|
blackbox.attach_err=0;
|
2008-05-09 17:35:45 +00:00
|
|
|
if (strstr(myARGV[2], "attach"))
|
|
|
|
{
|
|
|
|
blackbox.attach_rc=DebugActiveProcess(blackbox.pid);
|
|
|
|
if (!blackbox.attach_rc)
|
|
|
|
blackbox.attach_err=GetLastError();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
blackbox.attach_rc=TRUE;
|
|
|
|
|
2009-05-17 07:05:22 +00:00
|
|
|
debug_event=(argc >= 6 ? (HANDLE)(INT_PTR)atol(argv[5]) : NULL);
|
2008-12-23 20:02:47 +00:00
|
|
|
blackbox.debug_err=0;
|
2008-05-09 17:35:45 +00:00
|
|
|
if (debug_event && strstr(myARGV[2], "event"))
|
|
|
|
{
|
|
|
|
blackbox.debug_rc=SetEvent(debug_event);
|
|
|
|
if (!blackbox.debug_rc)
|
|
|
|
blackbox.debug_err=GetLastError();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
blackbox.debug_rc=TRUE;
|
|
|
|
|
2008-12-23 20:02:47 +00:00
|
|
|
if (logfile)
|
|
|
|
{
|
|
|
|
get_events(logfile, &start_event, &done_event);
|
|
|
|
}
|
|
|
|
|
2008-05-09 17:35:45 +00:00
|
|
|
if (strstr(myARGV[2], "order"))
|
|
|
|
{
|
|
|
|
trace("debugger: waiting for the start signal...\n");
|
|
|
|
WaitForSingleObject(start_event, INFINITE);
|
|
|
|
}
|
|
|
|
|
2008-12-23 20:02:47 +00:00
|
|
|
blackbox.nokill_err=0;
|
2008-05-09 17:35:45 +00:00
|
|
|
if (strstr(myARGV[2], "nokill"))
|
|
|
|
{
|
|
|
|
blackbox.nokill_rc=pDebugSetProcessKillOnExit(FALSE);
|
|
|
|
if (!blackbox.nokill_rc)
|
|
|
|
blackbox.nokill_err=GetLastError();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
blackbox.nokill_rc=TRUE;
|
|
|
|
|
2008-12-23 20:02:47 +00:00
|
|
|
blackbox.detach_err=0;
|
2008-05-09 17:35:45 +00:00
|
|
|
if (strstr(myARGV[2], "detach"))
|
|
|
|
{
|
|
|
|
blackbox.detach_rc=pDebugActiveProcessStop(blackbox.pid);
|
|
|
|
if (!blackbox.detach_rc)
|
|
|
|
blackbox.detach_err=GetLastError();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
blackbox.detach_rc=TRUE;
|
|
|
|
|
2008-12-23 20:02:47 +00:00
|
|
|
if (logfile)
|
|
|
|
{
|
|
|
|
save_blackbox(logfile, &blackbox, sizeof(blackbox));
|
|
|
|
}
|
2008-05-09 17:35:45 +00:00
|
|
|
trace("debugger: done debugging...\n");
|
|
|
|
SetEvent(done_event);
|
|
|
|
|
|
|
|
/* Just exit with a known value */
|
|
|
|
ExitProcess(0xdeadbeef);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void crash_and_debug(HKEY hkey, const char* argv0, const char* dbgtasks)
|
|
|
|
{
|
2011-10-03 17:58:01 +00:00
|
|
|
static BOOL skip_crash_and_debug = FALSE;
|
|
|
|
BOOL bRet;
|
2008-05-09 17:35:45 +00:00
|
|
|
DWORD ret;
|
|
|
|
HANDLE start_event, done_event;
|
|
|
|
char* cmd;
|
|
|
|
char dbglog[MAX_PATH];
|
|
|
|
char childlog[MAX_PATH];
|
|
|
|
PROCESS_INFORMATION info;
|
|
|
|
STARTUPINFOA startup;
|
|
|
|
DWORD exit_code;
|
|
|
|
crash_blackbox_t crash_blackbox;
|
|
|
|
debugger_blackbox_t dbg_blackbox;
|
2011-10-03 17:58:01 +00:00
|
|
|
DWORD wait_code;
|
|
|
|
|
|
|
|
if (skip_crash_and_debug)
|
|
|
|
{
|
|
|
|
win_skip("Skipping crash_and_debug\n");
|
|
|
|
return;
|
|
|
|
}
|
2008-05-09 17:35:45 +00:00
|
|
|
|
|
|
|
ret=RegSetValueExA(hkey, "auto", 0, REG_SZ, (BYTE*)"1", 2);
|
2012-12-09 20:39:13 +00:00
|
|
|
if (ret == ERROR_ACCESS_DENIED)
|
|
|
|
{
|
|
|
|
skip_crash_and_debug = TRUE;
|
|
|
|
skip("No write access to change the debugger\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-09 17:35:45 +00:00
|
|
|
ok(ret == ERROR_SUCCESS, "unable to set AeDebug/auto: ret=%d\n", ret);
|
|
|
|
|
|
|
|
get_file_name(dbglog);
|
|
|
|
get_events(dbglog, &start_event, &done_event);
|
2011-10-03 17:58:01 +00:00
|
|
|
cmd=HeapAlloc(GetProcessHeap(), 0, strlen(argv0)+10+strlen(dbgtasks)+1+strlen(dbglog)+2+34+1);
|
|
|
|
sprintf(cmd, "%s debugger %s \"%s\" %%ld %%ld", argv0, dbgtasks, dbglog);
|
2008-05-09 17:35:45 +00:00
|
|
|
ret=RegSetValueExA(hkey, "debugger", 0, REG_SZ, (BYTE*)cmd, strlen(cmd)+1);
|
|
|
|
ok(ret == ERROR_SUCCESS, "unable to set AeDebug/debugger: ret=%d\n", ret);
|
|
|
|
HeapFree(GetProcessHeap(), 0, cmd);
|
|
|
|
|
|
|
|
get_file_name(childlog);
|
2011-10-03 17:58:01 +00:00
|
|
|
cmd=HeapAlloc(GetProcessHeap(), 0, strlen(argv0)+16+strlen(dbglog)+2+1);
|
|
|
|
sprintf(cmd, "%s debugger crash \"%s\"", argv0, childlog);
|
2008-05-09 17:35:45 +00:00
|
|
|
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
ret=CreateProcessA(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info);
|
|
|
|
ok(ret, "CreateProcess: err=%d\n", GetLastError());
|
|
|
|
HeapFree(GetProcessHeap(), 0, cmd);
|
|
|
|
CloseHandle(info.hThread);
|
|
|
|
|
|
|
|
/* The process exits... */
|
|
|
|
trace("waiting for child exit...\n");
|
2011-10-03 17:58:01 +00:00
|
|
|
wait_code = WaitForSingleObject(info.hProcess, 30000);
|
|
|
|
#if defined(_WIN64) && defined(__MINGW32__)
|
|
|
|
/* Mingw x64 doesn't output proper unwind info */
|
|
|
|
skip_crash_and_debug = broken(wait_code == WAIT_TIMEOUT);
|
|
|
|
if (skip_crash_and_debug)
|
|
|
|
{
|
|
|
|
TerminateProcess(info.hProcess, WAIT_TIMEOUT);
|
|
|
|
WaitForSingleObject(info.hProcess, 5000);
|
|
|
|
CloseHandle(info.hProcess);
|
|
|
|
assert(DeleteFileA(dbglog) != 0);
|
|
|
|
assert(DeleteFileA(childlog) != 0);
|
|
|
|
win_skip("Giving up on child process\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
ok(wait_code == WAIT_OBJECT_0, "Timed out waiting for the child to crash\n");
|
|
|
|
bRet = GetExitCodeProcess(info.hProcess, &exit_code);
|
|
|
|
ok(bRet, "GetExitCodeProcess failed: err=%d\n", GetLastError());
|
2008-05-09 17:35:45 +00:00
|
|
|
if (strstr(dbgtasks, "code2"))
|
|
|
|
{
|
|
|
|
/* If, after attaching to the debuggee, the debugger exits without
|
|
|
|
* detaching, then the debuggee gets a special exit code.
|
|
|
|
*/
|
2009-06-06 16:10:47 +00:00
|
|
|
ok(exit_code == STATUS_DEBUGGER_INACTIVE ||
|
2009-10-25 16:21:40 +00:00
|
|
|
broken(exit_code == STATUS_ACCESS_VIOLATION) || /* Intermittent Vista+ */
|
2009-06-06 16:10:47 +00:00
|
|
|
broken(exit_code == WAIT_ABANDONED), /* NT4, W2K */
|
2008-05-09 17:35:45 +00:00
|
|
|
"wrong exit code : %08x\n", exit_code);
|
|
|
|
}
|
|
|
|
else
|
2009-06-06 16:10:47 +00:00
|
|
|
ok(exit_code == STATUS_ACCESS_VIOLATION ||
|
2011-10-03 17:58:01 +00:00
|
|
|
broken(exit_code == WAIT_ABANDONED), /* NT4, W2K, W2K3 */
|
2009-06-06 16:10:47 +00:00
|
|
|
"wrong exit code : %08x\n", exit_code);
|
2008-05-09 17:35:45 +00:00
|
|
|
CloseHandle(info.hProcess);
|
|
|
|
|
|
|
|
/* ...before the debugger */
|
|
|
|
if (strstr(dbgtasks, "order"))
|
|
|
|
ok(SetEvent(start_event), "SetEvent(start_event) failed\n");
|
|
|
|
|
|
|
|
trace("waiting for the debugger...\n");
|
2011-10-03 17:58:01 +00:00
|
|
|
wait_code = WaitForSingleObject(done_event, 5000);
|
|
|
|
#if defined(_WIN64) && defined(__MINGW32__)
|
|
|
|
/* Mingw x64 doesn't output proper unwind info */
|
|
|
|
skip_crash_and_debug = broken(wait_code == WAIT_TIMEOUT);
|
|
|
|
if (skip_crash_and_debug)
|
|
|
|
{
|
|
|
|
assert(DeleteFileA(dbglog) != 0);
|
|
|
|
assert(DeleteFileA(childlog) != 0);
|
|
|
|
win_skip("Giving up on debugger\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
ok(wait_code == WAIT_OBJECT_0, "Timed out waiting for the debugger\n");
|
2008-05-09 17:35:45 +00:00
|
|
|
|
|
|
|
assert(load_blackbox(childlog, &crash_blackbox, sizeof(crash_blackbox)));
|
|
|
|
assert(load_blackbox(dbglog, &dbg_blackbox, sizeof(dbg_blackbox)));
|
|
|
|
|
|
|
|
ok(dbg_blackbox.argc == 6, "wrong debugger argument count: %d\n", dbg_blackbox.argc);
|
|
|
|
ok(dbg_blackbox.pid == crash_blackbox.pid, "the child and debugged pids don't match: %d != %d\n", crash_blackbox.pid, dbg_blackbox.pid);
|
|
|
|
ok(dbg_blackbox.debug_rc, "debugger: SetEvent(debug_event) failed err=%d\n", dbg_blackbox.debug_err);
|
|
|
|
ok(dbg_blackbox.attach_rc, "DebugActiveProcess(%d) failed err=%d\n", dbg_blackbox.pid, dbg_blackbox.attach_err);
|
|
|
|
ok(dbg_blackbox.nokill_rc, "DebugSetProcessKillOnExit(FALSE) failed err=%d\n", dbg_blackbox.nokill_err);
|
|
|
|
ok(dbg_blackbox.detach_rc, "DebugActiveProcessStop(%d) failed err=%d\n", dbg_blackbox.pid, dbg_blackbox.detach_err);
|
|
|
|
|
|
|
|
assert(DeleteFileA(dbglog) != 0);
|
|
|
|
assert(DeleteFileA(childlog) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void crash_and_winedbg(HKEY hkey, const char* argv0)
|
|
|
|
{
|
2011-10-03 17:58:01 +00:00
|
|
|
BOOL bRet;
|
2008-05-09 17:35:45 +00:00
|
|
|
DWORD ret;
|
|
|
|
char* cmd;
|
|
|
|
PROCESS_INFORMATION info;
|
|
|
|
STARTUPINFOA startup;
|
|
|
|
DWORD exit_code;
|
|
|
|
|
|
|
|
ret=RegSetValueExA(hkey, "auto", 0, REG_SZ, (BYTE*)"1", 2);
|
|
|
|
ok(ret == ERROR_SUCCESS, "unable to set AeDebug/auto: ret=%d\n", ret);
|
|
|
|
|
|
|
|
cmd=HeapAlloc(GetProcessHeap(), 0, strlen(argv0)+15+1);
|
|
|
|
sprintf(cmd, "%s debugger crash", argv0);
|
|
|
|
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
ret=CreateProcessA(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info);
|
|
|
|
ok(ret, "CreateProcess: err=%d\n", GetLastError());
|
|
|
|
HeapFree(GetProcessHeap(), 0, cmd);
|
|
|
|
CloseHandle(info.hThread);
|
|
|
|
|
|
|
|
trace("waiting for child exit...\n");
|
|
|
|
ok(WaitForSingleObject(info.hProcess, 60000) == WAIT_OBJECT_0, "Timed out waiting for the child to crash\n");
|
2011-10-03 17:58:01 +00:00
|
|
|
bRet = GetExitCodeProcess(info.hProcess, &exit_code);
|
|
|
|
ok(bRet, "GetExitCodeProcess failed: err=%d\n", GetLastError());
|
2008-05-09 17:35:45 +00:00
|
|
|
ok(exit_code == STATUS_ACCESS_VIOLATION, "exit code = %08x\n", exit_code);
|
|
|
|
CloseHandle(info.hProcess);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_ExitCode(void)
|
|
|
|
{
|
|
|
|
static const char* AeDebug="Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug";
|
2009-05-17 07:05:22 +00:00
|
|
|
static const char* WineDbg="Software\\Wine\\WineDbg";
|
2008-05-09 17:35:45 +00:00
|
|
|
char test_exe[MAX_PATH];
|
|
|
|
DWORD ret;
|
|
|
|
HKEY hkey;
|
|
|
|
DWORD disposition;
|
2009-05-17 07:05:22 +00:00
|
|
|
reg_save_value auto_value;
|
|
|
|
reg_save_value debugger_value;
|
2008-05-09 17:35:45 +00:00
|
|
|
|
2014-04-18 22:50:27 +00:00
|
|
|
GetModuleFileNameA(GetModuleHandleA(NULL), test_exe, sizeof(test_exe));
|
|
|
|
if (GetFileAttributesA(test_exe) == INVALID_FILE_ATTRIBUTES)
|
2008-05-09 17:35:45 +00:00
|
|
|
strcat(test_exe, ".so");
|
|
|
|
if (GetFileAttributesA(test_exe) == INVALID_FILE_ATTRIBUTES)
|
|
|
|
{
|
|
|
|
ok(0, "could not find the test executable '%s'\n", test_exe);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret=RegCreateKeyExA(HKEY_LOCAL_MACHINE, AeDebug, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &disposition);
|
|
|
|
if (ret == ERROR_SUCCESS)
|
|
|
|
{
|
2009-05-17 07:05:22 +00:00
|
|
|
save_value(hkey, "auto", &auto_value);
|
|
|
|
save_value(hkey, "debugger", &debugger_value);
|
|
|
|
trace("HKLM\\%s\\debugger is set to '%s'\n", AeDebug, debugger_value.data);
|
2008-05-09 17:35:45 +00:00
|
|
|
}
|
|
|
|
else if (ret == ERROR_ACCESS_DENIED)
|
|
|
|
{
|
|
|
|
skip("not enough privileges to change the debugger\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (ret != ERROR_FILE_NOT_FOUND)
|
|
|
|
{
|
|
|
|
ok(0, "could not open the AeDebug key: %d\n", ret);
|
|
|
|
return;
|
|
|
|
}
|
2011-10-03 17:58:01 +00:00
|
|
|
else debugger_value.data = NULL;
|
2008-05-09 17:35:45 +00:00
|
|
|
|
2009-05-17 07:05:22 +00:00
|
|
|
if (debugger_value.data && debugger_value.type == REG_SZ &&
|
|
|
|
strstr((char*)debugger_value.data, "winedbg --auto"))
|
|
|
|
{
|
|
|
|
HKEY hkeyWinedbg;
|
|
|
|
ret=RegCreateKeyA(HKEY_CURRENT_USER, WineDbg, &hkeyWinedbg);
|
|
|
|
if (ret == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
static DWORD zero;
|
|
|
|
reg_save_value crash_dlg_value;
|
|
|
|
save_value(hkeyWinedbg, "ShowCrashDialog", &crash_dlg_value);
|
|
|
|
RegSetValueExA(hkeyWinedbg, "ShowCrashDialog", 0, REG_DWORD, (BYTE *)&zero, sizeof(DWORD));
|
|
|
|
crash_and_winedbg(hkey, test_exe);
|
|
|
|
restore_value(hkeyWinedbg, &crash_dlg_value);
|
|
|
|
RegCloseKey(hkeyWinedbg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ok(0, "Couldn't access WineDbg Key - error %u\n", ret);
|
|
|
|
}
|
2008-05-09 17:35:45 +00:00
|
|
|
|
2009-05-17 07:05:22 +00:00
|
|
|
if (winetest_interactive)
|
|
|
|
/* Since the debugging process never sets the debug event, it isn't recognized
|
|
|
|
as a valid debugger and, after the debugger exits, Windows will show a dialog box
|
|
|
|
asking the user what to do */
|
|
|
|
crash_and_debug(hkey, test_exe, "dbg,none");
|
|
|
|
else
|
|
|
|
skip("\"none\" debugger test needs user interaction\n");
|
2011-10-03 17:58:01 +00:00
|
|
|
ok(disposition == REG_OPENED_EXISTING_KEY, "expected REG_OPENED_EXISTING_KEY, got %d\n", disposition);
|
|
|
|
crash_and_debug(hkey, test_exe, "dbg,event,order");
|
2008-05-09 17:35:45 +00:00
|
|
|
crash_and_debug(hkey, test_exe, "dbg,attach,event,code2");
|
|
|
|
if (pDebugSetProcessKillOnExit)
|
|
|
|
crash_and_debug(hkey, test_exe, "dbg,attach,event,nokill");
|
2009-06-06 16:10:47 +00:00
|
|
|
else
|
|
|
|
win_skip("DebugSetProcessKillOnExit is not available\n");
|
2008-05-09 17:35:45 +00:00
|
|
|
if (pDebugActiveProcessStop)
|
|
|
|
crash_and_debug(hkey, test_exe, "dbg,attach,event,detach");
|
2009-06-06 16:10:47 +00:00
|
|
|
else
|
|
|
|
win_skip("DebugActiveProcessStop is not available\n");
|
2008-05-09 17:35:45 +00:00
|
|
|
|
|
|
|
if (disposition == REG_CREATED_NEW_KEY)
|
|
|
|
{
|
|
|
|
RegCloseKey(hkey);
|
|
|
|
RegDeleteKeyA(HKEY_LOCAL_MACHINE, AeDebug);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-05-17 07:05:22 +00:00
|
|
|
restore_value(hkey, &auto_value);
|
|
|
|
restore_value(hkey, &debugger_value);
|
2008-05-09 17:35:45 +00:00
|
|
|
RegCloseKey(hkey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-25 16:21:40 +00:00
|
|
|
static void test_RemoteDebugger(void)
|
|
|
|
{
|
|
|
|
BOOL bret, present;
|
|
|
|
if(!pCheckRemoteDebuggerPresent)
|
|
|
|
{
|
|
|
|
win_skip("CheckRemoteDebuggerPresent is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
present = TRUE;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
bret = pCheckRemoteDebuggerPresent(GetCurrentProcess(),&present);
|
|
|
|
ok(bret , "expected CheckRemoteDebuggerPresent to succeed\n");
|
|
|
|
ok(0xdeadbeef == GetLastError(),
|
|
|
|
"expected error to be unchanged, got %d/%x\n",GetLastError(), GetLastError());
|
|
|
|
|
|
|
|
present = TRUE;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
bret = pCheckRemoteDebuggerPresent(NULL,&present);
|
|
|
|
ok(!bret , "expected CheckRemoteDebuggerPresent to fail\n");
|
|
|
|
ok(present, "expected parameter to be unchanged\n");
|
|
|
|
ok(ERROR_INVALID_PARAMETER == GetLastError(),
|
|
|
|
"expected error ERROR_INVALID_PARAMETER, got %d/%x\n",GetLastError(), GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
bret = pCheckRemoteDebuggerPresent(GetCurrentProcess(),NULL);
|
|
|
|
ok(!bret , "expected CheckRemoteDebuggerPresent to fail\n");
|
|
|
|
ok(ERROR_INVALID_PARAMETER == GetLastError(),
|
|
|
|
"expected error ERROR_INVALID_PARAMETER, got %d/%x\n",GetLastError(), GetLastError());
|
|
|
|
}
|
|
|
|
|
2010-03-06 13:36:22 +00:00
|
|
|
struct child_blackbox
|
|
|
|
{
|
|
|
|
LONG failures;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void doChild(int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct child_blackbox blackbox;
|
|
|
|
const char *blackbox_file;
|
|
|
|
HANDLE parent;
|
|
|
|
DWORD ppid;
|
2010-04-22 08:47:47 +00:00
|
|
|
BOOL debug;
|
2010-03-06 13:36:22 +00:00
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
blackbox_file = argv[4];
|
|
|
|
sscanf(argv[3], "%08x", &ppid);
|
|
|
|
|
|
|
|
parent = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, ppid);
|
|
|
|
child_ok(!!parent, "OpenProcess failed, last error %#x.\n", GetLastError());
|
|
|
|
|
2010-04-22 08:47:47 +00:00
|
|
|
ret = pCheckRemoteDebuggerPresent(parent, &debug);
|
|
|
|
child_ok(ret, "CheckRemoteDebuggerPresent failed, last error %#x.\n", GetLastError());
|
|
|
|
child_ok(!debug, "Expected debug == 0, got %#x.\n", debug);
|
|
|
|
|
2010-03-06 13:36:22 +00:00
|
|
|
ret = DebugActiveProcess(ppid);
|
|
|
|
child_ok(ret, "DebugActiveProcess failed, last error %#x.\n", GetLastError());
|
|
|
|
|
2010-04-22 08:47:47 +00:00
|
|
|
ret = pCheckRemoteDebuggerPresent(parent, &debug);
|
|
|
|
child_ok(ret, "CheckRemoteDebuggerPresent failed, last error %#x.\n", GetLastError());
|
|
|
|
child_ok(debug, "Expected debug != 0, got %#x.\n", debug);
|
|
|
|
|
2010-03-06 13:36:22 +00:00
|
|
|
ret = pDebugActiveProcessStop(ppid);
|
|
|
|
child_ok(ret, "DebugActiveProcessStop failed, last error %#x.\n", GetLastError());
|
|
|
|
|
2010-04-22 08:47:47 +00:00
|
|
|
ret = pCheckRemoteDebuggerPresent(parent, &debug);
|
|
|
|
child_ok(ret, "CheckRemoteDebuggerPresent failed, last error %#x.\n", GetLastError());
|
|
|
|
child_ok(!debug, "Expected debug == 0, got %#x.\n", debug);
|
|
|
|
|
2010-03-06 13:36:22 +00:00
|
|
|
ret = CloseHandle(parent);
|
|
|
|
child_ok(ret, "CloseHandle failed, last error %#x.\n", GetLastError());
|
|
|
|
|
2010-04-22 08:47:47 +00:00
|
|
|
ret = pIsDebuggerPresent();
|
|
|
|
child_ok(ret, "Expected ret != 0, got %#x.\n", ret);
|
|
|
|
ret = pCheckRemoteDebuggerPresent(GetCurrentProcess(), &debug);
|
|
|
|
child_ok(ret, "CheckRemoteDebuggerPresent failed, last error %#x.\n", GetLastError());
|
|
|
|
child_ok(debug, "Expected debug != 0, got %#x.\n", debug);
|
|
|
|
|
|
|
|
if (pNtCurrentTeb)
|
|
|
|
{
|
Sync advapi32, gdi32, gdiplus, inetmib1, kernel32, mlang, msi, msvcrt, ntdll, oleaut32, rpcrt4, secur32, setupapi, shdocvw, shlwapi, snmpapi, twain_32, urlmon, user32, userenv, usp10, winhttp, wininet, wintrust, ws2_32 winetests to Wine 1.2rc6
svn path=/trunk/; revision=47939
2010-07-04 19:08:47 +00:00
|
|
|
pNtCurrentTeb()->Peb->BeingDebugged = FALSE;
|
2010-04-22 08:47:47 +00:00
|
|
|
|
|
|
|
ret = pIsDebuggerPresent();
|
|
|
|
child_ok(!ret, "Expected ret != 0, got %#x.\n", ret);
|
|
|
|
ret = pCheckRemoteDebuggerPresent(GetCurrentProcess(), &debug);
|
|
|
|
child_ok(ret, "CheckRemoteDebuggerPresent failed, last error %#x.\n", GetLastError());
|
|
|
|
child_ok(debug, "Expected debug != 0, got %#x.\n", debug);
|
|
|
|
|
Sync advapi32, gdi32, gdiplus, inetmib1, kernel32, mlang, msi, msvcrt, ntdll, oleaut32, rpcrt4, secur32, setupapi, shdocvw, shlwapi, snmpapi, twain_32, urlmon, user32, userenv, usp10, winhttp, wininet, wintrust, ws2_32 winetests to Wine 1.2rc6
svn path=/trunk/; revision=47939
2010-07-04 19:08:47 +00:00
|
|
|
pNtCurrentTeb()->Peb->BeingDebugged = TRUE;
|
2010-04-22 08:47:47 +00:00
|
|
|
}
|
|
|
|
|
2010-03-06 13:36:22 +00:00
|
|
|
blackbox.failures = child_failures;
|
|
|
|
save_blackbox(blackbox_file, &blackbox, sizeof(blackbox));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_debug_loop(int argc, char **argv)
|
|
|
|
{
|
|
|
|
const char *arguments = " debugger child ";
|
|
|
|
struct child_blackbox blackbox;
|
|
|
|
char blackbox_file[MAX_PATH];
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
STARTUPINFOA si;
|
2010-04-22 08:47:47 +00:00
|
|
|
BOOL debug;
|
2010-03-06 13:36:22 +00:00
|
|
|
DWORD pid;
|
|
|
|
char *cmd;
|
|
|
|
BOOL ret;
|
|
|
|
|
2010-04-22 08:47:47 +00:00
|
|
|
if (!pDebugActiveProcessStop || !pCheckRemoteDebuggerPresent)
|
2010-03-06 13:36:22 +00:00
|
|
|
{
|
2010-04-22 08:47:47 +00:00
|
|
|
win_skip("DebugActiveProcessStop or CheckRemoteDebuggerPresent not available, skipping test.\n");
|
2010-03-06 13:36:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pid = GetCurrentProcessId();
|
2010-04-22 08:47:47 +00:00
|
|
|
ret = DebugActiveProcess(pid);
|
|
|
|
ok(!ret, "DebugActiveProcess() succeeded on own process.\n");
|
|
|
|
|
2010-03-06 13:36:22 +00:00
|
|
|
get_file_name(blackbox_file);
|
2011-10-03 17:58:01 +00:00
|
|
|
cmd = HeapAlloc(GetProcessHeap(), 0, strlen(argv[0]) + strlen(arguments) + strlen(blackbox_file) + 2 + 10);
|
|
|
|
sprintf(cmd, "%s%s%08x \"%s\"", argv[0], arguments, pid, blackbox_file);
|
2010-03-06 13:36:22 +00:00
|
|
|
|
|
|
|
memset(&si, 0, sizeof(si));
|
|
|
|
si.cb = sizeof(si);
|
|
|
|
ret = CreateProcessA(NULL, cmd, NULL, NULL, FALSE, DEBUG_PROCESS, NULL, NULL, &si, &pi);
|
|
|
|
ok(ret, "CreateProcess failed, last error %#x.\n", GetLastError());
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, cmd);
|
|
|
|
|
2010-04-22 08:47:47 +00:00
|
|
|
ret = pCheckRemoteDebuggerPresent(pi.hProcess, &debug);
|
|
|
|
ok(ret, "CheckRemoteDebuggerPresent failed, last error %#x.\n", GetLastError());
|
|
|
|
ok(debug, "Expected debug != 0, got %#x.\n", debug);
|
|
|
|
|
2010-03-06 13:36:22 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
DEBUG_EVENT ev;
|
|
|
|
|
|
|
|
ret = WaitForDebugEvent(&ev, INFINITE);
|
|
|
|
ok(ret, "WaitForDebugEvent failed, last error %#x.\n", GetLastError());
|
|
|
|
if (!ret) break;
|
|
|
|
|
|
|
|
if (ev.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT) break;
|
|
|
|
|
|
|
|
ret = ContinueDebugEvent(ev.dwProcessId, ev.dwThreadId, DBG_CONTINUE);
|
|
|
|
ok(ret, "ContinueDebugEvent failed, last error %#x.\n", GetLastError());
|
|
|
|
if (!ret) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = CloseHandle(pi.hThread);
|
|
|
|
ok(ret, "CloseHandle failed, last error %#x.\n", GetLastError());
|
|
|
|
ret = CloseHandle(pi.hProcess);
|
|
|
|
ok(ret, "CloseHandle failed, last error %#x.\n", GetLastError());
|
|
|
|
|
|
|
|
load_blackbox(blackbox_file, &blackbox, sizeof(blackbox));
|
|
|
|
ok(!blackbox.failures, "Got %d failures from child process.\n", blackbox.failures);
|
|
|
|
|
|
|
|
ret = DeleteFileA(blackbox_file);
|
|
|
|
ok(ret, "DeleteFileA failed, last error %#x.\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
2013-09-11 11:32:57 +00:00
|
|
|
static void doChildren(int argc, char **argv)
|
|
|
|
{
|
|
|
|
const char *arguments = "debugger children last";
|
|
|
|
struct child_blackbox blackbox;
|
|
|
|
const char *blackbox_file, *p;
|
|
|
|
char event_name[MAX_PATH];
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
STARTUPINFOA si;
|
|
|
|
HANDLE event;
|
|
|
|
char *cmd;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (!strcmp(argv[3], "last")) return;
|
|
|
|
|
|
|
|
blackbox_file = argv[3];
|
|
|
|
|
|
|
|
p = strrchr(blackbox_file, '\\');
|
|
|
|
p = p ? p+1 : blackbox_file;
|
|
|
|
strcpy(event_name, p);
|
|
|
|
strcat(event_name, "_init");
|
2014-04-18 22:50:27 +00:00
|
|
|
event = OpenEventA(EVENT_ALL_ACCESS, FALSE, event_name);
|
2013-09-11 11:32:57 +00:00
|
|
|
child_ok(event != NULL, "OpenEvent failed, last error %d.\n", GetLastError());
|
|
|
|
SetEvent(event);
|
|
|
|
CloseHandle(event);
|
|
|
|
|
|
|
|
p = strrchr(blackbox_file, '\\');
|
|
|
|
p = p ? p+1 : blackbox_file;
|
|
|
|
strcpy(event_name, p);
|
|
|
|
strcat(event_name, "_attach");
|
2014-04-18 22:50:27 +00:00
|
|
|
event = OpenEventA(EVENT_ALL_ACCESS, FALSE, event_name);
|
2013-09-11 11:32:57 +00:00
|
|
|
child_ok(event != NULL, "OpenEvent failed, last error %d.\n", GetLastError());
|
|
|
|
WaitForSingleObject(event, INFINITE);
|
|
|
|
CloseHandle(event);
|
|
|
|
|
|
|
|
cmd = HeapAlloc(GetProcessHeap(), 0, strlen(argv[0]) + strlen(arguments) + 2);
|
|
|
|
sprintf(cmd, "%s %s", argv[0], arguments);
|
|
|
|
|
|
|
|
memset(&si, 0, sizeof(si));
|
|
|
|
si.cb = sizeof(si);
|
|
|
|
ret = CreateProcessA(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
|
|
|
|
child_ok(ret, "CreateProcess failed, last error %d.\n", GetLastError());
|
|
|
|
|
|
|
|
child_ok(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0,
|
|
|
|
"Timed out waiting for the child to exit\n");
|
|
|
|
|
|
|
|
ret = CloseHandle(pi.hThread);
|
|
|
|
child_ok(ret, "CloseHandle failed, last error %d.\n", GetLastError());
|
|
|
|
ret = CloseHandle(pi.hProcess);
|
|
|
|
child_ok(ret, "CloseHandle failed, last error %d.\n", GetLastError());
|
|
|
|
|
|
|
|
blackbox.failures = child_failures;
|
|
|
|
save_blackbox(blackbox_file, &blackbox, sizeof(blackbox));
|
2014-09-20 19:35:24 +00:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, cmd);
|
2013-09-11 11:32:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_debug_children(char *name, DWORD flag, BOOL debug_child)
|
|
|
|
{
|
|
|
|
const char *arguments = "debugger children";
|
|
|
|
struct child_blackbox blackbox;
|
|
|
|
char blackbox_file[MAX_PATH], *p;
|
|
|
|
char event_name[MAX_PATH];
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
STARTUPINFOA si;
|
|
|
|
HANDLE event_init, event_attach;
|
|
|
|
char *cmd;
|
|
|
|
BOOL debug, ret;
|
|
|
|
BOOL got_child_event = FALSE;
|
|
|
|
|
|
|
|
if (!pDebugActiveProcessStop || !pCheckRemoteDebuggerPresent)
|
|
|
|
{
|
|
|
|
win_skip("DebugActiveProcessStop or CheckRemoteDebuggerPresent not available, skipping test.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_file_name(blackbox_file);
|
|
|
|
cmd = HeapAlloc(GetProcessHeap(), 0, strlen(name) + strlen(arguments) + strlen(blackbox_file) + 5);
|
|
|
|
sprintf(cmd, "%s %s \"%s\"", name, arguments, blackbox_file);
|
|
|
|
|
|
|
|
p = strrchr(blackbox_file, '\\');
|
|
|
|
p = p ? p+1 : blackbox_file;
|
|
|
|
strcpy(event_name, p);
|
|
|
|
strcat(event_name, "_init");
|
2014-04-18 22:50:27 +00:00
|
|
|
event_init = CreateEventA(NULL, FALSE, FALSE, event_name);
|
2013-09-11 11:32:57 +00:00
|
|
|
ok(event_init != NULL, "OpenEvent failed, last error %d.\n", GetLastError());
|
|
|
|
|
|
|
|
p = strrchr(blackbox_file, '\\');
|
|
|
|
p = p ? p+1 : blackbox_file;
|
|
|
|
strcpy(event_name, p);
|
|
|
|
strcat(event_name, "_attach");
|
2014-04-18 22:50:27 +00:00
|
|
|
event_attach = CreateEventA(NULL, FALSE, flag!=0, event_name);
|
2013-09-11 11:32:57 +00:00
|
|
|
ok(event_attach != NULL, "CreateEvent failed, last error %d.\n", GetLastError());
|
|
|
|
|
|
|
|
memset(&si, 0, sizeof(si));
|
|
|
|
si.cb = sizeof(si);
|
|
|
|
|
|
|
|
ret = CreateProcessA(NULL, cmd, NULL, NULL, FALSE, flag, NULL, NULL, &si, &pi);
|
|
|
|
ok(ret, "CreateProcess failed, last error %d.\n", GetLastError());
|
|
|
|
HeapFree(GetProcessHeap(), 0, cmd);
|
|
|
|
if (!flag)
|
|
|
|
{
|
|
|
|
WaitForSingleObject(event_init, INFINITE);
|
|
|
|
ret = DebugActiveProcess(pi.dwProcessId);
|
|
|
|
ok(ret, "DebugActiveProcess failed, last error %d.\n", GetLastError());
|
|
|
|
ret = SetEvent(event_attach);
|
|
|
|
ok(ret, "SetEvent failed, last error %d.\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = pCheckRemoteDebuggerPresent(pi.hProcess, &debug);
|
|
|
|
ok(ret, "CheckRemoteDebuggerPresent failed, last error %d.\n", GetLastError());
|
|
|
|
ok(debug, "Expected debug != 0, got %x.\n", debug);
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
DEBUG_EVENT ev;
|
|
|
|
|
|
|
|
ret = WaitForDebugEvent(&ev, INFINITE);
|
|
|
|
ok(ret, "WaitForDebugEvent failed, last error %d.\n", GetLastError());
|
|
|
|
if (!ret) break;
|
|
|
|
|
|
|
|
if (ev.dwDebugEventCode==EXIT_PROCESS_DEBUG_EVENT && ev.dwProcessId==pi.dwProcessId) break;
|
|
|
|
else if (ev.dwProcessId != pi.dwProcessId) got_child_event = TRUE;
|
|
|
|
|
|
|
|
ret = ContinueDebugEvent(ev.dwProcessId, ev.dwThreadId, DBG_CONTINUE);
|
|
|
|
ok(ret, "ContinueDebugEvent failed, last error %d.\n", GetLastError());
|
|
|
|
if (!ret) break;
|
|
|
|
}
|
|
|
|
if(debug_child)
|
|
|
|
ok(got_child_event, "didn't get any child events (flag: %x).\n", flag);
|
|
|
|
else
|
|
|
|
ok(!got_child_event, "got child event (flag: %x).\n", flag);
|
|
|
|
CloseHandle(event_init);
|
|
|
|
CloseHandle(event_attach);
|
|
|
|
|
|
|
|
ret = CloseHandle(pi.hThread);
|
|
|
|
ok(ret, "CloseHandle failed, last error %d.\n", GetLastError());
|
|
|
|
ret = CloseHandle(pi.hProcess);
|
|
|
|
ok(ret, "CloseHandle failed, last error %d.\n", GetLastError());
|
|
|
|
|
|
|
|
load_blackbox(blackbox_file, &blackbox, sizeof(blackbox));
|
|
|
|
ok(!blackbox.failures, "Got %d failures from child process.\n", blackbox.failures);
|
|
|
|
|
|
|
|
ret = DeleteFileA(blackbox_file);
|
|
|
|
ok(ret, "DeleteFileA failed, last error %d.\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
2008-05-09 17:35:45 +00:00
|
|
|
START_TEST(debugger)
|
|
|
|
{
|
|
|
|
HMODULE hdll;
|
|
|
|
|
2014-04-18 22:50:27 +00:00
|
|
|
hdll=GetModuleHandleA("kernel32.dll");
|
2009-10-25 16:21:40 +00:00
|
|
|
pCheckRemoteDebuggerPresent=(void*)GetProcAddress(hdll, "CheckRemoteDebuggerPresent");
|
2008-05-09 17:35:45 +00:00
|
|
|
pDebugActiveProcessStop=(void*)GetProcAddress(hdll, "DebugActiveProcessStop");
|
|
|
|
pDebugSetProcessKillOnExit=(void*)GetProcAddress(hdll, "DebugSetProcessKillOnExit");
|
2010-04-22 08:47:47 +00:00
|
|
|
pIsDebuggerPresent=(void*)GetProcAddress(hdll, "IsDebuggerPresent");
|
2014-04-18 22:50:27 +00:00
|
|
|
hdll=GetModuleHandleA("ntdll.dll");
|
2010-04-22 08:47:47 +00:00
|
|
|
if (hdll) pNtCurrentTeb = (void*)GetProcAddress(hdll, "NtCurrentTeb");
|
2008-05-09 17:35:45 +00:00
|
|
|
|
|
|
|
myARGC=winetest_get_mainargs(&myARGV);
|
|
|
|
if (myARGC >= 3 && strcmp(myARGV[2], "crash") == 0)
|
|
|
|
{
|
|
|
|
doCrash(myARGC, myARGV);
|
|
|
|
}
|
|
|
|
else if (myARGC >= 3 && strncmp(myARGV[2], "dbg,", 4) == 0)
|
|
|
|
{
|
|
|
|
doDebugger(myARGC, myARGV);
|
|
|
|
}
|
2010-03-06 13:36:22 +00:00
|
|
|
else if (myARGC >= 5 && !strcmp(myARGV[2], "child"))
|
|
|
|
{
|
|
|
|
doChild(myARGC, myARGV);
|
|
|
|
}
|
2013-09-11 11:32:57 +00:00
|
|
|
else if (myARGC >= 4 && !strcmp(myARGV[2], "children"))
|
|
|
|
{
|
|
|
|
doChildren(myARGC, myARGV);
|
|
|
|
}
|
2008-05-09 17:35:45 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
test_ExitCode();
|
2009-10-25 16:21:40 +00:00
|
|
|
test_RemoteDebugger();
|
2010-03-06 13:36:22 +00:00
|
|
|
test_debug_loop(myARGC, myARGV);
|
2013-09-11 11:32:57 +00:00
|
|
|
test_debug_children(myARGV[0], DEBUG_PROCESS, TRUE);
|
|
|
|
test_debug_children(myARGV[0], DEBUG_ONLY_THIS_PROCESS, FALSE);
|
2014-04-18 22:50:27 +00:00
|
|
|
test_debug_children(myARGV[0], DEBUG_PROCESS|DEBUG_ONLY_THIS_PROCESS, FALSE);
|
2013-09-11 11:32:57 +00:00
|
|
|
test_debug_children(myARGV[0], 0, FALSE);
|
2008-05-09 17:35:45 +00:00
|
|
|
}
|
|
|
|
}
|