builtin: support -d no_backtrace, to ease compiling V code on older distros easier
parent
f807fd973e
commit
48b117618d
|
@ -87,48 +87,52 @@ fn print_backtrace_skipping_top_frames_linux(skipframes int) bool {
|
||||||
C.tcc_backtrace("Backtrace")
|
C.tcc_backtrace("Backtrace")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
buffer := [100]byteptr{}
|
$if no_backtrace ? {
|
||||||
nr_ptrs := C.backtrace(voidptr(buffer), 100)
|
|
||||||
if nr_ptrs < 2 {
|
|
||||||
eprintln('C.backtrace returned less than 2 frames')
|
|
||||||
return false
|
return false
|
||||||
}
|
} $else {
|
||||||
nr_actual_frames := nr_ptrs - skipframes
|
buffer := [100]byteptr{}
|
||||||
mut sframes := []string{}
|
nr_ptrs := C.backtrace(voidptr(buffer), 100)
|
||||||
//////csymbols := backtrace_symbols(*voidptr(&buffer[skipframes]), nr_actual_frames)
|
if nr_ptrs < 2 {
|
||||||
csymbols := C.backtrace_symbols(voidptr(&buffer[skipframes]), nr_actual_frames)
|
eprintln('C.backtrace returned less than 2 frames')
|
||||||
for i in 0 .. nr_actual_frames {
|
return false
|
||||||
sframes << unsafe {tos2( byteptr(csymbols[i]) )}
|
|
||||||
}
|
|
||||||
for sframe in sframes {
|
|
||||||
executable := sframe.all_before('(')
|
|
||||||
addr := sframe.all_after('[').all_before(']')
|
|
||||||
beforeaddr := sframe.all_before('[')
|
|
||||||
cmd := 'addr2line -e $executable $addr'
|
|
||||||
// taken from os, to avoid depending on the os module inside builtin.v
|
|
||||||
f := C.popen(charptr(cmd.str), 'r')
|
|
||||||
if isnil(f) {
|
|
||||||
eprintln(sframe)
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
buf := [1000]byte{}
|
nr_actual_frames := nr_ptrs - skipframes
|
||||||
mut output := ''
|
mut sframes := []string{}
|
||||||
for C.fgets(charptr(buf), 1000, f) != 0 {
|
//////csymbols := backtrace_symbols(*voidptr(&buffer[skipframes]), nr_actual_frames)
|
||||||
output += tos(byteptr(buf), vstrlen(byteptr(buf)))
|
csymbols := C.backtrace_symbols(voidptr(&buffer[skipframes]), nr_actual_frames)
|
||||||
|
for i in 0 .. nr_actual_frames {
|
||||||
|
sframes << unsafe {tos2( byteptr(csymbols[i]) )}
|
||||||
}
|
}
|
||||||
output = output.trim_space() + ':'
|
for sframe in sframes {
|
||||||
if C.pclose(f) != 0 {
|
executable := sframe.all_before('(')
|
||||||
eprintln(sframe)
|
addr := sframe.all_after('[').all_before(']')
|
||||||
continue
|
beforeaddr := sframe.all_before('[')
|
||||||
|
cmd := 'addr2line -e $executable $addr'
|
||||||
|
// taken from os, to avoid depending on the os module inside builtin.v
|
||||||
|
f := C.popen(charptr(cmd.str), 'r')
|
||||||
|
if isnil(f) {
|
||||||
|
eprintln(sframe)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
buf := [1000]byte{}
|
||||||
|
mut output := ''
|
||||||
|
for C.fgets(charptr(buf), 1000, f) != 0 {
|
||||||
|
output += tos(byteptr(buf), vstrlen(byteptr(buf)))
|
||||||
|
}
|
||||||
|
output = output.trim_space() + ':'
|
||||||
|
if C.pclose(f) != 0 {
|
||||||
|
eprintln(sframe)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if output in ['??:0:', '??:?:'] {
|
||||||
|
output = ''
|
||||||
|
}
|
||||||
|
// See http://wiki.dwarfstd.org/index.php?title=Path_Discriminators
|
||||||
|
// NB: it is shortened here to just d. , just so that it fits, and so
|
||||||
|
// that the common error file:lineno: line format is enforced.
|
||||||
|
output = output.replace(' (discriminator', ': (d.')
|
||||||
|
eprintln('${output:-46s} | ${addr:14s} | $beforeaddr')
|
||||||
}
|
}
|
||||||
if output in ['??:0:', '??:?:'] {
|
|
||||||
output = ''
|
|
||||||
}
|
|
||||||
// See http://wiki.dwarfstd.org/index.php?title=Path_Discriminators
|
|
||||||
// NB: it is shortened here to just d. , just so that it fits, and so
|
|
||||||
// that the common error file:lineno: line format is enforced.
|
|
||||||
output = output.replace(' (discriminator', ': (d.')
|
|
||||||
eprintln('${output:-46s} | ${addr:14s} | $beforeaddr')
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue