How to print stack trace (with symbolic function names) on Android?

后端 未结 1 648
臣服心动
臣服心动 2021-01-15 10:40

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, li

相关标签:
1条回答
  • 2021-01-15 11:02

    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).

    0 讨论(0)
提交回复
热议问题