Utils: Add the ability to interrupt inferiors via the process stub

This will be handy once we want to debug processes running as root.

The mechanism is the same as for "killProcess", and currently unused.

Change-Id: I2c5e5b77577ca32ed1118fcc81c03c6320db8800
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
hjk
2021-02-16 08:57:08 +01:00
parent f200466066
commit 12a0934830
5 changed files with 27 additions and 0 deletions

View File

@@ -604,6 +604,18 @@ bool ConsoleProcess::start()
return true;
}
void ConsoleProcess::interruptProcess()
{
#ifdef Q_OS_WIN
// Not used.
#else
if (d->m_stubSocket && d->m_stubSocket->isWritable()) {
d->m_stubSocket->write("i", 1);
d->m_stubSocket->flush();
}
#endif
}
void ConsoleProcess::killProcess()
{
#ifdef Q_OS_WIN

View File

@@ -87,6 +87,7 @@ public:
bool isRunning() const; // This reflects the state of the console+stub
qint64 applicationPID() const;
void interruptProcess();
void killProcess();
void killStub();

View File

@@ -346,6 +346,13 @@ int main(int argc, char *argv[])
kill(chldPid, SIGKILL);
}
break;
case 'i':
if (chldPid > 0) {
int res = kill(chldPid, SIGINT);
if (res)
perror("Stub could not interrupt inferior");
}
break;
case 'd':
isDetached = 1;
break;

View File

@@ -183,6 +183,11 @@ TerminalRunner::TerminalRunner(RunControl *runControl, const Runnable &stubRunna
this, [this] { reportDone(); });
}
void TerminalRunner::interruptProcess()
{
m_stubProc.interruptProcess();
}
void TerminalRunner::start()
{
m_stubProc.setEnvironment(m_stubRunnable.environment);

View File

@@ -77,6 +77,8 @@ public:
qint64 applicationPid() const { return m_applicationPid; }
qint64 applicationMainThreadId() const { return m_applicationMainThreadId; }
void interruptProcess();
private:
void start() final;
void stop() final;