环境
Mac、breakpad源码、minidump_stackwalk
步骤
NDK编写崩溃操作
/**
* 引起 crash
*/
void Crash() {
volatile int *a = (int *) (NULL);
*a = 1;
}
extern "C"
JNIEXPORT void JNICALL
Java_com_dodola_breakpad_MainActivity_crash(JNIEnv *env, jobject obj) {
Crash();
}
通过cmake编译breakpad源码
cmake配置
cmake_minimum_required(VERSION 3.4.1)
project(breakpad-core)
set(ENABLE_INPROCESS ON)
set(ENABLE_OUTOFPROCESS ON)
set(ENABLE_LIBCORKSCREW ON)
set(ENABLE_LIBUNWIND ON)
set(ENABLE_LIBUNWINDSTACK ON)
set(ENABLE_CXXABI ON)
set(ENABLE_STACKSCAN ON)
if (${ENABLE_INPROCESS})
add_definitions(-DENABLE_INPROCESS)
endif ()
if (${ENABLE_OUTOFPROCESS})
add_definitions(-DENABLE_OUTOFPROCESS)
endif ()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=implicit-function-declaration")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ")
# breakpad
include_directories(external/libbreakpad/src external/libbreakpad/src/common/android/include)
add_subdirectory(external/libbreakpad)
list(APPEND LINK_LIBRARIES breakpad)
add_library(breakpad-core SHARED
breakpad.cpp)
target_link_libraries(breakpad-core ${LINK_LIBRARIES}
log)
通过Android studio的/Applications/Android Studio.app/Contents/bin/lldb/bin目录,可以找到minidump_stackwalk进行一个dump日志的的查看
命令:
minidump_stackwalk 1.dmp >crashLog.txt
日志结果:
Operating system: Android
0.0.0 Linux 4.9.97 #1 SMP PREEMPT Fri Apr 12 21:02:27 CST 2019 aarch64
CPU: arm64
8 CPUs
Crash reason: SIGSEGV
Crash address: 0x0
Process uptime: not available
Thread 0 (crashed)
0 libcrash-lib.so + 0x5e0
x0 = 0x00000077374bf460 x1 = 0x0000007fdd8aab14
x2 = 0x0000007fdd8aabb0 x3 = 0x0000007734bd6f98
x4 = 0x0000007fdd8aadd0 x5 = 0x00000077348c4218
x6 = 0x0000007fdd8aa960 x7 = 0x000000771936be18
x8 = 0x0000000000000001 x9 = 0x0000000000000000
x10 = 0x0000000000430000 x11 = 0x0000007734fab6d8
x12 = 0x00000077bd85f530 x13 = 0x66911f3b52ec0dff
x14 = 0x00000077bd79c000 x15 = 0xffffffffffffffff
x16 = 0x0000007718c67fe8 x17 = 0x0000007718c575cc
x18 = 0x0000000000000001 x19 = 0x0000007737414c00
x20 = 0x0000000000000000 x21 = 0x0000007737414c00
x22 = 0x0000007fdd8aade0 x23 = 0x00000077193de661
x24 = 0x0000000000000004 x25 = 0x00000077bdbd05e0
x26 = 0x0000007737414ca0 x27 = 0x0000000000000001
x28 = 0x0000007fdd8aab10 fp = 0x0000007fdd8aaae0
lr = 0x0000007718c57604 sp = 0x0000007fdd8aaac0
pc = 0x0000007718c575e0
Found by: given as instruction pointer in context
1 libcrash-lib.so + 0x600
fp = 0x0000007fdd8aab10 lr = 0x0000007734ed0fe4
sp = 0x0000007fdd8aaaf0 pc = 0x0000007718c57604
Found by: previous frame's frame pointer
2 libart.so + 0x577fe0
fp = 0x1330a83800000001 lr = 0x00000077bdbd05e0
sp = 0x0000007fdd8aab20 pc = 0x0000007734ed0fe4
Found by: previous frame's frame pointer