mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
builtin: add sanity check on the number of returned frames by C.backtrace
This commit is contained in:
parent
3a461e7cee
commit
4568ce8f00
@ -50,6 +50,10 @@ fn print_backtrace_skipping_top_frames_mac(skipframes int) bool {
|
||||
$if macos {
|
||||
buffer := [100]byteptr
|
||||
nr_ptrs := C.backtrace(buffer, 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
|
||||
@ -59,6 +63,10 @@ fn print_backtrace_skipping_top_frames_freebsd(skipframes int) bool {
|
||||
$if freebsd {
|
||||
buffer := [100]byteptr
|
||||
nr_ptrs := C.backtrace(buffer, 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
|
||||
@ -81,6 +89,10 @@ fn print_backtrace_skipping_top_frames_linux(skipframes int) bool {
|
||||
}
|
||||
buffer := [100]byteptr
|
||||
nr_ptrs := C.backtrace(buffer, 100)
|
||||
if nr_ptrs < 2 {
|
||||
eprintln('C.backtrace returned less than 2 frames')
|
||||
return false
|
||||
}
|
||||
nr_actual_frames := nr_ptrs - skipframes
|
||||
mut sframes := []string{}
|
||||
//////csymbols := backtrace_symbols(*voidptr(&buffer[skipframes]), nr_actual_frames)
|
||||
|
@ -103,10 +103,14 @@ $if msvc {
|
||||
syminitok := C.SymInitialize( handle, 0, 1)
|
||||
if syminitok != 1 {
|
||||
eprintln('Failed getting process: Aborting backtrace.\n')
|
||||
return true
|
||||
return false
|
||||
}
|
||||
|
||||
frames := int(C.CaptureStackBackTrace(skipframes + 1, 100, backtraces, 0))
|
||||
if frames < 2 {
|
||||
eprintln('C.CaptureStackBackTrace returned less than 2 frames')
|
||||
return false
|
||||
}
|
||||
for i in 0..frames {
|
||||
frame_addr := backtraces[i]
|
||||
if C.SymFromAddr(handle, frame_addr, &offset, si) == 1 {
|
||||
|
Loading…
Reference in New Issue
Block a user