1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

Revert "print_backtrace_skipping_top_frames: Implementation for MSVC "

This reverts commit d1e7a54f3a.
This commit is contained in:
Alexander Medvednikov
2019-11-10 20:01:19 +03:00
parent fdf6682254
commit ffa9646749
7 changed files with 46 additions and 226 deletions

View File

@ -31,20 +31,55 @@ fn on_panic(f fn (int) int) {
}
pub fn print_backtrace_skipping_top_frames(skipframes int) {
$if windows {
$if msvc {
if print_backtrace_skipping_top_frames_msvc(skipframes) { return }
$if mac {
buffer := [100]byteptr
nr_ptrs := C.backtrace(*voidptr(buffer), 100)
C.backtrace_symbols_fd(*voidptr(&buffer[skipframes]), nr_ptrs-skipframes, 1)
return
}
$if linux {
$if !android {
$if glibc {
// backtrace is not available on Android.
//if C.backtrace_symbols_fd != 0 {
buffer := [100]byteptr
nr_ptrs := C.backtrace(*voidptr(buffer), 100)
nr_actual_frames := nr_ptrs-skipframes
mut sframes := []string
csymbols := *byteptr(C.backtrace_symbols(*voidptr(&buffer[skipframes]), nr_actual_frames))
for i in 0..nr_actual_frames { sframes << tos2(csymbols[i]) }
for sframe in sframes {
executable := sframe.all_before('(')
addr := sframe.all_after('[').all_before(']')
cmd := 'addr2line -e $executable $addr'
// taken from os, to avoid depending on the os module inside builtin.v
f := C.popen(cmd.str, 'r')
if isnil(f) {
println(sframe) continue
}
buf := [1000]byte
mut output := ''
for C.fgets(voidptr(buf), 1000, f) != 0 {
output += tos(buf, vstrlen(buf))
}
output = output.trim_space()+':'
if 0 != int(C.pclose(f)) {
println(sframe) continue
}
println( '${output:-45s} | $sframe')
}
//C.backtrace_symbols_fd(*voidptr(&buffer[skipframes]), nr_actual_frames, 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')
}
}
$if mingw {
if print_backtrace_skipping_top_frames_mingw(skipframes) { return }
}
}$else{
if print_backtrace_skipping_top_frames_nix(skipframes) { return }
}
println('print_backtrace_skipping_top_frames is not implemented on this platform for now...\n')
}
pub fn print_backtrace(){
// at the time of backtrace_symbols_fd call, the C stack would look something like this:
// 1 frame for print_backtrace_skipping_top_frames