[notmuch] [PATCH RFC] debugger: detect presence of ptrace type debuggers
Bart Trojanowski
bart at jukie.net
Fri Nov 27 19:11:04 PST 2009
According to the internet [1], this is a more reliable way of detecting if
one is under the spell of a debugger. Should work for ptrace, strace,
gdb, etc. Basically anything that uses the ptrace() syscall.
[1] http://vx.netlux.org/lib/vsc04.html
---
debugger.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/debugger.c b/debugger.c
index e8b9378..f486032 100644
--- a/debugger.c
+++ b/debugger.c
@@ -22,6 +22,8 @@
#include <libgen.h>
+#include <sys/ptrace.h>
+
#if HAVE_VALGRIND
#include <valgrind.h>
#else
@@ -36,6 +38,9 @@ debugger_is_active (void)
if (RUNNING_ON_VALGRIND)
return TRUE;
+ if (ptrace(PTRACE_TRACEME, 0, 1, 0) < 0)
+ return TRUE;
+
sprintf (buf, "/proc/%d/exe", getppid ());
if (readlink (buf, buf, sizeof (buf)) != -1 &&
strncmp (basename (buf), "gdb", 3) == 0)
--
1.6.4.4.2.gc2f148
More information about the notmuch
mailing list