realm-java icon indicating copy to clipboard operation
realm-java copied to clipboard

Log the native backtrace when exception throws

Open beeender opened this issue 9 years ago • 7 comments

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.

beeender avatar Dec 28 '16 11:12 beeender

It might be worth comparing with https://github.com/realm/realm-core/blob/master/src/realm/util/terminate.cpp

kneth avatar Jan 04 '17 14:01 kneth

We must also investigate how it works together with Crashlytics: https://docs.fabric.io/android/crashlytics/ndk.html

kneth avatar Jan 04 '17 14:01 kneth

Despite my concerns and comments, I like the idea!

kneth avatar Jan 04 '17 14:01 kneth

Might be useful: http://stackoverflow.com/questions/8115192/android-ndk-getting-the-backtrace

kneth avatar Jan 05 '17 12:01 kneth

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.

beeender avatar Jan 05 '17 12:01 beeender

Some ideas in #813

beeender avatar Mar 24 '17 10:03 beeender

I think I have heard rumours that the NDK team is working on a new libunwind.

kneth avatar Mar 24 '17 11:03 kneth