|
|
@@ -124,6 +124,13 @@ static void ggml_print_backtrace_symbols(void) {
|
|
|
int nptrs = backtrace(trace, sizeof(trace)/sizeof(trace[0]));
|
|
|
backtrace_symbols_fd(trace, nptrs, STDERR_FILENO);
|
|
|
}
|
|
|
+#elif defined(__APPLE__)
|
|
|
+#include <execinfo.h>
|
|
|
+static void ggml_print_backtrace_symbols(void) {
|
|
|
+ void * trace[100];
|
|
|
+ int nptrs = backtrace(trace, sizeof(trace)/sizeof(trace[0]));
|
|
|
+ backtrace_symbols_fd(trace, nptrs, STDERR_FILENO);
|
|
|
+}
|
|
|
#else
|
|
|
static void ggml_print_backtrace_symbols(void) {
|
|
|
// platform not supported
|
|
|
@@ -135,6 +142,20 @@ void ggml_print_backtrace(void) {
|
|
|
if (GGML_NO_BACKTRACE) {
|
|
|
return;
|
|
|
}
|
|
|
+#if defined(__APPLE__)
|
|
|
+ // On macOS, fork+debugger attachment is problematic due to:
|
|
|
+ // 1. libdispatch "poisons" forked child processes
|
|
|
+ // 2. lldb has issues attaching to parent from forked child
|
|
|
+ // Use simple backtrace() instead to avoid Terminal.app crashes
|
|
|
+ const char * GGML_BACKTRACE_LLDB = getenv("GGML_BACKTRACE_LLDB");
|
|
|
+ if (!GGML_BACKTRACE_LLDB) {
|
|
|
+ fprintf(stderr, "WARNING: Using native backtrace. Set GGML_BACKTRACE_LLDB for more info.\n");
|
|
|
+ fprintf(stderr, "WARNING: GGML_BACKTRACE_LLDB may cause native MacOS Terminal.app to crash.\n");
|
|
|
+ fprintf(stderr, "See: https://github.com/ggml-org/llama.cpp/pull/17869\n");
|
|
|
+ ggml_print_backtrace_symbols();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+#endif
|
|
|
#if defined(__linux__)
|
|
|
FILE * f = fopen("/proc/self/status", "r");
|
|
|
size_t size = 0;
|