diff options
author | 2012-09-03 05:00:32 -0700 | |
---|---|---|
committer | 2012-09-03 05:00:33 -0700 | |
commit | 1a397ececf88f2daffa103f8411aa9cbaabb50da (patch) | |
tree | b2c3a511014e2aaeff0a2a361daa567245f2fed2 | |
parent | 720e1056946277563d78e75f2ad0d17109f4332a (diff) | |
parent | 5540acb6765d24ca0257a303beee84cfa139a49f (diff) | |
download | latinime-1a397ececf88f2daffa103f8411aa9cbaabb50da.tar.gz latinime-1a397ececf88f2daffa103f8411aa9cbaabb50da.tar.xz latinime-1a397ececf88f2daffa103f8411aa9cbaabb50da.zip |
Merge "Add backtrace tool" into jb-mr1-dev
-rw-r--r-- | native/jni/src/defines.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/native/jni/src/defines.h b/native/jni/src/defines.h index 9b530077a..28661ab20 100644 --- a/native/jni/src/defines.h +++ b/native/jni/src/defines.h @@ -83,12 +83,38 @@ static inline void dumpWordInt(const int *word, const int length) { AKLOGI("i[ %s ]", charBuf); } +#ifndef __ANDROID__ +#define ASSERT(success) do { if(!success) { showStackTrace(); assert(success);};} while (0) +#define SHOW_STACK_TRACE do { showStackTrace(); } while (0) + +#include <execinfo.h> +#include <stdlib.h> +static inline void showStackTrace() { + void *callstack[128]; + int i, frames = backtrace(callstack, 128); + char **strs = backtrace_symbols(callstack, frames); + for (i = 0; i < frames; ++i) { + if (i == 0) { + AKLOGI("=== Trace ==="); + continue; + } + AKLOGI("%s", strs[i]); + } + free(strs); +} +#else +#define ASSERT(success) +#define SHOW_STACK_TRACE +#endif + #else #define AKLOGE(fmt, ...) #define AKLOGI(fmt, ...) #define DUMP_RESULT(words, frequencies, maxWordCount, maxWordLength) #define DUMP_WORD(word, length) #define DUMP_WORD_INT(word, length) +#define ASSERT(success) +#define SHOW_STACK_TRACE #endif #ifdef FLAG_DO_PROFILE |