-
Notifications
You must be signed in to change notification settings - Fork 68
Analyzing native crashes on Android
Mark Tehver edited this page Mar 7, 2022
·
1 revision
Native crashes on Android are hard to analyze. Logcat may contain lines like this:
#00 pc 00000000002d484c /data/app/~~gAdohKsYsR7ns_m6FQWiYA==/lib/arm/libcarto_mobile_sdk.so
#00 pc 00000000002d2699 /data/app/~~gAdohKsYsR7ns_m6FQWiYA==/lib/arm/libcarto_mobile_sdk.so
#00 pc 00000000001f605d /data/app/~~gAdohKsYsR7ns_m6FQWiYA==/lib/arm/libcarto_mobile_sdk.so
#00 pc 00000000001d1fe1 /data/app/~~gAdohKsYsR7ns_m6FQWiYA==/lib/arm/libcarto_mobile_sdk.so
#00 pc 00000000001bf8d3 /data/app/~~gAdohKsYsR7ns_m6FQWiYA==/lib/arm/libcarto_mobile_sdk.so
#00 pc 00000000001baa75 /data/app/~~gAdohKsYsR7ns_m6FQWiYA==/lib/arm/libcarto_mobile_sdk.so
#00 pc 0000000000210b23 /data/app/~~gAdohKsYsR7ns_m6FQWiYA==/lib/arm/libcarto_mobile_sdk.so
#00 pc 00000000001e9a77 /data/app/~~gAdohKsYsR7ns_m6FQWiYA==/lib/arm/libcarto_mobile_sdk.so
#00 pc 00000000000b0547 /apex/com.android.runtime/lib/bionic/libc.so (__pthread_start(void*)+40)
#00 pc 0000000000066b17 /apex/com.android.runtime/lib/bionic/libc.so (__start_thread+30)
This is a native stack trace but usually not very helpful, as it contains only native addresses. These addresses can be mapped to source code locations, though, by creating a duplicate build with full symbol info. We keep such builds for official SDK releases starting from SDK 4.4.5.
For custom builds, the following steps can be used:
- add
-g
flag toCMAKE_C_FLAGS_RELEASE
andCMAKE_CXX_FLAGS_RELEASE
in scripts/build/CMakeLists.txt - replace
-s
flag with-g
flag inCMAKE_SHARED_LINKER_FLAGS_RELEASE
- remove
-Wl,--build-id
flag fromCMAKE_SHARED_LINKER_FLAGS_RELEASE
- after the changes SDK should be built following the instructions in the building guide
- copy carto_mobile_sdk.so files found under build/android-arm64-v8a and build/android-armeabi-v7a directories to a separate location. These files are relatively large (200-500MB) and contain full debug symbol info needed for matching native addresses to source code locations.
- drop all the changes made in scripts/build/CMakeLists.txt, restore original file state
- remove
-Wl,--build-id
flag fromCMAKE_SHARED_LINKER_FLAGS_RELEASE
again - build the SDK again by following the instructions in the building guide. This build does not contain any debug symbol info but can be matched with the previously generated carto_mobile_sdk.so files.
When analyzing native crashes, ndk-stack
utility from Android NDK can be used afterwards:
cat crashlog.txt | ndk-stack -sym PATH_TO_DIRECTORY_CONTAINING_CARTO_MOBILE_SDK_SO_FILE
Detailed instructions can be found here.