Native code - how to get function call stack (backtrace) programmatically

前端 未结 2 697
感情败类
感情败类 2021-02-18 13:41

I have C++ codebase running on Android, and want to have crash reports sent by users.

I\'m using ACRA library which works fine for Java code, but when something crashes

相关标签:
2条回答
  • 2021-02-18 14:17

    I have done this in my game base project - you can see the JNI code which handles this here:

    https://bitbucket.org/xg/android-game-base/src/c0d969d44a55/jni/NativeActivityJNI.cpp#cl-40

    which calls the Java method defined here:

    https://bitbucket.org/xg/android-game-base/src/c0d969d44a55/src/com/gmail/whittock/tom/Util/NativeActivity.java#cl-91

    The overall solution is based on handling signals, then in the signal handler firing a call up to java to dump the stack trace etc, in my code I start another activity to get the logcat information and email it to me.

    0 讨论(0)
  • 2021-02-18 14:31

    ACRA can trap the application crashing. You could then instantiate a second process that would execute the logcat ( see this question ) command, filtering by your application name, and then have the process to send the dumped file to you. This is far from optimal because:

    • The Application that would span logcat has to have the WRITE_EXTERNAL_STORAGE and READ_LOGS permissions
    • Probably the user would be annoyed to having to install a new program

    But I didn't found another alternative to do this.

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