3

How can I start native debugging session on Nexus 5X?

I tried running 'ndk-gdb' and it cannot start the debugging session. The native code is build with NDK_GDB=1 and deployed app is debuggable.

Here is the output of ndk-gdb when attempting to start gdb session on Nexus 5X:

$ ndk-gdb --package=com.microblink.test --verbose
Android NDK installation path: /Users/dodo/android-sdks/android-ndk
Using default adb command: /Users/dodo/android-sdks/platform-tools/adb
ADB version found: Android Debug Bridge version 1.0.32
Revision 09a0d98bebce-android
Using ADB flags: 
Using JDB command: /usr/bin/jdb
Using auto-detected project path: .
Using package name: com.microblink.test
ABIs targetted by application: arm64-v8a armeabi armeabi-v7a armeabi-v7a mips mips64 x86 x86_64
Device API Level: 23
Device CPU ABIs: arm64-v8a armeabi-v7a armeabi
Compatible device ABI: arm64-v8a
Using gdb setup init: ./libs/arm64-v8a/gdb.setup
Using toolchain prefix: /Users/dodo/android-sdks/android-ndk/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-
Using app out directory: ./obj/local/arm64-v8a
Found debuggable flag: false
Found gdb.setup under libs/arm64-v8a, assuming app was built with NDK_DEBUG=1
Found data directory: '/data/data/com.microblink.test'
4813 KB/s (759464 bytes in 0.154s)
Push gdbserver in device
Found device gdbserver: /data/local/tmp/gdbserver
Found running PID: 16285
Launched gdbserver succesfully.
Setup network redirection
## COMMAND: adb_cmd forward tcp:5039 localfilesystem:/data/data/com.microblink.test/debug-socket
## COMMAND: adb_cmd pull /system/bin/app_process64 ./obj/local/arm64-v8a/app_process
1623 KB/s (22456 bytes in 0.013s)
Pulled app_process64 from device/emulator.
## COMMAND: adb_cmd pull /system/bin/linker64 ./obj/local/arm64-v8a/linker64
4637 KB/s (273320 bytes in 0.057s)
Pulled linker64 from device/emulator.
## COMMAND: adb_cmd pull /system/lib64/libc.so ./obj/local/arm64-v8a/libc.so
4046 KB/s (1032392 bytes in 0.249s)
Pulled /system/lib64/libc.so from device/emulator.
GNU gdb (GDB) 7.7
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-apple-darwin --target=aarch64-elf-linux".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://source.android.com/source/report-bugs.html>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Warning: /Users/dodo/Work/Microblink/android-core/core/CoreUtils/tinyxml2: No such file or directory.
./obj/local/arm64-v8a/gdb.setup:5: Error in sourced command file:
Remote connection closed
(gdb) c
The program is not being run.
(gdb) q

However, the very same call to ndk-gdb works correctly when started on HTC One M8 with Android 5.0.

Here is the output of ndk-gdb for same app when HTC One M8 was plugged into PC:

