One, background
As we all know, Crash problem Android JNI layer is a troublesome issue. Java opposing layers, crash since the c / c ++ is not output as the result of
Java's Exception Strace, so the positioning of the crash is a more difficult matter. Google Breakpad is a complete set of tools from the crash of
Captured the crash dump, it provides the corresponding tools.
Second, the purpose: when a crash program, crash program to collect information, to locate a place to crash
Third, the program
Google breakpad is a crash dump and analytical framework and tools for cross-platform collection.
Breakpad consists of three main components:
Client , in the form of built-in library of your application, write minidump file when a crash occurs
Symbol Dumper , reads debugging information (debugging information) generated by the compiler, and generates a symbol file
Processor , read the minidump file and symbol file generating readable c / c ++ Stack trace.
Is simply to generate a minidump, generates a symbol file, and then merge processing into readable Stack trace.
Fourth, integration
1. cloning or download breakpad open source libraries: https: //github.com/google/breakpad.git
2. Go to the root directory of execution:
$ cd breakpad $ ./configure && make
` The make after :
Libbreakpad_client.a generate static library file [libbreakpad_client.a] (/ uploads / 33f43e7fad5ec0fa5358c5fc9373e1db / libbreakpad_client.a) under src / client / linux directory, generate minidump_stackwalk tool [minidump_stackwalk] (/ uploads / 8b56c60770516b83344378e22ab64874 / minidump_stackwalk) under src / processor directory, for exporting crash log,
Generating dump_syms tool [dump_syms] (/ uploads / 05ca888d36dd5dfe4b0927e881ae775c / dump_syms) under src / tools / linux / dump_syms directory for deriving the symbol file.
3. There are two integrated manner, README.ANDROID under reference breakpad directory.
Note: This direct use sample_app, for the use of the app, you can directly include sample_app in jin of android.mk file
(1) .a compiled into library files, directly adding .a way to integrate
(2) use import-module, which allows the compiler to ndk
Used here (2) ways, android.mk detailed in documents jin sample_app directory [Android.mk] (/ uploads / bf07e5cc4ce46a87045203239a5eade4 / Android.mk)
(1) Direct Example / android / sample_app of
(2) adding a tag jni / Android.mk in
LOCAL_CPPFLAGS := -pie -fPIE -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
LOCAL_LDFLAGS := -pie -fPIE
android.mk See sample-app folder jin folder: Note
(3) adding the code main.cpp [test_breakpad.cpp] (/ uploads / 6becceec0fad8db20eda02f623ef9866 / test_breakpad.cpp)
#include <stdio.h> #include "client/linux/handler/exception_handler.h" #include "client/linux/handler/minidump_descriptor.h" namespace { bool DumpCallback(const google_breakpad::MinidumpDescriptor& descriptor,void* context, bool succeeded) {printf("Dump path: %s\n", descriptor.path()); return succeeded; } //this Crash is for test. if you add it into the project, delete it void Crash() { volatile int* a = reinterpret_cast<volatile int*>(NULL); *a = 1; } } // namespace int main(int argc, char* argv[]) { google_breakpad::MinidumpDescriptor descriptor("/sdcard"); google_breakpad::ExceptionHandler eh(descriptor, NULL, DumpCallback, NULL, true, -1); Crash(); //this is for test. if you add it into the project, delete it return 0; }
At this point, you can compile android cocos2d-x project, and the resulting crash files in / under sdcard, dmp file suffix
Five test
Build instructions:
$ cd android/sample_app $ ndk-build
Where $NDK points to a valid Android NDK installation. After executing "ndk-build", there will be many binary files named test_google_breakpad
Usage instructions:
After buildind the test program, send it to a device, then run it as
the shell UID:
$ adb push libs/armeabi/test_google_breakpad /data/local/tmp $ adb shell /data/local/tmp/test_google_breakpad
ps:However, you don"t have do these two steps, in that our shell of 'run_test' already has included them.
This will simply crash after dumping the name of the generated minidump
file.[a1ee9a8a-21bc-4e2b-85046fab-20468514.dmp](/uploads/52f61416273700a479a323df4d382412/a1ee9a8a-21bc-4e2b-85046fab-20468514.dmp)
And use the command of adb to pull the file of .dmp
See jni/test_breakpad.cpp for details.
Sixth, the results of analysis
Note: all of the things you need do is that to use the command of adb to pull the file of .dmp and to analysis it.
New sample_app Dump file in the directory, and copy command dump_syms minidump_stackwalk to the next Dump directory.
```
cp breakpad-master/src/tools/linux/dump_syms/dump_syms ./Dump
cp breakpad-master/src/processor/minidump_stackwalk ./Dump
```
File generation sym [test_google_breakpad.sym] (/ uploads / 54fa8d709f89fa17e5ba027ce44dc7c1 / test_google_breakpad.sym)
$ cd Dump
$ ./dump_syms test_google_breakpad > test_google_breakpad.sym
Note: In our APP in, test_google_breakpad in obj / local / armeabi-v7a directory, you need to copy the Dump directory
Dump the symbols in the new folder, create a new folder in the symbols test_google_breakpad folder, and then
test_google_breakpad new file folder to a hexadecimal string in the first line of the file named test_google_breakpad.sym
Folder, this file will test_google_breakpad.sym move to a hexadecimal string folder.
File generation crashed.log [crashed.log] (/ uploads / 79a0fdf3aebf28307c9caf98dba1d559 / crashed.log)
$ cd Dump
$ ./minidump_stackwalk xxxx-xxxx-xxxxx-xxxx.dmp symbols > crashed.log
Note: Make sure dmp file directory and symbols are of the same level
Crashed.log open the file, view the local program crash