Android : Get the stack trace of a SIGSEGV from a c++ lib
<p>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). </p>

<p>To retrieve the stack trace, I've used this code :
<a href="https://stackoverflow.com/a/28858941/5120292">https://stackoverflow.com/a/28858941/5120292</a></p>

<p>To handle the signals :</p>

<pre><code>struct sigaction psa, oldPsa;

void Utils::registerSignalHandlers() {

    psa.sa_sigaction = Utils::handleSignal;
    psa.sa_flags = SA_SIGINFO;
    sigemptyset( &amp;psa.sa_mask );

    sigaction(SIGSEGV, &amp;psa, &amp;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
}
</code></pre>

<p>By the way I can't modify the JNI bridges since they are auto-generated by a tool. </p>

<p>My project has this architecture :</p>

<ul>
<li>android_project

<ul>
<li>...</li>
<li>main_module</li>
<li>c++_library_module

<ul>
<li>...</li>
<li>jni</li>
<li>libs

<ul>
<li>armeabi-v7a

<ul>
<li>c++_lib.so</li>
</ul></li>
</ul></li>
</ul></li>
</ul></li>
</ul>

<p>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 !</p>