forked from cory/tildefriends
Hook up backtraces on android.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4251 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
e86b9dae48
commit
20b0337e0a
@ -14,11 +14,11 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifndef _WIN32
|
#if defined(__ANDROID__)
|
||||||
#ifndef __ANDROID__
|
#include <unwind.h>
|
||||||
|
#elif !defined(_WIN32)
|
||||||
#include <execinfo.h>
|
#include <execinfo.h>
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
static JSValue _util_utf8_encode(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
static JSValue _util_utf8_encode(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||||
{
|
{
|
||||||
@ -469,13 +469,41 @@ const char* tf_util_backtrace_string()
|
|||||||
return tf_util_backtrace_to_string(buffer, count);
|
return tf_util_backtrace_to_string(buffer, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(__ANDROID__)
|
||||||
|
typedef struct _android_backtrace_t
|
||||||
|
{
|
||||||
|
void** current;
|
||||||
|
void** end;
|
||||||
|
} android_backtrace_t;
|
||||||
|
|
||||||
|
static _Unwind_Reason_Code _android_unwind_callback(struct _Unwind_Context* context, void* arg)
|
||||||
|
{
|
||||||
|
android_backtrace_t* state = arg;
|
||||||
|
uintptr_t pc = _Unwind_GetIP(context);
|
||||||
|
if (pc)
|
||||||
|
{
|
||||||
|
if (state->current == state->end)
|
||||||
|
{
|
||||||
|
return _URC_END_OF_STACK;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*state->current++ = (void*)pc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _URC_NO_REASON;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int tf_util_backtrace(void** buffer, int count)
|
int tf_util_backtrace(void** buffer, int count)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return CaptureStackBackTrace(0, count, buffer, NULL);
|
return CaptureStackBackTrace(0, count, buffer, NULL);
|
||||||
#elif !defined(__ANDROID__)
|
#elif defined(__ANDROID__)
|
||||||
return backtrace(buffer, count);
|
android_backtrace_t state = { .current = buffer, .end = buffer + count };
|
||||||
|
_Unwind_Backtrace(_android_unwind_callback, &state);
|
||||||
|
return state.current - buffer;
|
||||||
#else
|
#else
|
||||||
return 0;
|
return backtrace(buffer, count);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user