diff --git a/compiler/cheaders.v b/compiler/cheaders.v index 0d1a542d7c..e6650785ca 100644 --- a/compiler/cheaders.v +++ b/compiler/cheaders.v @@ -23,6 +23,8 @@ CommonCHeaders = ' #ifdef __linux__ #include // backtrace and backtrace_symbols_fd +#pragma weak backtrace +#pragma weak backtrace_symbols_fd #endif #ifdef __linux__ diff --git a/vlib/builtin/builtin.v b/vlib/builtin/builtin.v index aa6dd4b2b5..7c02cf973c 100644 --- a/vlib/builtin/builtin.v +++ b/vlib/builtin/builtin.v @@ -19,16 +19,21 @@ fn on_panic(f fn (int) int) { pub fn print_backtrace_skipping_top_frames(skipframes int) { $if mac { - buffer := [100]voidptr + buffer := [100]byteptr nr_ptrs := C.backtrace(buffer, 100) C.backtrace_symbols_fd(&buffer[skipframes], nr_ptrs-skipframes, 1) return } $if linux { - buffer := [100]voidptr - nr_ptrs := C.backtrace(buffer, 100) - C.backtrace_symbols_fd(&buffer[skipframes], nr_ptrs-skipframes, 1) - return + if C.backtrace_symbols_fd != 0 { + buffer := [100]byteptr + nr_ptrs := C.backtrace(buffer, 100) + C.backtrace_symbols_fd(&buffer[skipframes], nr_ptrs-skipframes, 1) + return + }else{ + C.printf('backtrace_symbols_fd is missing, so printing backtraces is not available.\n') + C.printf('Some libc implementations like musl simply do not provide it.\n') + } } C.printf('print_backtrace_skipping_top_frames is not implemented on this platform for now...\n') }