diff options
author | Orgad Shaneh <orgad.shaneh@audiocodes.com> | 2014-05-14 11:26:20 +0300 |
---|---|---|
committer | Orgad Shaneh <orgads@gmail.com> | 2014-05-15 15:07:53 +0200 |
commit | a075bad97f281a47d341498e730057e868621d81 (patch) | |
tree | 7c5e07210215fad779b6d2121ea7aa1ee16a2cf6 /src/libs/utils/process_stub_unix.c | |
parent | 4f62d6517474aa8c9ccdc8737e1ab46c9ad0aa69 (diff) |
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 <oswald.buddenhagen@digia.com>
Reviewed-by: hjk <hjk121@nokiamail.com>
Diffstat (limited to 'src/libs/utils/process_stub_unix.c')
-rw-r--r-- | src/libs/utils/process_stub_unix.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/libs/utils/process_stub_unix.c b/src/libs/utils/process_stub_unix.c index 4a9df676b5c..efb2698402c 100644 --- a/src/libs/utils/process_stub_unix.c +++ b/src/libs/utils/process_stub_unix.c @@ -47,6 +47,16 @@ #include <errno.h> #include <assert.h> +#ifdef __linux__ +#include <sys/prctl.h> + +// 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); |