static void doChild(int argc, char **argv) { struct child_blackbox blackbox; const char *blackbox_file; HANDLE parent; DWORD ppid; BOOL debug; 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()); ret = pCheckRemoteDebuggerPresent(parent, &debug); child_ok(ret, "CheckRemoteDebuggerPresent failed, last error %#x.\n", GetLastError()); child_ok(!debug, "Expected debug == 0, got %#x.\n", debug); ret = DebugActiveProcess(ppid); child_ok(ret, "DebugActiveProcess failed, last error %#x.\n", GetLastError()); ret = pCheckRemoteDebuggerPresent(parent, &debug); child_ok(ret, "CheckRemoteDebuggerPresent failed, last error %#x.\n", GetLastError()); child_ok(debug, "Expected debug != 0, got %#x.\n", debug); ret = pDebugActiveProcessStop(ppid); child_ok(ret, "DebugActiveProcessStop failed, last error %#x.\n", GetLastError()); ret = pCheckRemoteDebuggerPresent(parent, &debug); child_ok(ret, "CheckRemoteDebuggerPresent failed, last error %#x.\n", GetLastError()); child_ok(!debug, "Expected debug == 0, got %#x.\n", debug); ret = CloseHandle(parent); child_ok(ret, "CloseHandle failed, last error %#x.\n", GetLastError()); 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) { pNtCurrentTeb()->Peb->BeingDebugged = FALSE; 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); pNtCurrentTeb()->Peb->BeingDebugged = TRUE; } blackbox.failures = child_failures; save_blackbox(blackbox_file, &blackbox, sizeof(blackbox)); }
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"); event = OpenEventA(EVENT_ALL_ACCESS, FALSE, event_name); 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"); event = OpenEventA(EVENT_ALL_ACCESS, FALSE, event_name); 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)); HeapFree(GetProcessHeap(), 0, cmd); }
static void doCrash(int argc, char** argv) { char* p; 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; }
static void doCrash(int argc, char** argv) { char* p; /* make sure the exception gets to the debugger */ SetErrorMode( 0 ); SetUnhandledExceptionFilter( NULL ); 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; }
static void doDebugger(int argc, char** argv) { const char* logfile; debugger_blackbox_t blackbox; HANDLE start_event, done_event, debug_event; blackbox.argc=argc; logfile=(argc >= 4 ? argv[3] : NULL); blackbox.pid=(argc >= 5 ? atol(argv[4]) : 0); if (strstr(myARGV[2], "attach")) { blackbox.attach_rc=DebugActiveProcess(blackbox.pid); if (!blackbox.attach_rc) blackbox.attach_err=GetLastError(); } else blackbox.attach_rc=TRUE; debug_event=(argc >= 6 ? (HANDLE)atol(argv[5]) : NULL); 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; get_events(logfile, &start_event, &done_event); if (strstr(myARGV[2], "order")) { trace("debugger: waiting for the start signal...\n"); WaitForSingleObject(start_event, INFINITE); } if (strstr(myARGV[2], "nokill")) { blackbox.nokill_rc=pDebugSetProcessKillOnExit(FALSE); if (!blackbox.nokill_rc) blackbox.nokill_err=GetLastError(); } else blackbox.nokill_rc=TRUE; if (strstr(myARGV[2], "detach")) { blackbox.detach_rc=pDebugActiveProcessStop(blackbox.pid); if (!blackbox.detach_rc) blackbox.detach_err=GetLastError(); } else blackbox.detach_rc=TRUE; save_blackbox(logfile, &blackbox, sizeof(blackbox)); trace("debugger: done debugging...\n"); SetEvent(done_event); /* Just exit with a known value */ ExitProcess(0xdeadbeef); }