ndk-samples icon indicating copy to clipboard operation
ndk-samples copied to clipboard

Unable to attach gdbserver to native activity app

Open albertofustinoni opened this issue 3 years ago • 0 comments

I am developing a fully native Android app that is implemented as a NativeActivity and has no Java code.

Since the project is multiplatform it uses CMake alone as the build system: no Android Studio or Gradle involved. So far I have been able to build, package and run my app fine, however I am unable to debug it: any attempts to attach gdbserver fail with it complainnig the PID is inaccessible or not found.

I am using an Android 11 (API level 30) emulator image with Google APIs only, which includes gdbserver and gdbserver64.

When running the app I can see it listed in top's output

Tasks: 258 total,   2 running, 256 sleeping,   0 stopped,   0 zombie
  Mem:  2028236K total,  1886276K used,   141960K free,  15773696 buffers
 Swap:  1521172K total,   133120K used,  1388052K free,   918140K cached
400%cpu  44%user   0%nice  64%sys 291%idle   0%iow   0%irq   0%sirq   0%host
   PID USER         PR  NI VIRT  RES  SHR S[%CPU] %MEM     TIME+ ARGS
  5534 u0_a153      10 -10  12G 185M  78M S 69.0   9.3  14:12.89 net.aftnet.vceverywhere
   329 system       -3  -8  10G  21M  10M S 32.6   1.0   4:24.28 surfaceflinger
   306 system       -3  -4  10G  12M 6.5M S 18.0   0.5   2:22.54 [email protected]
   530 system       18  -2  13G 245M 174M S  7.3  12.3   4:56.37 system_server
   294 audioserver  20   0  10G 3.7M 3.4M S  5.6   0.1   0:49.08 android.hardware.audio.service.ranchu
   296 bluetooth    20   0  10G 3.1M 2.9M S  5.3   0.1   1:18.48 [email protected]
   407 audioserver  20   0  10G 9.3M 8.3M S  4.3   0.4   0:54.63 audioserver
   670 bluetooth    20   0  12G 105M  81M S  2.6   5.2   0:34.58 com.android.bluetooth
  5834 root         20   0  10G 4.7M 3.6M R  2.0   0.2   0:00.13 top

But attempting to attach to its PID (5534 in this case) fails

generic_x86_64_arm64:/ # gdbserver64 :5039 --attach 5534
/bin/sh: 5534: inaccessible or not found
During startup program exited with code 127.
Exiting

This even when running the adb shell as root.

Even trying run-as net.aftnet.vceverywhere gdbserver64 --attach :5039 $(pidof net.aftnet.vceverywhere) fails in the same way.

How can I attach a debugger to a pure c++ app?

I also already specified

android:hasCode="false"
android:debuggable="true"

in the application section of the manifest.

albertofustinoni avatar Aug 10 '21 13:08 albertofustinoni