builtin: support `-d no_backtrace` on macos/bsd too

pull/10848/head
Delyan Angelov 2021-07-17 15:16:44 +03:00
parent 3a0fa550b6
commit b0167297e5
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 25 additions and 39 deletions

View File

@ -23,30 +23,28 @@ fn builtin_init() {
} }
fn print_backtrace_skipping_top_frames(xskipframes int) bool { fn print_backtrace_skipping_top_frames(xskipframes int) bool {
$if no_backtrace ? {
return false
} $else {
skipframes := xskipframes + 2 skipframes := xskipframes + 2
$if macos { $if macos || freebsd || openbsd || netbsd {
return print_backtrace_skipping_top_frames_mac(skipframes) return print_backtrace_skipping_top_frames_bsd(skipframes)
} } $else $if linux {
$if linux {
return print_backtrace_skipping_top_frames_linux(skipframes) return print_backtrace_skipping_top_frames_linux(skipframes)
} } $else {
$if freebsd {
return print_backtrace_skipping_top_frames_freebsd(skipframes)
}
$if netbsd {
return print_backtrace_skipping_top_frames_freebsd(skipframes)
}
$if openbsd {
return print_backtrace_skipping_top_frames_freebsd(skipframes)
}
println('print_backtrace_skipping_top_frames is not implemented. skipframes: $skipframes') println('print_backtrace_skipping_top_frames is not implemented. skipframes: $skipframes')
return false return false
}
}
} }
// the functions below are not called outside this file, // the functions below are not called outside this file,
// so there is no need to have their twins in builtin_windows.v // so there is no need to have their twins in builtin_windows.v
fn print_backtrace_skipping_top_frames_mac(skipframes int) bool { fn print_backtrace_skipping_top_frames_bsd(skipframes int) bool {
$if macos { $if no_backtrace ? {
return false
} $else {
$if macos || freebsd || openbsd || netbsd {
buffer := [100]voidptr{} buffer := [100]voidptr{}
nr_ptrs := C.backtrace(&buffer[0], 100) nr_ptrs := C.backtrace(&buffer[0], 100)
if nr_ptrs < 2 { if nr_ptrs < 2 {
@ -56,19 +54,7 @@ fn print_backtrace_skipping_top_frames_mac(skipframes int) bool {
C.backtrace_symbols_fd(&buffer[skipframes], nr_ptrs - skipframes, 2) C.backtrace_symbols_fd(&buffer[skipframes], nr_ptrs - skipframes, 2)
} }
return true return true
}
fn print_backtrace_skipping_top_frames_freebsd(skipframes int) bool {
$if freebsd {
buffer := [100]voidptr{}
nr_ptrs := C.backtrace(&buffer[0], 100)
if nr_ptrs < 2 {
eprintln('C.backtrace returned less than 2 frames')
return false
} }
C.backtrace_symbols_fd(&buffer[skipframes], nr_ptrs - skipframes, 2)
}
return true
} }
fn C.tcc_backtrace(fmt &char) int fn C.tcc_backtrace(fmt &char) int