我想使用ndk-gdb在Android应用程序上调试我的本机代码。 我的ndk版本是 r9d ,我的操作系统是 Ubuntu 12.04 64位。
我将HelloJni用于我的测试项目。编译完成后(ndk-build NDK_DEBUG = 1),我尝试使用ndk-gdb来调试这个项目。但是有错误。
> ndk-gdb --verbose --force --start
WARNING: The shell running this script isn't bash. Although we try to avoid bashism in scripts, things can happen.
/home/jargo/ndk/android-ndk-r9d/ndk-gdb: 143: /home/jargo/ndk/android-ndk-r9d/ndk-gdb: Bad substitution
Android NDK installation path: /home/jargo/ndk/android-ndk-r9d
Using default adb command: /home/jargo/sdk/android-sdk-linux/platform-tools/adb
ADB version found: Android Debug Bridge version 1.0.31
Using ADB flags:
Using JDB command: /usr/bin/jdb
Using auto-detected project path: .
Found package name: com.example.hellojni
ABIs targetted by application: armeabi
Device API Level: 17
Device CPU ABIs: armeabi-v7a armeabi
/home/jargo/ndk/android-ndk-r9d/ndk-gdb: 555: [: 1: unexpected operator
Compatible device ABI: armeabi
Using gdb setup init: ./libs/armeabi/gdb.setup
Using toolchain prefix: /home/jargo/ndk/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
Using app out directory: ./obj/local/armeabi
Found debuggable flag: false
Found gdb.setup under libs/armeabi, assuming app was built with NDK_DEBUG=1
Found data directory: '/data/data/com.example.hellojni'
Found device gdbserver: /data/data/com.example.hellojni/lib/gdbserver
Found first launchable activity: .HelloJni
Launching activity: com.example.hellojni/.HelloJni
## COMMAND: adb_cmd shell am start -D -n com.example.hellojni/.HelloJni
Starting: Intent { cmp=com.example.hellojni/.HelloJni }
## COMMAND: adb_cmd shell sleep 2
Found running PID: 9802
Launched gdbserver succesfully.
Setup network redirection
## COMMAND: adb_cmd forward tcp:5039 localfilesystem:/data/data/com.example.hellojni/debug-socket
## COMMAND: adb_cmd shell run-as com.example.hellojni /data/data/com.example.hellojni/lib/gdbserver +debug-socket --attach 9802
## COMMAND: adb_cmd pull /system/bin/app_process ./obj/local/armeabi/app_process
Cannot attach to lwp 9802: Operation not permitted (1)
Exiting
107 KB/s (9564 bytes in 0.086s)
Pulled app_process from device/emulator.
## COMMAND: adb_cmd pull /system/bin/linker ./obj/local/armeabi/linker
376 KB/s (63176 bytes in 0.163s)
Pulled linker from device/emulator.
## COMMAND: adb_cmd pull /system/lib/libc.so ./obj/local/armeabi/libc.so
560 KB/s (301636 bytes in 0.525s)
Pulled libc.so from device/emulator.
Setup JDB connection
## COMMAND: adb_cmd forward tcp:65534 jdwp:9802
java.io.IOException: handshake failed - connection prematurally closed
at com.sun.tools.jdi.SocketTransportService.handshake(SocketTransportService.java:136)
at com.sun.tools.jdi.SocketTransportService.attach(SocketTransportService.java:232)
at com.sun.tools.jdi.GenericAttachingConnector.attach(GenericAttachingConnector.java:116)
at com.sun.tools.jdi.SocketAttachingConnector.attach(SocketAttachingConnector.java:90)
at com.sun.tools.example.debug.tty.VMConnection.attachTarget(VMConnection.java:519)
at com.sun.tools.example.debug.tty.VMConnection.open(VMConnection.java:328)
at com.sun.tools.example.debug.tty.Env.init(Env.java:63)
at com.sun.tools.example.debug.tty.TTY.main(TTY.java:1066)
Fatal error:
Unable to attach to target VM.
/home/jargo/ndk/android-ndk-r9d/ndk-gdb: 771: [: armeabi: unexpected operator
GNU gdb (GDB) 7.3.1-gg2
Copyright (C) 2011 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-linux-gnu --target=arm-linux-android".
For bug reporting instructions, please see:
<http://source.android.com/source/report-bugs.html>.
./obj/local/armeabi/gdb.setup:4: Error in sourced command file:
Remote communication error. Target disconnected.: Connection reset by peer.
似乎错误在其脚本中,并且无法加载符号表。我发现这个link,它说使用ndk-gdb.py - ndk-gdb的python版本。错误显示如下,似乎连接失败。
> ndk-gdb.py --verbose --force --start
Android NDK installation path: /home/jargo/ndk/android-ndk-r9d
ADB version found: Android Debug Bridge version 1.0.31
Using ADB flags:
Using auto-detected project path: .
Found package name: com.example.hellojni
ABIs targetted by application: armeabi
Device API Level: 17
Device CPU ABIs: armeabi-v7a armeabi
Compatible device ABI: armeabi
Using gdb setup init: ./libs/armeabi/gdb.setup
Using toolchain prefix: /home/jargo/ndk/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
Using app out directory: ./obj/local/armeabi
Found debuggable flag: false
Found gdbserver under libs/armeabi, assuming app was built with NDK_DEBUG=1
Found device gdbserver: /data/data/com.example.hellojni/lib/gdbserver
Found data directory: '/data/data/com.example.hellojni'
Found first launchable activity: .HelloJni
Launching activity: com.example.hellojni/.HelloJni
## COMMAND: adb_cmd shell am start -D -n com.example.hellojni/.HelloJni
## COMMAND: adb_cmd shell sleep 2.000000
Found running PID: 9585
## COMMAND: adb_cmd shell run-as com.example.hellojni lib/gdbserver +debug-socket --attach 9585 [BACKGROUND]
Launched gdbserver succesfully.
Setup network redirection
## COMMAND: adb_cmd forward tcp:5039 localfilesystem:/data/data/com.example.hellojni/debug-socket
## COMMAND: adb_cmd pull /system/bin/app_process ./obj/local/armeabi/app_process
Cannot attach to lwp 9585: Operation not permitted (1)
Exiting
106 KB/s (9564 bytes in 0.087s)
Pulled app_process from device/emulator.
## COMMAND: adb_cmd pull /system/bin/linker ./obj/local/armeabi/linker
301 KB/s (63176 bytes in 0.204s)
Pulled linker from device/emulator.
## COMMAND: adb_cmd pull /system/lib/libc.so ./obj/local/armeabi/libc.so
752 KB/s (301636 bytes in 0.391s)
Pulled libc.so from device/emulator.
Set up JDB connection, using jdb command: /usr/bin/jdb
## COMMAND: adb_cmd forward tcp:65534 jdwp:9585
JDB :: java.io.IOException: handshake failed - connection prematurally closed
JDB :: at com.sun.tools.jdi.SocketTransportService.handshake(SocketTransportService.java:136)
JDB :: at com.sun.tools.jdi.SocketTransportService.attach(SocketTransportService.java:232)
JDB :: at com.sun.tools.jdi.GenericAttachingConnector.attach(GenericAttachingConnector.java:116)
JDB :: at com.sun.tools.jdi.SocketAttachingConnector.attach(SocketAttachingConnector.java:90)
JDB :: at com.sun.tools.example.debug.tty.VMConnection.attachTarget(VMConnection.java:519)
JDB :: at com.sun.tools.example.debug.tty.VMConnection.open(VMConnection.java:328)
JDB :: at com.sun.tools.example.debug.tty.Env.init(Env.java:63)
JDB :: at com.sun.tools.example.debug.tty.TTY.main(TTY.java:1066)
JDB ::
JDB :: Fatal error:
JDB :: Unable to attach to target VM.
GNU gdb (GDB) 7.3.1-gg2
Copyright (C) 2011 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-linux-gnu --target=arm-linux-android".
For bug reporting instructions, please see:
<http://source.android.com/source/report-bugs.html>.
./obj/local/armeabi/gdb.setup:4: Error in sourced command file:
Remote communication error. Target disconnected.: Connection reset by peer.
有谁知道这是什么问题?