How to Print Function Caller Stack in Android Log File

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How to Print Function Caller Stack in Android Log File

How to Print Function Caller Stack in Android Log File

Print caller stack may help you to analyze the program and find out the caller stack more easily.

You can write your code like this:

Java:

     Exception e = new Exception();

     Log.e(TAG,"xxx",e);

C++ file:

      #include <utils/Callstack.h>

     android::CallStack stack;

     stack.update(1,30);

     stacn.dump("xxx");

Then you can see the function's caller stack in Android main log file.

C file:

#include <corkscrew/backtrace.h>

#define MAX_DEPTH 31
#define MAX_BACKTRACE_LINE_LENGTH 800

static backtrace_frame_t mStack[MAX_DEPTH];
static size_t mCount;

void csupdate(int32_t ignoreDepth, int32_t maxDepth) {
    if (maxDepth > MAX_DEPTH) {
        maxDepth = MAX_DEPTH;
    }
    ssize_t count = unwind_backtrace(mStack, ignoreDepth + 1, maxDepth);
    mCount = count > 0 ? count : 0;
}

void csdump(const char* prefix)\
{
size_t i = 0;
    backtrace_symbol_t symbols[MAX_DEPTH];

    get_backtrace_symbols(mStack, mCount, symbols);

    for (i = 0; i < mCount; i++) {
        char line[MAX_BACKTRACE_LINE_LENGTH];
        format_backtrace_line(i, &mStack[i], &symbols[i],
                line, MAX_BACKTRACE_LINE_LENGTH);
        ALOGE("%s%s", prefix, line);
    }

    free_backtrace_symbols(symbols, mCount);
}

void myFunc()

{

     csupdate(1, 30);

     csdump("myprefix");

}

In Android.mk, add libcorkscrew, as below

LOCAL_SHARED_LIBRARIES := libxxx libyyy libcorkscrew

ラベル(1)
タグ(2)
評価なし
バージョン履歴
最終更新日:
‎10-13-2012 12:57 AM
更新者: