本文介绍了调试 Android NDK 原生应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调试和单步调试存在段错误的 Android 应用程序.我试过 ndk-gdb,但运气不佳.我还提到了 Android NDK 调试,但无法调试我的应用.

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.

当我尝试 ndk-gdb --start 时,我得到:

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.

这表明应用程序的段错误更少,但我不知道如何在此处设置断点,因为 gdb 从未真正给出提示.

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.

我也试过这个命令:

$ ../../toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-addr2line -f -e  libs/armeabi/libnative-plasma.so
bedb2330
??
??:0

我相信调试符号.

  • ndk-build -B V=1 APP_OPTIM=debug
  • Android.mkjni/ 中有 LOCAL_CFLAGS := -g
  • 蚂蚁调试
  • ndk-build -B V=1 APP_OPTIM=debug
  • Android.mk in jni/ has LOCAL_CFLAGS := -g
  • ant debug

我也ndk-build NDK_DEBUG=1,但我仍然看到我没有调试符号的地方.

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:

推荐答案

需要 NDK_DEBUG=1 并且清单中的 debuggable 标志设置为 true.当您构建应用程序时,在您的项目/libs/armeabi 中,应该有一个 gdb.setup 文件.那里有符号搜索路径,检查它是否有效.你有没有试过这个:

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.

这篇关于调试 Android NDK 原生应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-03 18:11