Android NDK(五)- ndk-stack 还原堆栈信息

native 的崩溃相比于 java 很难看懂,对于排查问题很不利。不过我们可以通过 NDK 中的工具 ndk-stack 来还原堆栈信息。

先制造一个异常:

extern "C"
JNIEXPORT void JNICALL
Java_com_teletian_sample_myndk_MainActivity_testCrash(JNIEnv *env, jobject thiz) {
    int* i = NULL;
    i[0] = 0;
}

运行之后出现崩溃,信息如下:

--------- beginning of crash
06-18 11:45:55.554 13648 13648 F libc    : Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 13648 (an.sample.myndk), pid 13648 (an.sample.myndk)
06-18 11:45:55.577 13683 13683 I crash_dump32: obtaining output fd from tombstoned, type: kDebuggerdTombstone
06-18 11:45:55.577  1820  1820 I /system/bin/tombstoned: received crash request for pid 13648
06-18 11:45:55.579 13683 13683 I crash_dump32: performing dump of process 13648 (target tid = 13648)
06-18 11:45:55.584 13683 13683 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-18 11:45:55.584 13683 13683 F DEBUG   : Build fingerprint: 'google/sdk_gphone_x86/generic_x86:10/QSR1.210802.001/7603624:userdebug/dev-keys'
06-18 11:45:55.584 13683 13683 F DEBUG   : Revision: '0'
06-18 11:45:55.584 13683 13683 F DEBUG   : ABI: 'x86'
06-18 11:45:55.584 13683 13683 F DEBUG   : Timestamp: 2022-06-18 11:45:55+0800
06-18 11:45:55.584 13683 13683 F DEBUG   : pid: 13648, tid: 13648, name: an.sample.myndk  >>> com.teletian.sample.myndk <<<
06-18 11:45:55.584 13683 13683 F DEBUG   : uid: 10146
06-18 11:45:55.584 13683 13683 F DEBUG   : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
06-18 11:45:55.584 13683 13683 F DEBUG   : Cause: null pointer dereference
06-18 11:45:55.584 13683 13683 F DEBUG   :     eax 00000000  ebx 0000000c  ecx ecb8dfc0  edx ff9f45e0
06-18 11:45:55.584 13683 13683 F DEBUG   :     edi ff9f47cc  esi ece565bb
06-18 11:45:55.584 13683 13683 F DEBUG   :     ebp ff9f45d8  esp ff9f45d0  eip c1a1d47b
06-18 11:45:55.742 13683 13683 F DEBUG   : 
06-18 11:45:55.742 13683 13683 F DEBUG   : backtrace:
06-18 11:45:55.742 13683 13683 F DEBUG   :       #00 pc 0000047b  /data/app/com.teletian.sample.myndk-XGWmLhI8hu8vJdkaA7VHEQ==/lib/x86/libmyndk.so (Java_com_teletian_sample_myndk_MainActivity_testCrash+27) (BuildId: 24293db346fab188b0e1c453f33aa6777f9f0be6)
06-18 11:45:55.742 13683 13683 F DEBUG   :       #01 pc 00144f67  /apex/com.android.runtime/lib/libart.so (art_quick_generic_jni_trampoline+71) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.742 13683 13683 F DEBUG   :       #02 pc 0013e7d2  /apex/com.android.runtime/lib/libart.so (art_quick_invoke_stub+338) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.742 13683 13683 F DEBUG   :       #03 pc 00149a69  /apex/com.android.runtime/lib/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+281) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.742 13683 13683 F DEBUG   :       #04 pc 00332542  /apex/com.android.runtime/lib/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)+386) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.742 13683 13683 F DEBUG   :       #05 pc 0032c1dc  /apex/com.android.runtime/lib/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+988) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.742 13683 13683 F DEBUG   :       #06 pc 0068191d  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+989) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.742 13683 13683 F DEBUG   :       #07 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.742 13683 13683 F DEBUG   :       #08 pc 0000035c  [anon:dalvik-classes3.dex extracted in memory from /data/app/com.teletian.sample.myndk-XGWmLhI8hu8vJdkaA7VHEQ==/base.apk!classes3.dex] (com.teletian.sample.myndk.MainActivity.onCreate+40)
06-18 11:45:55.743 13683 13683 F DEBUG   :       #09 pc 00681b8c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.743 13683 13683 F DEBUG   :       #10 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.743 13683 13683 F DEBUG   :       #11 pc 0019176e  /system/framework/framework.jar (android.app.Activity.performCreate+30)
06-18 11:45:55.743 13683 13683 F DEBUG   :       #12 pc 00681b8c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.743 13683 13683 F DEBUG   :       #13 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.743 13683 13683 F DEBUG   :       #14 pc 00191736  /system/framework/framework.jar (android.app.Activity.performCreate+2)
06-18 11:45:55.743 13683 13683 F DEBUG   :       #15 pc 00681b8c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.743 13683 13683 F DEBUG   :       #16 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.744 13683 13683 F DEBUG   :       #17 pc 001eefea  /system/framework/framework.jar (android.app.Instrumentation.callActivityOnCreate+6)
06-18 11:45:55.744 13683 13683 F DEBUG   :       #18 pc 00681b8c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.744 13683 13683 F DEBUG   :       #19 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.744 13683 13683 F DEBUG   :       #20 pc 00180bc8  /system/framework/framework.jar (android.app.ActivityThread.performLaunchActivity+752)
06-18 11:45:55.744 13683 13683 F DEBUG   :       #21 pc 0068465c  /apex/com.android.runtime/lib/libart.so (MterpInvokeDirect+1324) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.744 13683 13683 F DEBUG   :       #22 pc 00138921  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_direct+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.744 13683 13683 F DEBUG   :       #23 pc 00180846  /system/framework/framework.jar (android.app.ActivityThread.handleLaunchActivity+94)
06-18 11:45:55.744 13683 13683 F DEBUG   :       #24 pc 00681b8c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.744 13683 13683 F DEBUG   :       #25 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.744 13683 13683 F DEBUG   :       #26 pc 0025e29e  /system/framework/framework.jar (android.app.servertransaction.LaunchActivityItem.execute+126)
06-18 11:45:55.744 13683 13683 F DEBUG   :       #27 pc 00681b8c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.744 13683 13683 F DEBUG   :       #28 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.744 13683 13683 F DEBUG   :       #29 pc 002607ea  /system/framework/framework.jar (android.app.servertransaction.TransactionExecutor.executeCallbacks+154)
06-18 11:45:55.744 13683 13683 F DEBUG   :       #30 pc 00681b8c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.744 13683 13683 F DEBUG   :       #31 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.744 13683 13683 F DEBUG   :       #32 pc 00260726  /system/framework/framework.jar (android.app.servertransaction.TransactionExecutor.execute+146)
06-18 11:45:55.744 13683 13683 F DEBUG   :       #33 pc 00681b8c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.744 13683 13683 F DEBUG   :       #34 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.744 13683 13683 F DEBUG   :       #35 pc 0017fb7e  /system/framework/framework.jar (android.app.ActivityThread$H.handleMessage+78)
06-18 11:45:55.744 13683 13683 F DEBUG   :       #36 pc 00681b8c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.744 13683 13683 F DEBUG   :       #37 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.745 13683 13683 F DEBUG   :       #38 pc 002f58a2  /system/framework/framework.jar (android.os.Handler.dispatchMessage+38)
06-18 11:45:55.746 13683 13683 F DEBUG   :       #39 pc 00681b8c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.746 13683 13683 F DEBUG   :       #40 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.746 13683 13683 F DEBUG   :       #41 pc 00319f42  /system/framework/framework.jar (android.os.Looper.loop+466)
06-18 11:45:55.746 13683 13683 F DEBUG   :       #42 pc 0068501c  /apex/com.android.runtime/lib/libart.so (MterpInvokeStatic+1260) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.746 13683 13683 F DEBUG   :       #43 pc 001389a1  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_static+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.746 13683 13683 F DEBUG   :       #44 pc 00189476  /system/framework/framework.jar (android.app.ActivityThread.main+194)
06-18 11:45:55.746 13683 13683 F DEBUG   :       #45 pc 002f8e4a  /apex/com.android.runtime/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_6JValueEbb.llvm.14394197428592071423+298) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.746 13683 13683 F DEBUG   :       #46 pc 002ffd05  /apex/com.android.runtime/lib/libart.so (art::interpreter::EnterInterpreterFromEntryPoint(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*)+181) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.746 13683 13683 F DEBUG   :       #47 pc 0066fc89  /apex/com.android.runtime/lib/libart.so (artQuickToInterpreterBridge+1209) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.746 13683 13683 F DEBUG   :       #48 pc 0014503d  /apex/com.android.runtime/lib/libart.so (art_quick_to_interpreter_bridge+77) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.746 13683 13683 F DEBUG   :       #49 pc 0013e9a2  /apex/com.android.runtime/lib/libart.so (art_quick_invoke_static_stub+418) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.746 13683 13683 F DEBUG   :       #50 pc 00149a7a  /apex/com.android.runtime/lib/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+298) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.746 13683 13683 F DEBUG   :       #51 pc 0055a5a3  /apex/com.android.runtime/lib/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod*, art::(anonymous namespace)::ArgArray*, art::JValue*, char const*)+99) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.746 13683 13683 F DEBUG   :       #52 pc 0055c3bf  /apex/com.android.runtime/lib/libart.so (art::InvokeMethod(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jobject*, _jobject*, unsigned int)+1327) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.746 13683 13683 F DEBUG   :       #53 pc 004c91e3  /apex/com.android.runtime/lib/libart.so (art::Method_invoke(_JNIEnv*, _jobject*, _jobject*, _jobjectArray*)+83) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.746 13683 13683 F DEBUG   :       #54 pc 000c6bf8  /system/framework/x86/boot.oat (art_jni_trampoline+168) (BuildId: 7913dbaef2e8d9971cb7619ef0d566987f8326a7)
06-18 11:45:55.746 13683 13683 F DEBUG   :       #55 pc 0013e7d2  /apex/com.android.runtime/lib/libart.so (art_quick_invoke_stub+338) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.746 13683 13683 F DEBUG   :       #56 pc 00149a69  /apex/com.android.runtime/lib/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+281) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.746 13683 13683 F DEBUG   :       #57 pc 00332542  /apex/com.android.runtime/lib/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)+386) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.746 13683 13683 F DEBUG   :       #58 pc 0032c1dc  /apex/com.android.runtime/lib/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+988) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.746 13683 13683 F DEBUG   :       #59 pc 0068191d  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+989) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.746 13683 13683 F DEBUG   :       #60 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.747 13683 13683 F DEBUG   :       #61 pc 0034cde6  /system/framework/framework.jar (com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run+22)
06-18 11:45:55.747 13683 13683 F DEBUG   :       #62 pc 002f8e4a  /apex/com.android.runtime/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_6JValueEbb.llvm.14394197428592071423+298) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.747 13683 13683 F DEBUG   :       #63 pc 002ffd05  /apex/com.android.runtime/lib/libart.so (art::interpreter::EnterInterpreterFromEntryPoint(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*)+181) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.747 13683 13683 F DEBUG   :       #64 pc 0066fc89  /apex/com.android.runtime/lib/libart.so (artQuickToInterpreterBridge+1209) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.747 13683 13683 F DEBUG   :       #65 pc 0014503d  /apex/com.android.runtime/lib/libart.so (art_quick_to_interpreter_bridge+77) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.747 13683 13683 F DEBUG   :       #66 pc 00998b58  /system/framework/x86/boot-framework.oat (com.android.internal.os.ZygoteInit.main+1816) (BuildId: 38176ebc9c3cce5f657a723b08d40d487952c484)
06-18 11:45:55.747 13683 13683 F DEBUG   :       #67 pc 0013e9a2  /apex/com.android.runtime/lib/libart.so (art_quick_invoke_static_stub+418) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.748 13683 13683 F DEBUG   :       #68 pc 00149a7a  /apex/com.android.runtime/lib/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+298) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.748 13683 13683 F DEBUG   :       #69 pc 0055a5a3  /apex/com.android.runtime/lib/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod*, art::(anonymous namespace)::ArgArray*, art::JValue*, char const*)+99) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.748 13683 13683 F DEBUG   :       #70 pc 0055a23e  /apex/com.android.runtime/lib/libart.so (art::InvokeWithVarArgs(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jmethodID*, char*)+430) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.748 13683 13683 F DEBUG   :       #71 pc 0043060d  /apex/com.android.runtime/lib/libart.so (art::JNI::CallStaticVoidMethodV(_JNIEnv*, _jclass*, _jmethodID*, char*)+893) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
06-18 11:45:55.748 13683 13683 F DEBUG   :       #72 pc 000b25fe  /system/lib/libandroid_runtime.so (_JNIEnv::CallStaticVoidMethod(_jclass*, _jmethodID*, ...)+62) (BuildId: 3643bee2c4fb7899d7781c565843060b)
06-18 11:45:55.748 13683 13683 F DEBUG   :       #73 pc 000b628a  /system/lib/libandroid_runtime.so (android::AndroidRuntime::start(char const*, android::Vector<android::String8> const&, bool)+794) (BuildId: 3643bee2c4fb7899d7781c565843060b)
06-18 11:45:55.748 13683 13683 F DEBUG   :       #74 pc 00003632  /system/bin/app_process32 (main+1490) (BuildId: b7a60bc7d078521421fd5a8d201915ae)
06-18 11:45:55.748 13683 13683 F DEBUG   :       #75 pc 000898e8  /apex/com.android.runtime/lib/bionic/libc.so (__libc_init+120) (BuildId: 471745f0fbbcedb3db1553d5bd6fcd8b)

