Commit 70f08bdf authored by Oswald Buddenhagen's avatar Oswald Buddenhagen
Browse files

inferior interruption improvements

- on windows, use the recommended way to interrupt a debugged process
- on unix, use SIGTRAP
- assorted minor improvements
parent 6e118e72
......@@ -29,65 +29,42 @@
#include "procinterrupt.h"
#if defined(Q_OS_WIN)
#include <windows.h>
using namespace Debugger::Internal;
typedef HANDLE (WINAPI *PtrCreateRemoteThread)(
HANDLE hProcess,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
SIZE_T dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress,
LPVOID lpParameter,
DWORD dwCreationFlags,
LPDWORD lpThreadId);
#if defined(Q_OS_WIN)
PtrCreateRemoteThread resolveCreateRemoteThread()
{
HINSTANCE hLib = LoadLibraryA("Kernel32");
return (PtrCreateRemoteThread)GetProcAddress(hLib, "CreateRemoteThread");
}
#define _WIN32_WINNT 0x0501 /* WinXP, needed for DebugBreakProcess() */
#include <windows.h>
bool Debugger::Internal::interruptProcess(int pID)
{
DWORD pid = pID;
if (!pid)
if (pID <= 0)
return false;
PtrCreateRemoteThread libFunc = resolveCreateRemoteThread();
if (libFunc) {
DWORD dwThreadId = 0;
HANDLE hproc = OpenProcess(PROCESS_ALL_ACCESS, false, pid);
HANDLE hthread = libFunc(hproc, NULL, 0, (LPTHREAD_START_ROUTINE)DebugBreak, 0, 0, &dwThreadId);
CloseHandle(hthread);
if (dwThreadId)
return true;
}
return false;
}
HANDLE hproc = OpenProcess(PROCESS_ALL_ACCESS, false, pID);
if (hproc == NULL)
return false;
#endif // defined(Q_OS_WIN)
bool ok = DebugBreakProcess(hproc) != 0;
CloseHandle(hproc);
return ok;
}
#if defined(Q_OS_LINUX) || defined(Q_OS_MAC)
#else // Q_OS_WIN
#include <sys/types.h>
#include <signal.h>
using namespace Debugger::Internal;
bool Debugger::Internal::interruptProcess(int pID)
{
int procId = pID;
if (procId != -1) {
if (kill(procId, SIGINT) == 0)
if (pID > 0) {
if (kill(pID, SIGTRAP) == 0)
return true;
}
return false;
}
#endif // defined(Q_OS_LINUX) || defined(Q_OS_MAC)
#endif // !Q_OS_WIN
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment