Android NDK- ndk-stack 还原堆栈信息
Posted teletian
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
以上是关于Android NDK- ndk-stack 还原堆栈信息的主要内容,如果未能解决你的问题,请参考以下文章
制作一个异常的 so 包,并利用 ndk-stack 分析 native 层的 Crash 日志
Android处理native crash(ndk-stack和addr2line)
我的Android进阶之旅如何在Android Studio开发NDK的时候,通过addr2line或者ndk-stack来定位出错代码的位置