这个崩溃信息只能看到 Java_com_teletian_sample_myndk_MainActivity_testCrash+27 这个方法出现崩溃了,具体那一行也不知道。

下面我们来通过 ndk-stack 这个工具还原堆栈信息看看。

1. 先将崩溃信息保存为文件,再通过文件还原
adb logcat -c
adb logcat > crash.log
ndk-stack -sym app/build/intermediates/cmake/debug/obj/x86/ -dump crash.log

还原出来的信息如下:

********** Crash dump: **********
Build fingerprint: 'google/sdk_gphone_x86/generic_x86:10/QSR1.210802.001/7603624:userdebug/dev-keys'
#00 0x0000047b /data/app/com.teletian.sample.myndk-XGWmLhI8hu8vJdkaA7VHEQ==/lib/x86/libmyndk.so (Java_com_teletian_sample_myndk_MainActivity_testCrash+27) (BuildId: 24293db346fab188b0e1c453f33aa6777f9f0be6)
                                                                                                 Java_com_teletian_sample_myndk_MainActivity_testCrash
                                                                                                 /Users/tianjf/Android/AndroidStudioProjects/MyNDK/app/src/main/cpp/native-lib.cpp:8:10
#01 0x00144f67 /apex/com.android.runtime/lib/libart.so (art_quick_generic_jni_trampoline+71) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#02 0x0013e7d2 /apex/com.android.runtime/lib/libart.so (art_quick_invoke_stub+338) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#03 0x00149a69 /apex/com.android.runtime/lib/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+281) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#04 0x00332542 /apex/com.android.runtime/lib/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)+386) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#05 0x0032c1dc /apex/com.android.runtime/lib/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+988) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#06 0x0068191d /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+989) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#07 0x00138821 /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#08 0x0000035c [anon:dalvik-classes3.dex extracted in memory from /data/app/com.teletian.sample.myndk-XGWmLhI8hu8vJdkaA7VHEQ==/base.apk!classes3.dex] (com.teletian.sample.myndk.MainActivity.onCreate+40)
#09 0x00681b8c /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#10 0x00138821 /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#11 0x0019176e /system/framework/framework.jar (android.app.Activity.performCreate+30)
#12 0x00681b8c /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#13 0x00138821 /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#14 0x00191736 /system/framework/framework.jar (android.app.Activity.performCreate+2)
#15 0x00681b8c /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#16 0x00138821 /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#17 0x001eefea /system/framework/framework.jar (android.app.Instrumentation.callActivityOnCreate+6)
#18 0x00681b8c /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#19 0x00138821 /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#20 0x00180bc8 /system/framework/framework.jar (android.app.ActivityThread.performLaunchActivity+752)
#21 0x0068465c /apex/com.android.runtime/lib/libart.so (MterpInvokeDirect+1324) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#22 0x00138921 /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_direct+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#23 0x00180846 /system/framework/framework.jar (android.app.ActivityThread.handleLaunchActivity+94)
#24 0x00681b8c /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#25 0x00138821 /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#26 0x0025e29e /system/framework/framework.jar (android.app.servertransaction.LaunchActivityItem.execute+126)
#27 0x00681b8c /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#28 0x00138821 /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#29 0x002607ea /system/framework/framework.jar (android.app.servertransaction.TransactionExecutor.executeCallbacks+154)
#30 0x00681b8c /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#31 0x00138821 /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#32 0x00260726 /system/framework/framework.jar (android.app.servertransaction.TransactionExecutor.execute+146)
#33 0x00681b8c /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#34 0x00138821 /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#35 0x0017fb7e /system/framework/framework.jar (android.app.ActivityThread$H.handleMessage+78)
#36 0x00681b8c /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#37 0x00138821 /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#38 0x002f58a2 /system/framework/framework.jar (android.os.Handler.dispatchMessage+38)
#39 0x00681b8c /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#40 0x00138821 /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#41 0x00319f42 /system/framework/framework.jar (android.os.Looper.loop+466)
#42 0x0068501c /apex/com.android.runtime/lib/libart.so (MterpInvokeStatic+1260) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#43 0x001389a1 /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_static+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#44 0x00189476 /system/framework/framework.jar (android.app.ActivityThread.main+194)
#45 0x002f8e4a /apex/com.android.runtime/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_6JValueEbb.llvm.14394197428592071423+298) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#46 0x002ffd05 /apex/com.android.runtime/lib/libart.so (art::interpreter::EnterInterpreterFromEntryPoint(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*)+181) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#47 0x0066fc89 /apex/com.android.runtime/lib/libart.so (artQuickToInterpreterBridge+1209) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#48 0x0014503d /apex/com.android.runtime/lib/libart.so (art_quick_to_interpreter_bridge+77) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#49 0x0013e9a2 /apex/com.android.runtime/lib/libart.so (art_quick_invoke_static_stub+418) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#50 0x00149a7a /apex/com.android.runtime/lib/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+298) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#51 0x0055a5a3 /apex/com.android.runtime/lib/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod*, art::(anonymous namespace)::ArgArray*, art::JValue*, char const*)+99) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#52 0x0055c3bf /apex/com.android.runtime/lib/libart.so (art::InvokeMethod(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jobject*, _jobject*, unsigned int)+1327) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#53 0x004c91e3 /apex/com.android.runtime/lib/libart.so (art::Method_invoke(_JNIEnv*, _jobject*, _jobject*, _jobjectArray*)+83) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#54 0x000c6bf8 /system/framework/x86/boot.oat (art_jni_trampoline+168) (BuildId: 7913dbaef2e8d9971cb7619ef0d566987f8326a7)
#55 0x0013e7d2 /apex/com.android.runtime/lib/libart.so (art_quick_invoke_stub+338) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#56 0x00149a69 /apex/com.android.runtime/lib/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+281) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#57 0x00332542 /apex/com.android.runtime/lib/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)+386) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#58 0x0032c1dc /apex/com.android.runtime/lib/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+988) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#59 0x0068191d /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+989) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#60 0x00138821 /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#61 0x0034cde6 /system/framework/framework.jar (com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run+22)
#62 0x002f8e4a /apex/com.android.runtime/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_6JValueEbb.llvm.14394197428592071423+298) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#63 0x002ffd05 /apex/com.android.runtime/lib/libart.so (art::interpreter::EnterInterpreterFromEntryPoint(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*)+181) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#64 0x0066fc89 /apex/com.android.runtime/lib/libart.so (artQuickToInterpreterBridge+1209) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#65 0x0014503d /apex/com.android.runtime/lib/libart.so (art_quick_to_interpreter_bridge+77) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#66 0x00998b58 /system/framework/x86/boot-framework.oat (com.android.internal.os.ZygoteInit.main+1816) (BuildId: 38176ebc9c3cce5f657a723b08d40d487952c484)
#67 0x0013e9a2 /apex/com.android.runtime/lib/libart.so (art_quick_invoke_static_stub+418) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#68 0x00149a7a /apex/com.android.runtime/lib/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+298) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#69 0x0055a5a3 /apex/com.android.runtime/lib/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod*, art::(anonymous namespace)::ArgArray*, art::JValue*, char const*)+99) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#70 0x0055a23e /apex/com.android.runtime/lib/libart.so (art::InvokeWithVarArgs(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jmethodID*, char*)+430) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#71 0x0043060d /apex/com.android.runtime/lib/libart.so (art::JNI::CallStaticVoidMethodV(_JNIEnv*, _jclass*, _jmethodID*, char*)+893) (BuildId: 26b0fc8885e87fc8f11e1081b83a9b8e)
#72 0x000b25fe /system/lib/libandroid_runtime.so (_JNIEnv::CallStaticVoidMethod(_jclass*, _jmethodID*, ...)+62) (BuildId: 3643bee2c4fb7899d7781c565843060b)
#73 0x000b628a /system/lib/libandroid_runtime.so (android::AndroidRuntime::start(char const*, android::Vector<android::String8> const&, bool)+794) (BuildId: 3643bee2c4fb7899d7781c565843060b)
#74 0x00003632 /system/bin/app_process32 (main+1490) (BuildId: b7a60bc7d078521421fd5a8d201915ae)
#75 0x000898e8 /apex/com.android.runtime/lib/bionic/libc.so (__libc_init+120) (BuildId: 471745f0fbbcedb3db1553d5bd6fcd8b)
Crash dump is completed

可以看到,还原的信息中出现了 native-lib.cpp:8:10,这样就可以知道是哪一行出错了。如果你是在 Android Stduio 的 Terminal 窗口中执行的命令,还能直接点击跳转到出现问题的那一行,很方便。

2. 直接在 logcat 中还原
adb logcat -c
adb logcat | ndk-stack -sym app/build/intermediates/cmake/debug/obj/x86

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,053评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,527评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,779评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,685评论 1 276
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,699评论 5 366
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,609评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,989评论 3 396
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,654评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,890评论 1 298
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,634评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,716评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,394评论 4 319
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,976评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,950评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,191评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 44,849评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,458评论 2 342

推荐阅读更多精彩内容