I'm trying to debug and step through an Android application that segfaults. I've tried ndk-gdb
, but with little luck. I've also referred to Android NDK Debugging without being able to debug my app.
When I try ndk-gdb --start
, and I get:
$ ndk-gdb --start --verbose
Android NDK installation path: /opt/android-ndk-r7
Using default adb command: /opt/android-sdk-linux/platform-tools/adb
ADB version found: Android Debug Bridge version 1.0.29
Using final ADB command: '/opt/android-sdk-linux/platform-tools/adb'
Using auto-detected project path: .
Found package name: com.example.native_plasma
ABIs targetted by application: armeabi armeabi-v7a
Device API Level: 10
Device CPU ABIs: armeabi-v7a armeabi
Compatible device ABI: armeabi-v7a
Found debuggable flag: true
Found device gdbserver: /data/data/com.example.native_plasma/lib/gdbserver
Using gdb setup init: ./libs/armeabi-v7a/gdb.setup
Using toolchain prefix: /opt/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-
Using app out directory: ./obj/local/armeabi-v7a
Found data directory: '/data/data/com.example.native_plasma'
Found first launchable activity: android.app.NativeActivity
Launching activity: com.example.native_plasma/android.app.NativeActivity
## COMMAND: /opt/android-sdk-linux/platform-tools/adb shell am start -n com.example.native_plasma/android.app.NativeActivity
Starting: Intent { cmp=com.example.native_plasma/android.app.NativeActivity }
## COMMAND: /opt/android-sdk-linux/platform-tools/adb shell sleep 2
Found running PID: 0
ERROR: Could not extract PID of application on device/emulator.
Weird, this probably means one of these:
- The installed package does not match your current manifest.
- The application process was terminated.
Try using the --verbose option and look at its output for details.
This indicates that the application segfaulted more less, but I don't know how to set a breakpoint here since gdb never actually gives a prompt.
I also tried this command:
$ ../../toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-addr2line -f -e libs/armeabi/libnative-plasma.so
bedb2330
??
??:0
I have debug symbols I believe.
ndk-build -B V=1 APP_OPTIM=debug
Android.mk
in jni/
has LOCAL_CFLAGS := -g
ant debug
I've also ndk-build NDK_DEBUG=1
but I still get where it looks like I don't have debug symbols.
Here's an image of the stack trace. It doesn't get any more informative:
Using Android Studio 2.2 and higher, you can use the NDK to compile C and C++ code into a native library and package it into your APK using Gradle, the IDE's integrated build system. Your Java code can then call functions in your native library through the Java Native Interface (JNI) framework.
Navigate to Settings -> System -> Developer options and then scroll to the Debugging section. Click on “Select debug app”. Select the application you want to debug from the list.
Android Debug Bridge (adb) is a versatile command-line tool that lets you communicate with a device. The adb command facilitates a variety of device actions, such as installing and debugging apps, and it provides access to a Unix shell that you can use to run a variety of commands on a device.
Well NDK_DEBUG=1 and debuggable flag in manifest set to true are required. When you build the app,in your project/libs/armeabi, there should be a gdb.setup file. There is symbol search path there, check whether it is valid. And did you try this:
ndk-gdb --start --verbose --force
And looks like you are getting a null pointer exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With