简体   繁体   English

调试Android NDK本机应用程序

[英]Debugging Android NDK native apps

I'm trying to debug and step through an Android application that segfaults. 我正在尝试调试并逐步执行段错误的Android应用程序。 I've tried ndk-gdb , but with little luck. 我试过ndk-gdb ,但运气不好。 I've also referred to Android NDK Debugging without being able to debug my app. 我还提到了Android NDK调试而无法调试我的应用程序。

When I try ndk-gdb --start , and I get: 当我尝试ndk-gdb --start ,我得到:

$ 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. 这表明应用程序segfaulted更少,但我不知道如何在这里设置断点,因为gdb实际上从未给出提示。

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 -BV=1 APP_OPTIM=debug
  • Android.mk in jni/ has LOCAL_CFLAGS := -g jni/ Android.mk jni/具有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. 我也ndk-build NDK_DEBUG=1但我仍然看到我没有调试符号的地方。

Here's an image of the stack trace. 这是堆栈跟踪的图像。 It doesn't get any more informative: 它没有提供更多信息:

追溯

Well NDK_DEBUG=1 and debuggable flag in manifest set to true are required. NDK_DEBUG = 1并且清单设置为true时的debuggable标志是必需的。 When you build the app,in your project/libs/armeabi, there should be a gdb.setup file. 在构建应用程序时,在项目/ libs / armeabi中,应该有一个gdb.setup文件。 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. 看起来你得到一个空指针异常。

在最新版本的NDK和Eclipse插件中,您可以右键单击包并选择Debug as - > Android Native Application

Make sure that you load your native library in either a launchable activity or in your Application class. 确保在可启动活动或Application类中加载本机库。 Otherwise it wouldn't work and you'll get the following error No symbol table is loaded. Use the "file" command. 否则它将无法工作,您将收到以下错误No symbol table is loaded. Use the "file" command. No symbol table is loaded. Use the "file" command. .

For example in Application class: 例如在Application类中:

import android.app.Application;

public class MyApp extends Application {

    static {
        System.loadLibrary("Name");
    }

    public static native int doSomething();
}

Name is the name of your library (.so file) without the lib part. Name是没有lib部分的库(.so文件)的名称。

我解决了把--nowait选项放到shell命令:

ndk-gdb --start --verbose --nowait

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM