Commit 6e118e72 authored by Oswald Buddenhagen's avatar Oswald Buddenhagen
Browse files

process interruption improvements

rely on the inferior's pid being available. consequently, remove the
bizarre findChild stuff.
parent 445e409d
......@@ -620,23 +620,13 @@ void GdbEngine::interruptInferior()
return;
}
if (q->m_attachedPID > 0) {
if (!interruptProcess(q->m_attachedPID))
// qq->notifyInferiorStopped();
//else
debugMessage(QString("CANNOT INTERRUPT %1").arg(q->m_attachedPID));
if (q->m_attachedPID <= 0) {
debugMessage("TRYING TO INTERRUPT INFERIOR BEFORE PID WAS OBTAINED");
return;
}
#ifdef Q_OS_MAC
sendCommand("-exec-interrupt", GdbExecInterrupt);
//qq->notifyInferiorStopped();
#else
if (!interruptChildProcess(m_gdbProc.pid()))
// qq->notifyInferiorStopped();
//else
debugMessage(QString("CANNOT STOP INFERIOR"));
#endif
if (!interruptProcess(q->m_attachedPID))
debugMessage(QString("CANNOT INTERRUPT %1").arg(q->m_attachedPID));
}
void GdbEngine::maybeHandleInferiorPidChanged(const QString &pid0)
......
......@@ -32,7 +32,6 @@
#if defined(Q_OS_WIN)
#include <windows.h>
#include <Tlhelp32.h>
using namespace Debugger::Internal;
......@@ -51,28 +50,6 @@ PtrCreateRemoteThread resolveCreateRemoteThread()
return (PtrCreateRemoteThread)GetProcAddress(hLib, "CreateRemoteThread");
}
DWORD findProcessId(DWORD parentId)
{
HANDLE hProcList = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 procEntry;
procEntry.dwSize = sizeof(PROCESSENTRY32);
DWORD procId = 0;
BOOL moreProc = Process32First(hProcList, &procEntry);
while (moreProc) {
if (procEntry.th32ParentProcessID == parentId) {
procId = procEntry.th32ProcessID;
break;
}
moreProc = Process32Next(hProcList, &procEntry);
}
CloseHandle(hProcList);
return procId;
}
bool Debugger::Internal::interruptProcess(int pID)
{
DWORD pid = pID;
......@@ -92,83 +69,17 @@ bool Debugger::Internal::interruptProcess(int pID)
return false;
}
bool Debugger::Internal::interruptChildProcess(Q_PID parentPID)
{
DWORD pid = findProcessId(parentPID->dwProcessId);
return interruptProcess(pid);
}
#endif // defined(Q_OS_WIN)
#if defined(Q_OS_LINUX) || defined(Q_OS_MAC)
#include <QtCore/QLatin1String>
#include <QtCore/QString>
#include <QtCore/QDir>
#include <QtCore/QFileInfoList>
#include <QtCore/QByteArray>
#include <QtCore/QDebug>
#include <sys/types.h>
#include <signal.h>
#include <sys/sysctl.h>
using namespace Debugger::Internal;
/* Mac OS X
int OPParentIDForProcessID(int pid)
// Returns the parent process id for the given process id (pid)
{
const uint OPProcessValueUnknown = UINT_MAX;
struct kinfo_proc info;
size_t length = sizeof(struct kinfo_proc);
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid };
if (sysctl(mib, 4, &info, &length, NULL, 0) < 0)
return OPProcessValueUnknown;
if (length == 0)
return OPProcessValueUnknown;
return info.kp_eproc.e_ppid;
}
*/
int findParentProcess(int procId)
{
QFile statFile(QLatin1String("/proc/") + QString::number(procId) +
QLatin1String("/stat"));
if (!statFile.open(QIODevice::ReadOnly))
return -1;
QByteArray line = statFile.readLine();
line = line.mid(line.indexOf(')') + 4);
//qDebug() << "1: " << line;
line = line.left(line.indexOf(' '));
//qDebug() << "2: " << line;
return QString(line).toInt();
}
int findChildProcess(int parentId)
{
QDir proc(QLatin1String("/proc"));
QFileInfoList procList = proc.entryInfoList(QDir::Dirs);
foreach (const QFileInfo &info, procList) {
int procId = 0;
bool ok = false;
procId = info.baseName().toInt(&ok);
if (!ok || !procId)
continue;
if (findParentProcess(procId) == parentId)
return procId;
}
return -1;
}
bool Debugger::Internal::interruptProcess(int pID)
{
int procId = pID;
......@@ -179,11 +90,4 @@ bool Debugger::Internal::interruptProcess(int pID)
return false;
}
bool Debugger::Internal::interruptChildProcess(Q_PID parentPID)
{
int procId = findChildProcess(parentPID);
//qDebug() << "INTERRUPTING PROCESS" << procId;
return interruptProcess(procId);
}
#endif // defined(Q_OS_LINUX) || defined(Q_OS_MAC)
......@@ -36,7 +36,6 @@ namespace Debugger {
namespace Internal {
bool interruptProcess(int pID);
bool interruptChildProcess(Q_PID parentPID);
} // Internal
} // GdbDebugger
......
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