From 0bb7932d8d6d316bbacbd8454fa79433d3989ffa Mon Sep 17 00:00:00 2001 From: l3utterfly Date: Mon, 29 Jul 2024 21:02:39 +0900 Subject: [PATCH 1/6] added android implementation of ggml_print_backtrace_symbols --- ggml/src/ggml.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c index c76d00a39ed00..171b80e84b8d5 100644 --- a/ggml/src/ggml.c +++ b/ggml/src/ggml.c @@ -141,7 +141,51 @@ typedef pthread_t ggml_thread_t; #include -#if defined(__linux__) +#if defined(__ANDROID__) +#include +#include +#include + +struct BacktraceState { + void** current; + void** end; +}; + +static _Unwind_Reason_Code unwind_callback(struct _Unwind_Context* context, void* arg) { + struct BacktraceState* state = (struct BacktraceState*)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; +} + +static void ggml_print_backtrace_symbols(void) { + const int max = 100; + void* buffer[max]; + + struct BacktraceState state = {buffer, buffer + max}; + _Unwind_Backtrace(unwind_callback, &state); + + int count = state.current - buffer; + + for (int idx = 0; idx < count; ++idx) { + const void* addr = buffer[idx]; + const char* symbol = ""; + + Dl_info info; + if (dladdr(addr, &info) && info.dli_sname) { + symbol = info.dli_sname; + } + + fprintf(stderr, "%d: %p %s\n", idx, addr, symbol); + } +} +#elif defined(__linux__) #include static void ggml_print_backtrace_symbols(void) { void * trace[100]; From e0894593550a7f4426880d2c40cbf092bcd46e49 Mon Sep 17 00:00:00 2001 From: l3utterfly Date: Mon, 29 Jul 2024 22:43:17 +0900 Subject: [PATCH 2/6] Update ggml/src/ggml.c Co-authored-by: slaren --- ggml/src/ggml.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c index 171b80e84b8d5..57c035daaf388 100644 --- a/ggml/src/ggml.c +++ b/ggml/src/ggml.c @@ -146,7 +146,7 @@ typedef pthread_t ggml_thread_t; #include #include -struct BacktraceState { +struct backtrace_state { void** current; void** end; }; From 8a3eceba0c892394ee6b5a1995779e5b46eb1362 Mon Sep 17 00:00:00 2001 From: l3utterfly Date: Mon, 29 Jul 2024 22:43:24 +0900 Subject: [PATCH 3/6] Update ggml/src/ggml.c Co-authored-by: slaren --- ggml/src/ggml.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c index 57c035daaf388..d26d8b6c76aa4 100644 --- a/ggml/src/ggml.c +++ b/ggml/src/ggml.c @@ -147,8 +147,8 @@ typedef pthread_t ggml_thread_t; #include struct backtrace_state { - void** current; - void** end; + void ** current; + void ** end; }; static _Unwind_Reason_Code unwind_callback(struct _Unwind_Context* context, void* arg) { From 45b6b799b6c2fe8c57ead551afdcdc09e17df53f Mon Sep 17 00:00:00 2001 From: l3utterfly Date: Mon, 29 Jul 2024 22:43:29 +0900 Subject: [PATCH 4/6] Update ggml/src/ggml.c Co-authored-by: slaren --- ggml/src/ggml.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c index d26d8b6c76aa4..79e10a4397f1d 100644 --- a/ggml/src/ggml.c +++ b/ggml/src/ggml.c @@ -152,7 +152,7 @@ struct backtrace_state { }; static _Unwind_Reason_Code unwind_callback(struct _Unwind_Context* context, void* arg) { - struct BacktraceState* state = (struct BacktraceState*)arg; + struct backtrace_state * state = (struct backtrace_state *)arg; uintptr_t pc = _Unwind_GetIP(context); if (pc) { if (state->current == state->end) { From 687f8fdecbb2224c14189571425566b94a62b198 Mon Sep 17 00:00:00 2001 From: l3utterfly Date: Mon, 29 Jul 2024 22:43:34 +0900 Subject: [PATCH 5/6] Update ggml/src/ggml.c Co-authored-by: slaren --- ggml/src/ggml.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c index 79e10a4397f1d..fe962ca5cc279 100644 --- a/ggml/src/ggml.c +++ b/ggml/src/ggml.c @@ -174,8 +174,8 @@ static void ggml_print_backtrace_symbols(void) { int count = state.current - buffer; for (int idx = 0; idx < count; ++idx) { - const void* addr = buffer[idx]; - const char* symbol = ""; + const void * addr = buffer[idx]; + const char * symbol = ""; Dl_info info; if (dladdr(addr, &info) && info.dli_sname) { From a272a7425df03d2221b459e9ccdb26d3a546744a Mon Sep 17 00:00:00 2001 From: l3utterfly Date: Mon, 29 Jul 2024 22:43:39 +0900 Subject: [PATCH 6/6] Update ggml/src/ggml.c Co-authored-by: slaren --- ggml/src/ggml.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c index fe962ca5cc279..4d566788461dd 100644 --- a/ggml/src/ggml.c +++ b/ggml/src/ggml.c @@ -168,7 +168,7 @@ static void ggml_print_backtrace_symbols(void) { const int max = 100; void* buffer[max]; - struct BacktraceState state = {buffer, buffer + max}; + struct backtrace_state state = {buffer, buffer + max}; _Unwind_Backtrace(unwind_callback, &state); int count = state.current - buffer;