ndk-stack 調試 android c++ 代碼崩潰位置

來源:互聯網
上載者:User

標籤:android   style   blog   http   color   使用   for   檔案   ar   

   在android下面使用jni來調用c++,在開發遊戲是非常正常的。但是要調試c++部分卻是非常麻煩的問題。如果快速定位崩潰位置呢。NDK提供了一個小工具ndk-stack.

首先,我們先配置環境,把NDK路徑和adb的路徑配置到環境變數中。如下面:

ADBPATH = F:\DevelopTools\adt-bundle-windows-x86_64-20131030\sdk\platform-tools

NDKROOT = F:\DevelopTools\android-ndk-r9d

Path = %path%;%NDKROOT %;%ADBPATH%;

 

接下, 去我們到工程的根目錄,執行以下命令:

adb logcat | ndk-stack -sym obj/local/armeabi

開始執行調試遊戲,出現下列錯誤

********** Crash dump: **********Build fingerprint: ‘generic/sdk/generic:2.3.3/GRI34/101070:eng/test-keys‘pid: 571, tid: 571  >>> com.example.hellojni <<<signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000Stack frame I/DEBUG   (   30):          #00  pc 00000eb0  /data/data/com.exampringFromJNI at C:\Users\zhangchuanwei\workspace1\hellojni/jni/hellojni.cpp:22Stack frame I/DEBUG   (   30):          #01  pc 00017d74  /system/lib/libdvm.sStack frame I/DEBUG   (   30):          #02  pc 00048f08  /system/lib/libdvm.sStack frame I/DEBUG   (   30):          #03  pc 00041ab6  /system/lib/libdvm.sStack frame I/DEBUG   (   30):          #04  pc 0002976c  /system/lib/libdvm.sStack frame I/DEBUG   (   30):          #05  pc 00021020  /system/lib/libdvm.sStack frame I/DEBUG   (   30):          #06  pc 0005f5de  /system/lib/libdvm.sStack frame I/DEBUG   (   30):          #07  pc 00066fce  /system/lib/libdvm.sStack frame I/DEBUG   (   30):          #08  pc 0001cfd4  /system/lib/libdvm.sStack frame I/DEBUG   (   30):          #09  pc 000220dc  /system/lib/libdvm.sStack frame I/DEBUG   (   30):          #10  pc 00020fd0  /system/lib/libdvm.sStack frame I/DEBUG   (   30):          #11  pc 0005f430  /system/lib/libdvm.sStack frame I/DEBUG   (   30):          #12  pc 0004b9a8  /system/lib/libdvm.sStack frame I/DEBUG   (   30):          #13  pc 0003ebb0  /system/lib/libdvm.sStack frame I/DEBUG   (   30):          #14  pc 000314ac  /system/lib/libandroStack frame I/DEBUG   (   30):          #15  pc 000322c6  /system/lib/libandroStack frame I/DEBUG   (   30):          #16  pc 00008ca2  /system/bin/app_procStack frame I/DEBUG   (   30):          #17  pc 00014db8  /system/lib/libc.so

直接可以看到我們的工程第22行有錯誤,看下22行是什麼

 

   18 struct strTest{   19     char* pstr;   20 };   21 strTest *ptest=NULL;   22 ptest->pstr=NULL;   23 return env->NewStringUTF("hello world returned.");

對於ndk-stack的使用可以看ndk根目錄下的docs/NDK-STACK.html檔案

源碼:http://files.cnblogs.com/chuanwei-zhang/hellojni-dynamic.zip

static const char* className = "com/example/hellojni/MainActivity";JNIEXPORT jstring JNICALL stringFromJNI(JNIEnv* env, jclass clazz){    //return env->NewStringUTF(env, "Hello form JNI!");    struct strTest{        char* pstr;    };    strTest *ptest=NULL;    ptest->pstr=NULL;    return env->NewStringUTF("hello world returned.");}

下載源碼,並替換hellojni.cpp裡面的上面這個函數,就可以重現上面問題了。

ndk-stack 調試 android c++ 代碼崩潰位置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.