Why is attaching gdbserver to a native android app failing?

Viewed 269

I am developing a fully native application in using C++ and pure CMake as the build system - no Android Studio involved at all (proof of concept here)

The code builds, apk is generated and can be installed and run via ADB without issue but I cannot get gdbserver64 to attach to the process for debugging.

More details:

  • App is built against SDK/NDK API level 30
  • Attempting to debug on an Android 11 emulator instance without Google Play
  • I can run adb root just fine
  • Image already includes gdbserver and gdbserver64, attempting to use those
  • Developer options and USB debugging enebled in emulator
  • App has android:debuggable="true" in manifest

But every time I try gdbserver64 :5039 --attach $(pidof my.app.id)

I get /bin/sh: <app_pid>: inaccessible or not found

What am I missing? And no, I cannot just move to Android Studio - this is a cross platform project that needs to be buildable using only CMake.

2 Answers

According to my observation, this may be a bug of prebuilt gdbserver. It treats the parameter after --attach as a program name and tries to start it.

It's not really an answer, but in similar configuration to yours I got same error message and unable to overcome this. For me, switching to lldb helped, see e.g.

Related