$ ndk-gdb --package=com.microblink.test --verbose
Android NDK installation path: /Users/dodo/android-sdks/android-ndk
Using default adb command: /Users/dodo/android-sdks/platform-tools/adb
ADB version found: Android Debug Bridge version 1.0.32
Revision 09a0d98bebce-android
Using ADB flags: 
Using JDB command: /usr/bin/jdb
Using auto-detected project path: .
Using package name: com.microblink.test
ABIs targetted by application: arm64-v8a armeabi armeabi-v7a armeabi-v7a mips mips64 x86 x86_64
Device API Level: 21
Device CPU ABIs:  armeabi-v7a armeabi
Compatible device ABI: armeabi-v7a
Using gdb setup init: ./libs/armeabi-v7a/gdb.setup
Using toolchain prefix: /Users/dodo/android-sdks/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-
Using app out directory: ./obj/local/armeabi-v7a
Found debuggable flag: false
Found gdb.setup under libs/armeabi-v7a, assuming app was built with NDK_DEBUG=1
Found data directory: '/data/data/com.microblink.test'
Found device gdbserver: /data/data/com.microblink.test/lib/gdbserver
Found running PID: 2608
Launched gdbserver succesfully.
Setup network redirection
## COMMAND: adb_cmd forward tcp:5039 localfilesystem:/data/data/com.microblink.test/debug-socket
## COMMAND: adb_cmd pull /system/bin/app_process32 ./obj/local/armeabi-v7a/app_process
2175 KB/s (13636 bytes in 0.006s)
Pulled app_process32 from device/emulator.
## COMMAND: adb_cmd pull /system/bin/linker ./obj/local/armeabi-v7a/linker
3395 KB/s (133823 bytes in 0.038s)
Pulled linker from device/emulator.
## COMMAND: adb_cmd pull /system/lib/libc.so ./obj/local/armeabi-v7a/libc.so
3133 KB/s (490423 bytes in 0.152s)
Pulled /system/lib/libc.so from device/emulator.
Pulled *.bc:.so from device/emulator.
remote object '/data/data/com.microblink.test/lib/*.bc:.so' does not exist
Pulled No.so from device/emulator.
remote object '/data/data/com.microblink.test/lib/No.so' does not exist
Pulled such.so from device/emulator.
remote object '/data/data/com.microblink.test/lib/such.so' does not exist
Pulled file.so from device/emulator.
remote object '/data/data/com.microblink.test/lib/file.so' does not exist
Pulled or.so from device/emulator.
remote object '/data/data/com.microblink.test/lib/or.so' does not exist
Pulled directory.so from device/emulator.
remote object '/data/data/com.microblink.test/lib/directory.so' does not exist
GNU gdb (GDB) 7.7
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-apple-darwin --target=arm-linux-android".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://source.android.com/source/report-bugs.html>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Warning: /Users/dodo/Work/Microblink/android-core/core/CoreUtils/tinyxml2: No such file or directory.
warning: Could not load shared library symbols for 113 libraries, e.g. libm.so.
Use the "info sharedlibrary" command to see the complete listing.
Do you need "set solib-search-path" or "set sysroot"?
0xb6ecca6c in __epoll_pwait ()
   from /Users/dodo/Work/Microblink/android-core/android-studio/LibRecognizer/build/intermediates/ndk/everything/release/obj/local/armeabi-v7a/libc.so
(gdb) c
Continuing.

Is this an Android 6.0 issue or simply a 64-bit device issue (debugging also does not work on Samsung Galaxy S6, but I beleive this is due to a run-as not working).

Has anyone managed to debug NDK on Nexus 5X?

DoDo
  • 2,248
  • 2
  • 22
  • 34
  • I'm a bit late but I debug daily on Nexus 5X and 6P with Android studio and lldb, see my answer [here](http://stackoverflow.com/questions/28602260/how-to-get-breakpoint-in-ndk-native-code-and-debug-native-code-in-android-studio/33956159#33956159). I know it's not ndk-gdb but if you just want to d step by step ... you should be fine :) – Sistr Jan 05 '16 at 15:43
  • Sistr, I tried that. Seems promising, but debugger launching takes several minutes and native breakpoints are not hit. Even more, sometimes launching just deadlocks and never finishes. Are you using gradle-experimental plugin for building native code or custom ndk-build call from gradle exec task? – DoDo Jan 07 '16 at 18:41
  • I'm using gradle experimental plugin. One thing I sometime forget is to select the configuration "app native" instead of "app" next to the "run" green triangle button. Actually with lldb I have some very good perf for debug (attach in less than 2 second and breakpoint works on every single devices I tried for now, it's (for me) much more reliable than gdb :/. ) – Sistr Jan 08 '16 at 12:03
  • Do you have your project hosted somewhere ? – Sistr Jan 08 '16 at 12:03
  • Unfortunately, it is a closed source project, however I am using NDK build procedure as described [here](http://dodotrivia.blogspot.hr/2015/12/using-gradle-to-build-ndk-projects.html). – DoDo Jan 08 '16 at 16:16
  • Yeah :/ I used that in the past but can't help much because I always struggled with debugging using ndk-gdb too. If I were you and it is a long plan project I would probably try to migrate to gradle experiemtal plugin (http://tools.android.com/tech-docs/android-ndk-preview). It works pretty well and you can see dozen of example regarding how to use it here: https://github.com/googlesamples/android-ndk. Sorry I can't do more :/ – Sistr Jan 09 '16 at 12:10
  • Thank you for your comment, Sistr. I've been playing around with gradle experimental plugin for a while, however I still do not find it good enough to use it for production builds as it is missing key features and our Android.mk is gigantic so it is not so easy to migrate. It appears that for the time being I'll have to find another way of debugging NDK, for example simulating the lldb invocation AS is doing in command line, or using compatible device, like HTC One M8, for debugging... – DoDo Jan 09 '16 at 15:32

0 Answers0