4

I am using vs-android for building native C++ Android applications. I would like to debug from the command line by launching gdbserver on the emulator and connecting to that GDB server. Since I'm not using the Android build scripts I don't get the gdbserver delivered by default. So I added gdbserver to the lib folder from where vs-android collects it and pushes it into the APK. The file is now found on the emulator in the lib folder of the application where my SO is also located when I deploy the application with adb install.

I now try to run gdbserver with run-as but I get the error "Cannot attach to process 924: Operation not permitted (1)".

According to this http://ian-ni-lewis.blogspot.com/2011/05/ndk-debugging-without-root-access.html the server should be able to attach to the process when gdbserver is started with run-as.

Any ideas as to what I could still be doing wrong?

  • The ndk-gdb script is just that - a shell script, which you can read and learn from. It seems you aren't using the run-as thing properly or it's broken on your device (as it is on one of mine). Additionally, make sure the apk being debugged has Internet permission as gdbserver will need a network socket unless you proxy it via a unix domain one. (I'd expect a different error message for that, but errors triggering misleading messages is not unknown in this world) – Chris Stratton Sep 06 '11 at 17:08

2 Answers2

3

adb shell su -c setenforce 0 it will solve the problem

Kiru
  • 91
  • 5
0

To figure out if the problem is with run-as or with gdbserver, try using run-as to execute 'ps' instead of gdbserver, and then see if the 'ps' process is listed as having the same userid as the application's process. If not, you have a problem with run-as. If it is the same userid as the app, then the problem is more likely with gdbserver.

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
  • I tried this with id and it really is the same user as the one that runs the application I'm trying to debug. This is the line that I've been using for attaching to the process: run-as com.ri.AndroidTests /data/data/com.ri.AndroidTests/lib/gdbserver :1234 --attach 285. – Timo Heinäpurola Sep 06 '11 at 20:27