我正在尝试调试我的本机库已有一段时间了,它只是无法工作。本机代码可以工作和编译,但出于优化目的,我真的需要调试本机代码。
我已经逐步阅读并遵循了许多教程(例如tutorial1,tutorial2),但我遇到了一些我无法找到解决方案的错误。
我已经设置了Android和C ++调试配置,在使用Android调试配置进行调试后,它在加载库(仅一个)后命中断点。我去cygwin看看我的设备是否被检测到(它是)。然后运行:
$ ndk-gdb --start --verbose
这给了我以下输出:
Android NDK installation path: /cygdrive/c/Android/android-ndk/android-ndk-r8
Using default adb command: /cygdrive/c/Android/android-sdk/platform-tools/adb
ADB version found: Android Debug Bridge version 1.0.29
Using ADB flags:
Using auto-detected project path: .
Found package name: com.mypackage
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/Android/android-ndk/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-
Using app out directory: ./obj/local/armeabi-v7a
Found debuggable flag: true
Found device gdbserver: /data/data/com.mypackage/lib/gdbserver
Found data directory: '/data/data/com.mypackage'
Found first launchable activity: .MainActivity
Launching activity: com.mypackage/.MainActivity
## COMMAND: /cygdrive/c/Android/android-sdk/platform-tools/adb shell am start -n com.mypackage/.MainActivity
Starting: Intent { cmp=com.mypackage/.MainActivity }
## COMMAND: /cygdrive/c/Android/android-sdk/platform-tools/adb shell sleep 2
Found running PID: 6907
Launched gdbserver succesfully.
Setup network redirection
## COMMAND: /cygdrive/c/Android/android-sdk/platform-tools/adb shell run-as com.mypackage lib/gdbserver +debug-socket --attach 6907
## COMMAND: /cygdrive/c/Android/android-sdk/platform-tools/adb forward tcp:5039 localfilesystem:/data/data/com.mypackage/debug-socket
Attached; pid = 6907
Could not open remote device: Invalid argument.
Detaching process(es): 6907
## COMMAND: /cygdrive/c/Android/android-sdk/platform-tools/adb pull /system/bin/app_process obj/local/armeabi-v7a/app_process
2405 KB/s (9852 bytes in 0.004s)
Pulled app_process from device/emulator.
## COMMAND: /cygdrive/c/Android/android-sdk/platform-tools/adb pull /system/lib/libc.so obj/local/armeabi-v7a/libc.so
4994 KB/s (286412 bytes in 0.056s)
Pulled libc.so from device/emulator.
User@This-PC /cygdrive/c/Development/MyAppAndroid/trunk/MyApp
$
我可以看到gdbserver已成功启动,这很好,但我不知道为什么会这样:
Could not open remote device: Invalid argument
因为adb可以连接到设备(如前所述)。在那之后,在我看来(我对cygwin不太熟悉)gdb只是关闭所有内容,这将使eclipse中的c ++ Debug也失败。当我运行它时,出现以下错误:
76-target-select remote localhost:5039
&"Remote communication error: Bad file descriptor.\n"
Remote communication error: Bad file descriptor.
76^error,msg="Remote communication error: Bad file descriptor."
有什么东西可以阻止我的设备被adb检测到吗?我一直没有问题地使用这个设备进行测试(没有c ++调试)。
问题还在于端口错误吗?
答案 0 :(得分:3)
我遇到了同样的问题,所以我在ndk-gdb文件中替换了以下行:
原件:
run adb_cmd shell run-as $PACKAGE_NAME lib/gdbserver +$DEBUG_SOCKET --attach $PID &
替换:
run adb_cmd shell run-as $PACKAGE_NAME lib/gdbserver tcp:5888 --attach $PID &
原着:
run adb_cmd forward tcp:$DEBUG_PORT localfilesystem:$DATA_DIR/$DEBUG_SOCKET
替换:
run adb_cmd forward tcp:5039 tcp:5888
修复了“无效参数”问题。
P上。