Home » Android » java native interface – ptrace returning -1 on Android

java native interface – ptrace returning -1 on Android

Posted by: admin May 14, 2020 Leave a comment

Questions:

I’m trying to detect when gdb is attached to my app and I’m using this in JNI code

long x = ptrace(PTRACE_TRACEME, 0, 1, 0);    
char buffer[24];
sprintf(buffer, "ptrace = %ld", x);
return (*env)->NewStringUTF(env, buffer);

However, x is always -1 regardless of whether gdb is attached or not. Why is that? What can I do to figure out what I’m doing wrong?

How to&Answers: