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 {
$if no_backtrace ? {
return false
} $else {
skipframes := xskipframes + 2
$if macos {
return print_backtrace_skipping_top_frames_mac(skipframes)
}
$if linux {
$if macos || freebsd || openbsd || netbsd {
return print_backtrace_skipping_top_frames_bsd(skipframes)
} $else $if linux {
return print_backtrace_skipping_top_frames_linux(skipframes)
}
$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)
}
} $else {
println('print_backtrace_skipping_top_frames is not implemented. skipframes: $skipframes')
return false
}
}
}
// the functions below are not called outside this file,
// so there is no need to have their twins in builtin_windows.v
fn print_backtrace_skipping_top_frames_mac(skipframes int) bool {
$if macos {
fn print_backtrace_skipping_top_frames_bsd(skipframes int) bool {
$if no_backtrace ? {
return false
} $else {
$if macos || freebsd || openbsd || netbsd {
buffer := [100]voidptr{}
nr_ptrs := C.backtrace(&buffer[0], 100)
if nr_ptrs < 2 {
@ -57,18 +55,6 @@ fn print_backtrace_skipping_top_frames_mac(skipframes int) bool {
}
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