Skip to content

Log the native backtrace when exception throws#3960

Open
beeender wants to merge 1 commit intoreleasesfrom
mc/experimental-native-exception
Open

Log the native backtrace when exception throws#3960
beeender wants to merge 1 commit intoreleasesfrom
mc/experimental-native-exception

Conversation

@beeender
Copy link
Copy Markdown
Contributor

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 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
@kneth
Copy link
Copy Markdown
Contributor

kneth commented Jan 4, 2017

@kneth
Copy link
Copy Markdown
Contributor

kneth commented Jan 4, 2017

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

@@ -0,0 +1,65 @@
#include <unwind.h>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does API < 16 have libunwind?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you see anything about the API 16 with libunwind? I cannot find too much information about that.

But! https://code.google.com/p/android/issues/detail?id=199936

libunwind is not an NDK API. even if you get this to work now, in future releases you will be prevented from linking against libunwind at runtime.

:( :( :(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unwind.h exists in both R10e and R13b.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kneth
Copy link
Copy Markdown
Contributor

kneth commented Jan 4, 2017

Despite my concerns and comments, I like the idea!

@kneth
Copy link
Copy Markdown
Contributor

kneth commented Jan 5, 2017

@beeender
Copy link
Copy Markdown
Contributor Author

beeender commented Jan 5, 2017

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
Copy link
Copy Markdown
Contributor Author

Some ideas in #813

@kneth
Copy link
Copy Markdown
Contributor

kneth commented Mar 24, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants