mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
print backtraces on panic on mac and linux
This commit is contained in:
parent
02fc7e14cd
commit
73c6bae480
@ -39,6 +39,11 @@ fn (v mut V) cc() {
|
|||||||
else {
|
else {
|
||||||
a << '-g'
|
a << '-g'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v.pref.is_debug {
|
||||||
|
a << ' -rdynamic ' // needed for nicer symbolic backtraces
|
||||||
|
}
|
||||||
|
|
||||||
if v.os != .msvc && v.os != .freebsd {
|
if v.os != .msvc && v.os != .freebsd {
|
||||||
a << '-Werror=implicit-function-declaration'
|
a << '-Werror=implicit-function-declaration'
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,15 @@ CommonCHeaders = '
|
|||||||
#include <execinfo.h> // backtrace and backtrace_symbols_fd
|
#include <execinfo.h> // backtrace and backtrace_symbols_fd
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
#include <execinfo.h> // backtrace and backtrace_symbols_fd
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/wait.h> // os__wait uses wait on nix
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define EMPTY_STRUCT_DECLARATION
|
#define EMPTY_STRUCT_DECLARATION
|
||||||
#define OPTION_CAST(x) (x)
|
#define OPTION_CAST(x) (x)
|
||||||
|
@ -17,15 +17,28 @@ fn on_panic(f fn (int) int) {
|
|||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_backtrace() {
|
pub fn print_backtrace_skipping_top_frames(skipframes int) {
|
||||||
if true {
|
|
||||||
return // TODO
|
|
||||||
}
|
|
||||||
$if mac {
|
$if mac {
|
||||||
buffer := [100]voidptr
|
buffer := [100]voidptr
|
||||||
nr_ptrs := C.backtrace(buffer, 100)
|
nr_ptrs := C.backtrace(buffer, 100)
|
||||||
C.backtrace_symbols_fd(buffer, nr_ptrs, 1)
|
C.backtrace_symbols_fd(&buffer[skipframes], nr_ptrs-skipframes, 1)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
$if linux {
|
||||||
|
buffer := [100]voidptr
|
||||||
|
nr_ptrs := C.backtrace(buffer, 100)
|
||||||
|
C.backtrace_symbols_fd(&buffer[skipframes], nr_ptrs-skipframes, 1)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
C.printf('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
|
||||||
|
// 1 frame for print_backtrace itself
|
||||||
|
// ... print the rest of the backtrace frames ...
|
||||||
|
// => top 2 frames should be skipped, since they will not be informative to the developer
|
||||||
|
print_backtrace_skipping_top_frames(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
// replaces panic when -debug arg is passed
|
// replaces panic when -debug arg is passed
|
||||||
@ -37,7 +50,7 @@ fn _panic_debug(line_no int, file, mod, fn_name, s string) {
|
|||||||
println(' line: ' + line_no.str())
|
println(' line: ' + line_no.str())
|
||||||
println(' message: $s')
|
println(' message: $s')
|
||||||
println('=========================================')
|
println('=========================================')
|
||||||
print_backtrace()
|
print_backtrace_skipping_top_frames(1)
|
||||||
C.exit(1)
|
C.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user