bool Debugger::isAvailable() { #if defined(_DEBUG) #if defined(POCO_OS_FAMILY_WINDOWS) #if defined(_WIN32_WCE) #if (_WIN32_WCE >= 0x600) BOOL isDebuggerPresent; if (CheckRemoteDebuggerPresent(GetCurrentProcess(), &isDebuggerPresent)) { return isDebuggerPresent ? true : false; } return false; #else return false; #endif #else return IsDebuggerPresent() ? true : false; #endif #elif defined(POCO_VXWORKS) return false; #elif defined(POCO_OS_FAMILY_UNIX) return std::getenv("POCO_ENABLE_DEBUGGER") ? true : false; #elif defined(POCO_OS_FAMILY_VMS) return true; #endif #else return false; #endif }
__declspec(dllexport) DWORD __cdecl PluginDebugCheck(int iWinVer) { BOOL bDebugged = false; CheckRemoteDebuggerPresent(GetCurrentProcess(),&bDebugged); if(bDebugged) return 1; else return 0; }
bool isWinProcessBeingDebugged(unsigned long pid) { HANDLE processHandle = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid); if (processHandle == NULL) return false; BOOL debugged = FALSE; CheckRemoteDebuggerPresent(processHandle, &debugged); CloseHandle(processHandle); return debugged != FALSE; }
/* This function is not used because it isn't realiable in some new environments */ int debug_checkremotedebuggerpresent() { BOOL isdebug = FALSE; CheckRemoteDebuggerPresent(GetCurrentProcess(), &isdebug); if (isdebug) { return 0; } else { return 1; } }
static bool isProcessBeingDebugged(HWND hwnd) { DWORD pid = 0; if (!GetWindowThreadProcessId(hwnd, &pid) || !pid) return false; const HANDLE processHandle = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid); if (!processHandle) return false; BOOL debugged = FALSE; CheckRemoteDebuggerPresent(processHandle, &debugged); CloseHandle(processHandle); return debugged != FALSE; }
LONG WINAPI vboxVDbgVectoredHandler(struct _EXCEPTION_POINTERS *pExceptionInfo) { PEXCEPTION_RECORD pExceptionRecord = pExceptionInfo->ExceptionRecord; PCONTEXT pContextRecord = pExceptionInfo->ContextRecord; switch (pExceptionRecord->ExceptionCode) { case EXCEPTION_BREAKPOINT: case EXCEPTION_ACCESS_VIOLATION: case EXCEPTION_STACK_OVERFLOW: case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: case EXCEPTION_FLT_DIVIDE_BY_ZERO: case EXCEPTION_FLT_INVALID_OPERATION: case EXCEPTION_INT_DIVIDE_BY_ZERO: case EXCEPTION_ILLEGAL_INSTRUCTION: if (g_VBoxVehFlags & VBOXVEH_F_BREAK) { BOOL fBreak = TRUE; #ifndef DEBUG_misha if (pExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT) { HANDLE hProcess = GetCurrentProcess(); BOOL fDebuggerPresent = FALSE; /* we do not want to generate breakpoint exceptions recursively, so do it only when running under debugger */ if (CheckRemoteDebuggerPresent(hProcess, &fDebuggerPresent)) fBreak = !!fDebuggerPresent; else fBreak = FALSE; /* <- the function has failed, don't break for sanity */ } #endif if (fBreak) { RT_BREAKPOINT(); } } if (g_VBoxVehFlags & VBOXVEH_F_DUMP) vboxMdMinidumpCreate(pExceptionInfo); if (g_VBoxVehFlags & VBOXVEH_F_EXIT) exit(1); break; default: break; } return EXCEPTION_CONTINUE_SEARCH; }
extern "C" __declspec (dllexport) inline BOOL IsDebuggerAttached() { BOOL remoteDebugger; CheckRemoteDebuggerPresent(GetCurrentProcess(), &remoteDebugger); return IsDebuggerPresent() || remoteDebugger; }
BOOL CheckRemoteDebuggerPresentAPI () { BOOL bIsDbgPresent = FALSE; CheckRemoteDebuggerPresent(GetCurrentProcess(), &bIsDbgPresent); return bIsDbgPresent; }