سؤال

This question has been asked a number of times, but it has never really been answered. I've spent 5 to 6 hours today trying to port some libraries to Android (libunwind, liwdfl) that probably have never been intended to work on ARM. To no avail, of course.

The problem is that Android lacks backtrace / backtrace_symbols functions. Has anyone found a way to print stacktrace, say, upon receiving SIGSEGV?

هل كانت مفيدة؟

المحلول

The way this is done internally is with the CallStack class. For example:

CallStack cs("logtag");

will dump the current native call stack to the log. Unfortunately this is not available in the NDK, and the class does change from version to version.

In Android KitKit (4.4), the implementation used the internal libcorkscrew library. In the current "master" branch, the implementation uses libbacktrace, also an internal library. However, this new library is built on libunwind, an open-source project.

So you should be able to build libunwind into your app and use it that way. Since the libraries are already in use on Android, porting should be far less of a problem (just start with the AOSP external/libunwind sources).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top