builtin: add a 'v hash:' line to V panics

pull/9745/head
Delyan Angelov 2021-04-15 11:43:38 +03:00
parent 466dc4540b
commit cb69c4c91a
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 6 additions and 0 deletions

View File

@ -9,6 +9,10 @@ pub fn exit(code int) {
C.exit(code)
}
fn vcommithash() string {
return unsafe { tos5(&char(C.V_CURRENT_COMMIT_HASH)) }
}
// panic_debug private function that V uses for panics, -cg/-g is passed
// recent versions of tcc print nicer backtraces automatically
// NB: the duplication here is because tcc_backtrace should be called directly
@ -24,6 +28,7 @@ fn panic_debug(line_no int, file string, mod string, fn_name string, s string) {
eprintln(' function: ${fn_name}()')
eprintln(' message: $s')
eprintln(' file: $file:$line_no')
eprintln(' v hash: $vcommithash()')
eprintln('=========================================')
} $else {
eprint('V panic: ')
@ -63,6 +68,7 @@ pub fn panic_optional_not_set(s string) {
pub fn panic(s string) {
eprint('V panic: ')
eprintln(s)
eprintln('v hash: $vcommithash()')
$if exit_after_panic_message ? {
C.exit(1)
} $else {