In my android project I use a c++ lib that I've implemented. My lib has some crashes, but I can only retrieve the stack traces of the exceptions raised, but not of the signals like SIGSEGV (the stack trace is empty).
To retrieve the stack trace, I've used this code : https://stackoverflow.com/a/28858941/5120292
To handle the signals :
struct sigaction psa, oldPsa;
void Utils::registerSignalHandlers() {
psa.sa_sigaction = Utils::handleSignal;
psa.sa_flags = SA_SIGINFO;
sigemptyset( &psa.sa_mask );
sigaction(SIGSEGV, &psa, &oldPsa);
}
void Utils::handleSignal(int signalNumber, siginfo_t *sigInfo, void *context) {
std::string message = get_stacktrace();
throw std::runtime_error(message); // this will create a java.lang.RuntimeException
}
By the way I can't modify the JNI bridges since they are auto-generated by a tool.
My project has this architecture :
- android_project
- ...
- main_module
- c++_library_module
- ...
- jni
- libs
- armeabi-v7a
- c++_lib.so
- armeabi-v7a
I saw that there is a tool called ndk-stack, but I could not understand how to make it work with my project. Also, it would be preferable to retrieve the log inside the program, and not using an external tool.. Any help would be appreciated !