如何使用Android 6.0在Nexus 5X上调试本机代码?

如何使用Android 6.0在Nexus 5X上调试本机代码?,android,debugging,android-ndk,gdb,Android,Debugging,Android Ndk,Gdb,如何在Nexus 5X上启动本机调试会话 我尝试运行“ndk gdb”,但它无法启动调试会话。本机代码是使用NDK_GDB=1构建的,部署的应用程序是可调试的 以下是尝试在Nexus 5X上启动gdb会话时ndk gdb的输出: $ ndk-gdb --package=com.microblink.test --verbose Android NDK installation path: /Users/dodo/android-sdks/android-ndk Using default adb

如何在Nexus 5X上启动本机调试会话

我尝试运行“ndk gdb”,但它无法启动调试会话。本机代码是使用NDK_GDB=1构建的,部署的应用程序是可调试的

以下是尝试在Nexus 5X上启动gdb会话时ndk gdb的输出:

$ 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
这是安卓6.0的问题还是64位设备的问题(三星Galaxy S6的调试也不起作用,但我认为这是由于运行方式不起作用所致)


有人试过在Nexus 5X上调试NDK吗?

我有点晚了,但我每天都用Android studio和lldb在Nexus 5X和6P上调试NDK,请看我的答案。我知道这不是ndk gdb,但如果你只是想一步一步地。。。你应该没事:)姐姐,我试过了。看起来很有希望,但调试器启动需要几分钟,并且不会命中本机断点。更重要的是,有时启动只是死锁,永远不会结束。您是使用gradle实验插件构建本机代码还是使用gradle exec任务的自定义ndk构建调用?我使用的是gradle实验插件。我有时忘记的一件事是在“运行”绿色三角形按钮旁边选择“应用程序本机”而不是“应用程序”。事实上,对于lldb,我有一些非常好的调试性能(在不到2秒的时间内连接,断点可以在我目前尝试的每个设备上工作,它(对我来说)比gdb:/)可靠得多。)您是否在某个地方托管了您的项目?不幸的是,它是一个封闭源代码项目,但我使用的是如上所述的NDK构建过程。
$ 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.