ci: fix vlib/dl/example/use_test.v in windows-tcc
parent
dbaccd4272
commit
4d0dab826b
|
@ -1,12 +1,11 @@
|
||||||
// Copyright (c) 2019-2021 Alexander Medvednikov. All rights reserved.
|
// Copyright (c) 2019-2021 Alexander Medvednikov. All rights reserved.
|
||||||
// Use of this source code is governed by an MIT license
|
// Use of this source code is governed by an MIT license
|
||||||
// that can be found in the LICENSE file.
|
// that can be found in the LICENSE file.
|
||||||
|
|
||||||
module builtin
|
module builtin
|
||||||
|
|
||||||
// dbghelp.h is already included in cheaders.v
|
// dbghelp.h is already included in cheaders.v
|
||||||
#flag windows -l dbghelp
|
#flag windows -l dbghelp
|
||||||
|
// SymbolInfo is used by print_backtrace_skipping_top_frames_msvc
|
||||||
pub struct SymbolInfo {
|
pub struct SymbolInfo {
|
||||||
pub mut:
|
pub mut:
|
||||||
f_size_of_struct u32 // must be 88 to be recognised by SymFromAddr
|
f_size_of_struct u32 // must be 88 to be recognised by SymFromAddr
|
||||||
|
@ -41,11 +40,18 @@ pub mut:
|
||||||
f_address u64
|
f_address u64
|
||||||
}
|
}
|
||||||
|
|
||||||
fn C.SymSetOptions(symoptions u32) u32 // returns the current options mask
|
// returns the current options mask
|
||||||
fn C.GetCurrentProcess() voidptr // returns handle
|
fn C.SymSetOptions(symoptions u32) u32
|
||||||
|
|
||||||
|
// returns handle
|
||||||
|
fn C.GetCurrentProcess() voidptr
|
||||||
|
|
||||||
fn C.SymInitialize(h_process voidptr, p_user_search_path byteptr, b_invade_process int) int
|
fn C.SymInitialize(h_process voidptr, p_user_search_path byteptr, b_invade_process int) int
|
||||||
|
|
||||||
fn C.CaptureStackBackTrace(frames_to_skip u32, frames_to_capture u32, p_backtrace voidptr, p_backtrace_hash voidptr) u16
|
fn C.CaptureStackBackTrace(frames_to_skip u32, frames_to_capture u32, p_backtrace voidptr, p_backtrace_hash voidptr) u16
|
||||||
|
|
||||||
fn C.SymFromAddr(h_process voidptr, address u64, p_displacement voidptr, p_symbol voidptr) int
|
fn C.SymFromAddr(h_process voidptr, address u64, p_displacement voidptr, p_symbol voidptr) int
|
||||||
|
|
||||||
fn C.SymGetLineFromAddr64(h_process voidptr, address u64, p_displacement voidptr, p_line &Line64) int
|
fn C.SymGetLineFromAddr64(h_process voidptr, address u64, p_displacement voidptr, p_line &Line64) int
|
||||||
|
|
||||||
// Ref - https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-symsetoptions
|
// Ref - https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-symsetoptions
|
||||||
|
@ -60,12 +66,15 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// g_original_codepage - used to restore the original windows console code page when exiting
|
// g_original_codepage - used to restore the original windows console code page when exiting
|
||||||
__global ( g_original_codepage = u32(0) )
|
__global ( g_original_codepage = u32(0))
|
||||||
|
|
||||||
// utf8 to stdout needs C.SetConsoleOutputCP(C.CP_UTF8)
|
// utf8 to stdout needs C.SetConsoleOutputCP(C.CP_UTF8)
|
||||||
fn C.GetConsoleOutputCP() u32
|
fn C.GetConsoleOutputCP() u32
|
||||||
|
|
||||||
fn C.SetConsoleOutputCP(wCodePageID u32) bool
|
fn C.SetConsoleOutputCP(wCodePageID u32) bool
|
||||||
|
|
||||||
fn restore_codepage() {
|
fn restore_codepage() {
|
||||||
C.SetConsoleOutputCP( g_original_codepage )
|
C.SetConsoleOutputCP(g_original_codepage)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn builtin_init() {
|
fn builtin_init() {
|
||||||
|
@ -98,23 +107,25 @@ fn print_backtrace_skipping_top_frames(skipframes int) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_backtrace_skipping_top_frames_msvc(skipframes int) bool {
|
fn print_backtrace_skipping_top_frames_msvc(skipframes int) bool {
|
||||||
$if msvc {
|
$if msvc {
|
||||||
mut offset := u64(0)
|
mut offset := u64(0)
|
||||||
backtraces := [100]voidptr{}
|
backtraces := [100]voidptr{}
|
||||||
sic := SymbolInfoContainer{}
|
sic := SymbolInfoContainer{}
|
||||||
mut si := &sic.syminfo
|
mut si := &sic.syminfo
|
||||||
si.f_size_of_struct = sizeof(SymbolInfo) // Note: C.SYMBOL_INFO is 88
|
si.f_size_of_struct = sizeof(SymbolInfo) // Note: C.SYMBOL_INFO is 88
|
||||||
si.f_max_name_len = sizeof(SymbolInfoContainer) - sizeof(SymbolInfo) - 1
|
si.f_max_name_len = sizeof(SymbolInfoContainer) - sizeof(SymbolInfo) - 1
|
||||||
fname := charptr( &si.f_name )
|
fname := charptr(&si.f_name)
|
||||||
mut sline64 := Line64{}
|
mut sline64 := Line64{}
|
||||||
sline64.f_size_of_struct = sizeof(Line64)
|
sline64.f_size_of_struct = sizeof(Line64)
|
||||||
|
|
||||||
handle := C.GetCurrentProcess()
|
handle := C.GetCurrentProcess()
|
||||||
defer { C.SymCleanup(handle) }
|
defer {
|
||||||
|
C.SymCleanup(handle)
|
||||||
|
}
|
||||||
|
|
||||||
C.SymSetOptions(symopt_debug | symopt_load_lines | symopt_undname)
|
C.SymSetOptions(symopt_debug | symopt_load_lines | symopt_undname)
|
||||||
|
|
||||||
syminitok := C.SymInitialize( handle, 0, 1)
|
syminitok := C.SymInitialize(handle, 0, 1)
|
||||||
if syminitok != 1 {
|
if syminitok != 1 {
|
||||||
eprintln('Failed getting process: Aborting backtrace.\n')
|
eprintln('Failed getting process: Aborting backtrace.\n')
|
||||||
return false
|
return false
|
||||||
|
@ -125,16 +136,17 @@ $if msvc {
|
||||||
eprintln('C.CaptureStackBackTrace returned less than 2 frames')
|
eprintln('C.CaptureStackBackTrace returned less than 2 frames')
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for i in 0..frames {
|
for i in 0 .. frames {
|
||||||
frame_addr := backtraces[i]
|
frame_addr := backtraces[i]
|
||||||
if C.SymFromAddr(handle, frame_addr, &offset, si) == 1 {
|
if C.SymFromAddr(handle, frame_addr, &offset, si) == 1 {
|
||||||
nframe := frames - i - 1
|
nframe := frames - i - 1
|
||||||
mut lineinfo := ''
|
mut lineinfo := ''
|
||||||
if C.SymGetLineFromAddr64(handle, frame_addr, &offset, &sline64) == 1 {
|
if C.SymGetLineFromAddr64(handle, frame_addr, &offset, &sline64) == 1 {
|
||||||
file_name := tos3(sline64.f_file_name)
|
file_name := tos3(sline64.f_file_name)
|
||||||
lineinfo = '${file_name}:${sline64.f_line_number}'
|
lnumber := sline64.f_line_number
|
||||||
|
lineinfo = '$file_name:$lnumber'
|
||||||
} else {
|
} else {
|
||||||
addr :
|
addr:
|
||||||
lineinfo = '?? : address = 0x${(&frame_addr):x}'
|
lineinfo = '?? : address = 0x${(&frame_addr):x}'
|
||||||
}
|
}
|
||||||
sfunc := tos3(fname)
|
sfunc := tos3(fname)
|
||||||
|
@ -153,10 +165,10 @@ $if msvc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
} $else {
|
} $else {
|
||||||
eprintln('print_backtrace_skipping_top_frames_msvc must be called only when the compiler is msvc')
|
eprintln('print_backtrace_skipping_top_frames_msvc must be called only when the compiler is msvc')
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_backtrace_skipping_top_frames_mingw(skipframes int) bool {
|
fn print_backtrace_skipping_top_frames_mingw(skipframes int) bool {
|
||||||
|
@ -165,31 +177,35 @@ fn print_backtrace_skipping_top_frames_mingw(skipframes int) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn C.tcc_backtrace(fmt charptr, other ...charptr) int
|
fn C.tcc_backtrace(fmt charptr, other ...charptr) int
|
||||||
|
|
||||||
fn print_backtrace_skipping_top_frames_tcc(skipframes int) bool {
|
fn print_backtrace_skipping_top_frames_tcc(skipframes int) bool {
|
||||||
$if tinyc {
|
$if tinyc {
|
||||||
C.tcc_backtrace("Backtrace")
|
$if no_backtrace ? {
|
||||||
|
eprintln('backtraces are disabled')
|
||||||
|
} $else {
|
||||||
|
C.tcc_backtrace('Backtrace')
|
||||||
return false
|
return false
|
||||||
|
}
|
||||||
} $else {
|
} $else {
|
||||||
eprintln('print_backtrace_skipping_top_frames_tcc must be called only when the compiler is tcc')
|
eprintln('print_backtrace_skipping_top_frames_tcc must be called only when the compiler is tcc')
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO copypaste from os
|
// TODO copypaste from os
|
||||||
// we want to be able to use this here without having to `import os`
|
// we want to be able to use this here without having to `import os`
|
||||||
struct ExceptionRecord {
|
struct ExceptionRecord {
|
||||||
pub:
|
pub:
|
||||||
// status_ constants
|
// status_ constants
|
||||||
code u32
|
code u32
|
||||||
flags u32
|
flags u32
|
||||||
|
|
||||||
record &ExceptionRecord
|
record &ExceptionRecord
|
||||||
address voidptr
|
address voidptr
|
||||||
param_count u32
|
param_count u32
|
||||||
// params []voidptr
|
// params []voidptr
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ContextRecord {
|
struct ContextRecord {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,9 +215,10 @@ pub:
|
||||||
context_record &ContextRecord
|
context_record &ContextRecord
|
||||||
}
|
}
|
||||||
|
|
||||||
type VectoredExceptionHandler = fn(&ExceptionPointers)int
|
type VectoredExceptionHandler = fn (&ExceptionPointers) int
|
||||||
|
|
||||||
fn C.AddVectoredExceptionHandler(int, C.PVECTORED_EXCEPTION_HANDLER)
|
fn C.AddVectoredExceptionHandler(int, C.PVECTORED_EXCEPTION_HANDLER)
|
||||||
|
|
||||||
fn add_vectored_exception_handler(handler VectoredExceptionHandler) {
|
fn add_vectored_exception_handler(handler VectoredExceptionHandler) {
|
||||||
C.AddVectoredExceptionHandler(1, C.PVECTORED_EXCEPTION_HANDLER(handler))
|
C.AddVectoredExceptionHandler(1, C.PVECTORED_EXCEPTION_HANDLER(handler))
|
||||||
}
|
}
|
||||||
|
@ -228,6 +245,7 @@ fn add_unhandled_exception_handler() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn C.IsDebuggerPresent() bool
|
fn C.IsDebuggerPresent() bool
|
||||||
|
|
||||||
fn C.__debugbreak()
|
fn C.__debugbreak()
|
||||||
|
|
||||||
fn break_if_debugger_attached() {
|
fn break_if_debugger_attached() {
|
||||||
|
|
Loading…
Reference in New Issue