I want to use ndk-gdb to debug my native code in an android application. My version is ndk r9d and my Ubuntu 12.04 OS is 64-bit .
I am using HelloJni for my test project. After compiling (ndk-build NDK_DEBUG = 1) I try to use ndk-gdb to debug this project. But there are mistakes.
> 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
Starting: Intent { cmp=com.example.hellojni/.HelloJni }
Found running PID: 9802
Launched gdbserver succesfully.
Setup network redirection
Cannot attach to lwp 9802: Operation not permitted (1)
Exiting
107 KB/s (9564 bytes in 0.086s)
Pulled app_process from device/emulator.
376 KB/s (63176 bytes in 0.163s)
Pulled linker from device/emulator.
560 KB/s (301636 bytes in 0.525s)
Pulled libc.so from device/emulator.
Setup JDB connection
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.
It seems that the error is in the script and cannot load the character table. I found this link, it says ndk-gdb.py uses the python version of ndk-gdb. Errors show the following, it seems that the connection failed.
> 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
Found running PID: 9585
Launched gdbserver succesfully.
Setup network redirection
Cannot attach to lwp 9585: Operation not permitted (1)
Exiting
106 KB/s (9564 bytes in 0.087s)
Pulled app_process from device/emulator.
301 KB/s (63176 bytes in 0.204s)
Pulled linker from device/emulator.
752 KB/s (301636 bytes in 0.391s)
Pulled libc.so from device/emulator.
Set up JDB connection, using jdb command: /usr/bin/jdb
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.
Does anyone know what the problem is?
source
share