Saturday 26 September 2020

Is it possible to locate function names from a C++ backtrace from Android app?

I'm testing my app, which has a lot of C++, in debug. Even though it's compiled in debug, and the C++ code is compiled by my own app (thus is compiled in debug mode also), I get crash backtraces like this:

09-23 19:16:32.672 14123 14123 F DEBUG   : Build fingerprint: 'motorola/griffin/griffin:8.0.0/OPL27.76-71-2-3/3:user/release-keys'
09-23 19:16:32.672 14123 14123 F DEBUG   : Revision: 'p3b0'
09-23 19:16:32.672 14123 14123 F DEBUG   : ABI: 'arm64'
09-23 19:16:32.672 14123 14123 F DEBUG   : pid: 14078, tid: 14078, name: my_flutter_app  >>> com.sergio_lever.my_flutter_app <<<
09-23 19:16:32.672 14123 14123 F DEBUG   : signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
09-23 19:16:32.675 14123 14123 F DEBUG   : Abort message: 'terminating with uncaught exception of type std::bad_optional_access: bad_optional_access'
09-23 19:16:32.675 14123 14123 F DEBUG   :     x0   0000000000000000  x1   00000000000036fe  x2   0000000000000006  x3   0000000000000008
09-23 19:16:32.675 14123 14123 F DEBUG   :     x4   fefeff7ee760d21f  x5   fefeff7ee760d21f  x6   fefeff7ee760d21f  x7   7f7f7f7fff7fff7f
09-23 19:16:32.675 14123 14123 F DEBUG   :     x8   0000000000000083  x9   18e2b086a928bab4  x10  0000000000000000  x11  0000000000000001
09-23 19:16:32.675 14123 14123 F DEBUG   :     x12  ffffffffffffffff  x13  0000000000000001  x14  0024287419403a06  x15  0000260af954a2fc
09-23 19:16:32.675 14123 14123 F DEBUG   :     x16  0000007fb44632f8  x17  0000007fb44049d4  x18  0000007fe861da5c  x19  00000000000036fe
09-23 19:16:32.675 14123 14123 F DEBUG   :     x20  00000000000036fe  x21  0000007fe861d828  x22  ffffff80ffffffc8  x23  0000007fe861d8e0
09-23 19:16:32.676 14123 14123 F DEBUG   :     x24  0000007fe861d7c0  x25  0000007fe861d800  x26  0000000000000000  x27  0000000000000001
09-23 19:16:32.676 14123 14123 F DEBUG   :     x28  0000000000000001  x29  0000007fe861d730  x30  0000007fb43b8d24
09-23 19:16:32.676 14123 14123 F DEBUG   :     sp   0000007fe861d6f0  pc   0000007fb44049dc  pstate 0000000060000000
09-23 19:16:32.682 14123 14123 F DEBUG   : 
09-23 19:16:32.682 14123 14123 F DEBUG   : backtrace:
09-23 19:16:32.682 14123 14123 F DEBUG   :     #00 pc 00000000000699dc  /system/lib64/libc.so (tgkill+8)
09-23 19:16:32.682 14123 14123 F DEBUG   :     #01 pc 000000000001dd20  /system/lib64/libc.so (abort+88)
09-23 19:16:32.682 14123 14123 F DEBUG   :     #02 pc 000000000009fffc  /data/app/com.sergio_lever.my_flutter_app-05UKts6YyVXBufMPQhp4Ew==/base.apk (offset 0x3853000)
09-23 19:16:32.682 14123 14123 F DEBUG   :     #03 pc 00000000000a0154  /data/app/com.sergio_lever.my_flutter_app-05UKts6YyVXBufMPQhp4Ew==/base.apk (offset 0x3853000)
09-23 19:16:32.682 14123 14123 F DEBUG   :     #04 pc 000000000009d044  /data/app/com.sergio_lever.my_flutter_app-05UKts6YyVXBufMPQhp4Ew==/base.apk (offset 0x3853000)
09-23 19:16:32.682 14123 14123 F DEBUG   :     #05 pc 000000000009c914  /data/app/com.sergio_lever.my_flutter_app-05UKts6YyVXBufMPQhp4Ew==/base.apk (offset 0x3853000)
09-23 19:16:32.682 14123 14123 F DEBUG   :     #06 pc 000000000009c870  /data/app/com.sergio_lever.my_flutter_app-05UKts6YyVXBufMPQhp4Ew==/base.apk (offset 0x3853000)
09-23 19:16:32.682 14123 14123 F DEBUG   :     #07 pc 00000000007a25d0  /data/app/com.sergio_lever.my_flutter_app-05UKts6YyVXBufMPQhp4Ew==/base.apk (offset 0xaef5000)
09-23 19:16:32.684 14123 14123 F DEBUG   :     #08 pc 00000000007a0ad4  /data/app/com.sergio_lever.my_flutter_app-05UKts6YyVXBufMPQhp4Ew==/base.apk (offset 0xaef5000)
09-23 19:16:32.684 14123 14123 F DEBUG   :     #09 pc 00000000007a07e8  /data/app/com.sergio_lever.my_flutter_app-05UKts6YyVXBufMPQhp4Ew==/base.apk (offset 0xaef5000)
09-23 19:16:32.684 14123 14123 F DEBUG   :     #10 pc 00000000007a0b50  /data/app/com.sergio_lever.my_flutter_app-05UKts6YyVXBufMPQhp4Ew==/base.apk (offset 0xaef5000)
09-23 19:16:32.684 14123 14123 F DEBUG   :     #11 pc 00000000007a1890  /data/app/com.sergio_lever.my_flutter_app-05UKts6YyVXBufMPQhp4Ew==/base.apk (offset 0xaef5000)
09-23 19:16:32.684 14123 14123 F DEBUG   :     #12 pc 000000000000c46c  /data/app/com.sergio_lever.my_flutter_app-05UKts6YyVXBufMPQhp4Ew==/oat/arm64/base.odex (offset 0xa000)
09-23 19:16:33.509  1136  1136 E /system/bin/tombstoned: Tombstone written to: /data/tombstones//tombstone_00

