我有两个 Android 项目:一个是库,另一个是使用该库的常规应用程序。我的目标是从 android 应用程序调试共享库。我遵循了本指南:
http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-debugging/
我注释掉了最后一行
##$GDBCLIENT -x `native_path $GDBSETUP`
但是下面一行
##cp -f $GDBSETUP_INIT $GDBSETUP
抱怨消息:
it cannot stat ./libs/armeabi-v7a/gdb.setup
所以我把它注释掉了,因为我认为 Eclipse 会为我上传它。除此之外,我确保:
在两个 Android.mk 中我都放了 LOCAL_CFLAGS := -Wall –g
我在应用程序的 libs 库中获取 .so
我在应用程序中使 debuggable true
修改了 gdb2.setup 路径,以便使用 solib-search-path ./libs/armeabi-v7a/ 引用 .so 并使用目录引用源
在执行 System.LoadLibrary 指令后,我执行了 ndk-build-eclipse 并且没有产生错误,当我开始本地调试时,我得到了:
无法访问地址 0x1 处的内存
在 Cygwin 上我得到了:
从主机 0.0.0.0 远程调试
这是运行 ndk-gdb-eclipse 命令的输出:
$ ./ndk-gdb-eclipse --adb=/cygdrive/c/Utilities/adt-bundle-windows/adt-bundle-windows/sdk/platform-tools/adb --project=/cygdrive/c/Projects/IDSmart/IDSmartApp/IDSmart --force --port=5039 --verbose
Android NDK installation path: /cygdrive/c/Utilities/android-ndk-r8c-windows/android-ndk-r8c/.
Using specific adb command: /cygdrive/c/Utilities/adt-bundle-windows/adt-bundle-windows/sdk/platform-tools/adb
ADB version found: Android Debug Bridge version 1.0.31
Using ADB flags:
Using specified project path: /cygdrive/c/Projects/IDSmart/IDSmartApp/IDSmart
Found package name: uk.co.idscan.idsmart
ABIs targetted by application: armeabi-v7a
Device API Level: 15
Device CPU ABIs: armeabi-v7a armeabi
Compatible device ABI: armeabi-v7a
Using gdb setup init: ./libs/armeabi-v7a/gdb.setup
Using toolchain prefix: /cygdrive/c/Utilities/android-ndk-r8c-windows/android-ndk-r8c/./toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/arm-linux-androideabi-
Using app out directory: ./obj/local/armeabi-v7a
Found debuggable flag: true
Found device gdbserver: /data/data/uk.co.idscan.idsmart/lib/gdbserver
Found data directory: '/data/data/uk.co.idscan.idsmart'
Found running PID: 7922
7922
Killing existing debugging session
## COMMAND: adb_cmd shell kill -9 7864
/system/bin/sh: kill: 7864: Operation not permitted
Launched gdbserver succesfully.
Setup network redirection
## COMMAND: adb_cmd shell run-as uk.co.idscan.idsmart lib/gdbserver +debug-socket --attach 7922
## COMMAND: adb_cmd forward tcp:5039 localfilesystem:/data/data/uk.co.idscan.idsmart/debug-socket
Attached; pid = 7922
Listening on Unix socket debug-socket
## COMMAND: adb_cmd pull /system/bin/app_process obj/local/armeabi-v7a/app_process
1373 KB/s (9848 bytes in 0.007s)
Pulled app_process from device/emulator.
## COMMAND: adb_cmd pull /system/bin/linker obj/local/armeabi-v7a/linker
2147 KB/s (39592 bytes in 0.018s)
Pulled linker from device/emulator.
## COMMAND: adb_cmd pull /system/lib/libc.so obj/local/armeabi-v7a/libc.so
2576 KB/s (282316 bytes in 0.107s)
Pulled libc.so from device/emulator.