From a075bad97f281a47d341498e730057e868621d81 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Wed, 14 May 2014 11:26:20 +0300 Subject: Fix debugging of terminal applications on Linux On modern linux distributions (Ubuntu >= 10.10, Debian >= Wheezy), trying to debug a terminal application fails, with "ptrace: Operation not permitted". In order to allow the debugger to attach to the created process, the process itself needs to inform the kernel of the debugging process. Task-number: QTCREATORBUG-3509 Change-Id: I68670426fad18cbe3b7cce9d57633e58e631e025 Reviewed-by: Oswald Buddenhagen Reviewed-by: hjk --- src/libs/utils/consoleprocess_unix.cpp | 1 + src/libs/utils/process_stub_unix.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/libs/utils/consoleprocess_unix.cpp b/src/libs/utils/consoleprocess_unix.cpp index 1374d06f16..68917967dc 100644 --- a/src/libs/utils/consoleprocess_unix.cpp +++ b/src/libs/utils/consoleprocess_unix.cpp @@ -162,6 +162,7 @@ bool ConsoleProcess::start(const QString &program, const QString &args) << msgPromptToClose() << workingDirectory() << (d->m_tempFile ? d->m_tempFile->fileName() : QString()) + << QString::number(getpid()) << pcmd << pargs.toUnixArgs(); QString xterm = allArgs.takeFirst(); diff --git a/src/libs/utils/process_stub_unix.c b/src/libs/utils/process_stub_unix.c index 4a9df676b5..efb2698402 100644 --- a/src/libs/utils/process_stub_unix.c +++ b/src/libs/utils/process_stub_unix.c @@ -47,6 +47,16 @@ #include #include +#ifdef __linux__ +#include + +// Enable compilation with older header that doesn't contain this constant +// for running on newer libraries that do support it +#ifndef PR_SET_PTRACER +#define PR_SET_PTRACER 0x59616d61 +#endif +#endif + /* For OpenBSD */ #ifndef EPROTO # define EPROTO EINVAL @@ -90,6 +100,7 @@ enum { ArgMsg, ArgDir, ArgEnv, + ArgPid, ArgExe }; @@ -289,6 +300,7 @@ int main(int argc, char *argv[]) /* Get a SIGTRAP after exec() has loaded the new program. */ #ifdef __linux__ + prctl(PR_SET_PTRACER, atoi(argv[ArgPid])); ptrace(PTRACE_TRACEME); #else ptrace(PT_TRACE_ME, 0, 0, 0); -- cgit v1.2.1