Skip to content

Commit 11067a7

Browse files
committed
fix: Provide macos-specific backtrace printing to avoid terminal death
Branch: MacOSSafeBacktrace Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
1 parent 6340ab1 commit 11067a7

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

ggml/src/ggml.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ static void ggml_print_backtrace_symbols(void) {
124124
int nptrs = backtrace(trace, sizeof(trace)/sizeof(trace[0]));
125125
backtrace_symbols_fd(trace, nptrs, STDERR_FILENO);
126126
}
127+
#elif defined(__APPLE__)
128+
#include <execinfo.h>
129+
static void ggml_print_backtrace_symbols(void) {
130+
void * trace[100];
131+
int nptrs = backtrace(trace, sizeof(trace)/sizeof(trace[0]));
132+
backtrace_symbols_fd(trace, nptrs, STDERR_FILENO);
133+
}
127134
#else
128135
static void ggml_print_backtrace_symbols(void) {
129136
// platform not supported
@@ -135,6 +142,14 @@ void ggml_print_backtrace(void) {
135142
if (GGML_NO_BACKTRACE) {
136143
return;
137144
}
145+
#if defined(__APPLE__)
146+
// On macOS, fork+debugger attachment is problematic due to:
147+
// 1. libdispatch "poisons" forked child processes
148+
// 2. lldb has issues attaching to parent from forked child
149+
// Use simple backtrace() instead to avoid Terminal.app crashes
150+
ggml_print_backtrace_symbols();
151+
return;
152+
#endif
138153
#if defined(__linux__)
139154
FILE * f = fopen("/proc/self/status", "r");
140155
size_t size = 0;

0 commit comments

Comments
 (0)