Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
270 views
in Technique[技术] by (71.8m points)

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

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

Tips? enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...