Log the native backtrace when exception throws
It is always a pain for us that after converting c++ exception to java's, all the native backtrace just lost. This tries to hook into the __cxa_throw to log the native backtrace PCs when exception throws. The pc address can be then decoded through addr2line like: addr2line -C -f -e librealm-jni.so 0xa0293 0xa0548 0xb8cd1 0x3acb3 0x15611
A more wicked idea would be totally implement a __cxa_throw function and
convert exceptions from there and unwind the callstack to where JNI borders
then return to java peacefully. It seems to be doable and we can get rid of
the try CATCHSTD blocks for every JNI call. Need more investigations.
It might be worth comparing with https://github.com/realm/realm-core/blob/master/src/realm/util/terminate.cpp
We must also investigate how it works together with Crashlytics: https://docs.fabric.io/android/crashlytics/ndk.html
Despite my concerns and comments, I like the idea!
Might be useful: http://stackoverflow.com/questions/8115192/android-ndk-getting-the-backtrace
According to http://stackoverflow.com/a/35585744/1396606 , it seems it is safe for us to use <unwind.h> -- we are using gnustl static linked. Also, we are using visibility=hidden for build, but we don't need to parse symbols inside the so. Just get the backtrace addresses are good enough for us.
Some ideas in #813
I think I have heard rumours that the NDK team is working on a new libunwind.