简体   繁体   中英

Unable to find android NDK stack-trace

I am developing an app that crashes in NDK code with SIG_SEGV. This causes the app to hang for about 15 seconds, then Android will prompt me to force close it. This prints the java stack-trace to logcat, but I don't see any stack-trace for the NDK. I have redirected stdio with ADB but I still don't see a stack-trace. How can I print C++ stack trace to logcat or where is being printed too?
Using Android 2.3.4
NDK r8b

The "force close" dialog is posted by the crashing application. This sounds like a Dalvik crash rather than a native crash. If the process is receiving a SIGSEGV it should be notifying debuggerd and exiting, leaving a trace in the log. It might be helpful to include logcat output from the crash in your question.

At any rate, recent versions of Android include the native traces mixed in with the Dalvik stack dump when threads are in native code. If you have a rooted device running a recent version of Android, you can ask debuggerd to dump a trace of all threads with adb shell debuggerd -b <pid> .

You're on Android 2.3.x, though, so none of that helps you. Your best option is to send the process a fatal signal to get the debuggerd crash dump. The signal must be sent twice, eg:

adb shell kill -6 <pid> ; sleep 1 ; adb shell kill -6 <pid>

This requires a rooted device, as the "shell" user can't send signals to arbitrary processes. Depending on what exactly is going on, you should be able to do this while the "force close" dialog is still on screen... but if the thread managed to crash without taking the process down then there may not be a stack to get a trace from.

You can use the following code to get Log

 __android_log_print(ANDROID_LOG_ERROR, "TRACKERS", "%s", Str);

and add the following library

#include <android/log.h>

有一个名为CheckJNI的工具,并且在那里进行设置的教程。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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