How can I effectively debug C code that's wrapped with JNI in Eclipse? (Android Dev)

天涯浪子 提交于 2019-12-28 08:39:42

问题


I've got a segfault but I have absolutely no idea how to locate it.

Tips?


回答1:


You can get the location of the C function that caused the crash using the Android NDK Stacktrace Analyzer.

The steps are on the wiki, but basically you need to get the stack trace from logcat into a file (adb logcat > mycrash.log), then dump your library to a text file, then run the program on the two of them. Here's the shell script I use to do the lot:

#!/bin/sh
if test $# -lt 2 ; then
    echo "Extract readable stack trace from Android logcat crash"
    echo "Usage $0 lib.so crash.log"
    exit 1
fi
of=$(mktemp)
echo "Disassemble $1"
~/tools/android-ndk-r5/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-objdump -S $1 > $of
echo "Parse stack trace in $2"
~/bin/parse_stack.py $of $2

Change the paths to the Android NDK and parse_stack.py file as you need.




回答2:


How to Effectively Debug Android JNI C/C++ Code in Eclipse:

  1. Setup your project to be a mixed Java, C, and C++ project:

    http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-development/

  2. Setup your project to enable debugging:

    http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-debugging/#more-23

Note: The author of the site used Eclipse(Galileo) on Ubuntu. I found some differences when using Eclipse(Helios) on MacOS (especially with the debug setup). Once things are set up, Eclipse works very well as an IDE for JNI development.



来源:https://stackoverflow.com/questions/4846080/how-can-i-effectively-debug-c-code-thats-wrapped-with-jni-in-eclipse-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!