I'm supposing that both on release and debug mode I get the same backtrace. So, if some user of the app sends me this backtrace (which I believe is sent through google play send feedback option when the app crashes), is there a way for me to find the actual names of the functions? Maybe looking at the offsets?

If it's possible, why wont logcat show the true names of the functions in the backtrace at least for my debug version of the app?

UPDATE:

I found ndk-stack utility, I tried:

adb logcat | $ANDROID_NDK_HOME/ndk-stack -sym $PWD/android/app/.cxx/cmake/debug/armeabi-v7a/

Android NDK site recommends

adb logcat | $NDK/ndk-stack -sym $PROJECT_PATH/obj/local/armeabi-v7a

but I did not find $PROJECT_PATH/obj/local/armeabi-v7a

The ndk-stack tool gives me this output:

Build fingerprint: 'motorola/griffin/griffin:8.0.0/OPL27.76-71-2-3/3:user/release-keys'
#00 0x00000000007b89b4 /data/app/com.sergio.my_flutter_app-P3kaX9v7DTNaKtQvm2Eotg==/base.apk (offset 0x4716000)
#01 0x00000000007b9ca0 /data/app/com.sergio.my_flutter_app-P3kaX9v7DTNaKtQvm2Eotg==/base.apk (offset 0x4716000)
#02 0x00000000007bb03c /data/app/com.sergio.my_flutter_app-P3kaX9v7DTNaKtQvm2Eotg==/base.apk (offset 0x4716000)
#03 0x00000000007baf78 /data/app/com.sergio.my_flutter_app-P3kaX9v7DTNaKtQvm2Eotg==/base.apk (offset 0x4716000)
#04 0x00000000007bac18 /data/app/com.sergio.my_flutter_app-P3kaX9v7DTNaKtQvm2Eotg==/base.apk (offset 0x4716000)
#05 0x000000000006637c /system/lib64/libc.so (_ZL15__pthread_startPv+36)
#06 0x000000000001f178 /system/lib64/libc.so (__start_thread+68)
Crash dump is completed

but this does not show the name of the functions in the backtrace.

Possible reason: there are no .o or .a files in $PWD/android/app/.cxx/cmake/debug/armeabi-v7a/

I also tried

adb logcat | $ANDROID_NDK_HOME/ndk-stack -sym $PWD/build/app/intermediates/merged_native_libs/debug/out/lib/armeabi-v7a

In that folder, indeed there exists my .so file so I think it's the right place. However I get the same output as before: no names for the backtrace functins.



from Is it possible to locate function names from a C++ backtrace from Android app?

No comments:

Post a Comment