使用ndk stack定位so庫crash位置

2021-08-22 10:33:57 字數 3208 閱讀 4989

ndk-stack 工具讓您可以在堆疊追蹤出現在 adb logcat 的輸出中時過濾它們。 它還可以從源**將共享庫中的任意位址替換為對應的< source-file: < line-number> 值,從而更容易找出問題所在。

例如,它可將下面的crash log:

i/debug   (   31): ***

******

******

******

******

******

******

******

***i/debug ( 31): build fingerprint: 'generic/google_sdk/generic/:2.2/frf91/43546:eng/test-keys'

i/debug ( 31): pid: 351, tid: 351

%gt;%

gt;%

gt; /data/local/ndk-tests/crasher <<<

i/debug ( 31): signal 11 (sigsegv), fault addr 0d9f00d8

i/debug ( 31): r0 0000af88 r1 0000a008 r2 baadf00d r3 0d9f00d8

i/debug ( 31): r4 00000004 r5 0000a008 r6 0000af88 r7 00013c44

i/debug ( 31): r8 00000000 r9 00000000

1000000000 fp 00000000

i/debug ( 31): ip 0000959c sp be956cc8 lr 00008403 pc 0000841e cpsr 60000030

i/debug ( 31): #00 pc 0000841e /data/local/ndk-tests/crasher

i/debug ( 31): #01 pc 000083fe /data/local/ndk-tests/crasher

i/debug ( 31): #02 pc 000083f6 /data/local/ndk-tests/crasher

i/debug ( 31): #03 pc 000191ac /system/lib/libc.so

i/debug ( 31): #04 pc 000083ea /data/local/ndk-tests/crasher

i/debug ( 31): #05 pc 00008458 /data/local/ndk-tests/crasher

i/debug ( 31): #06 pc 0000d362 /system/lib/libc.so

i/debug ( 31):

轉換為帶檔名、函式名和行號的log:

********** crash dump: **********

build fingerprint: 'generic/google_sdk/generic/:2.2/frf91/43546:eng/test-keys'

pid: 351, tid: 351

>>> /data/local/ndk-tests/crasher <<<

signal 11 (sigsegv), fault addr 0d9f00d8

stack frame #00 pc 0000841e /data/local/ndk-tests/crasher : routine zoo in /tmp/foo/crasher/jni/zoo.c:13

stack frame #01 pc 000083fe /data/local/ndk-tests/crasher : routine bar in /tmp/foo/crasher/jni/bar.c:5

stack frame #02 pc 000083f6 /data/local/ndk-tests/crasher : routine my_comparison in /tmp/foo/crasher/jni/foo.c:9

stack frame #03 pc 000191ac /system/lib/libc.so

stack frame #04 pc 000083ea /data/local/ndk-tests/crasher : routine foo in /tmp/foo/crasher/jni/foo.c:14

stack frame #05 pc 00008458 /data/local/ndk-tests/crasher : routine main in /tmp/foo/crasher/jni/main.c:19

stack frame #06 pc 0000d362 /system/lib/libc.so

用法

若要使用 ndk-stack,首先,需要乙個包含應用共享庫的符號版本。 如果使用 ndk 構建系統 (ndk-build),則這些共享庫檔案位於 $project_path/obj/local/ 下,其中 表示您的裝置的 abi。 預設情況下,系統使用 armeabi abi。

可通過兩種方式使用此工具。可以將 logcat 文字作為直接輸入傳送到程式。例如:

adb logcat |

$ndk/ndk-stack

-sym

$project_path/obj/local/armeabi

也可以使用 -dump 選項將 logcat 指定為輸入檔案。例如:

adb logcat > /tmp/foo.txt

$ndk/ndk-stack

-sym

$project_path/obj/local/armeabi -dump foo.txt

該工具在開始解析 logcat 輸出時將查詢第一行星號。例如:

*** **

* *** **

* *** **

* *** **

* *** **

* *** **

* *** **

* *** ***

注:在複製/貼上log時,請別忘了此行,否則 ndk-stack 無法正常工作。

ndk stack 定位錯誤 動態載入的so

我們一般都是使用ndk stack 定位libs下的so錯誤,動態載入sd卡上的so時不能 多次load了,否則會出現定位位置出錯。操作命令 adb路徑 adb logcat ndk stack路徑 ndk stack sym 專案jni路徑 obj local armeabi v7a 或者arme...

ndk stack使用方法

過去用eclipse跑cocos2d android崩潰了只能出乙個fatal signal訊號,現在有了ndk stack好了一點點,能定位到哪個函式崩潰了,用法如下 我的cocos2d x android工程在 d works demo hellococos proj.android目錄下,nd...

使用ndk stack來查詢崩潰

logcat報錯 fatal signal 6 sigabrt at 0x000025c9 code 6 thread 9703 thread 1277 都是一些暫存器以及函式位址,真不知道怎麼找具體哪個函式出錯了,這個時候使用ndk stack這個工具,ndk stack需要log作為輸入來分析 ...