ci: fix vlib/dl/example/use_test.v in windows-tcc

pull/8347/head^2
Delyan Angelov 2021-01-25 21:19:15 +02:00
parent dbaccd4272
commit 4d0dab826b
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 111 additions and 93 deletions

View File

@ -1,12 +1,11 @@
// Copyright (c) 2019-2021 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module builtin
// dbghelp.h is already included in cheaders.v
#flag windows -l dbghelp
// SymbolInfo is used by print_backtrace_skipping_top_frames_msvc
pub struct SymbolInfo {
pub mut:
f_size_of_struct u32 // must be 88 to be recognised by SymFromAddr
@ -41,11 +40,18 @@ pub mut:
f_address u64
}
fn C.SymSetOptions(symoptions u32) u32 // returns the current options mask
fn C.GetCurrentProcess() voidptr // returns handle
// returns the current options mask
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.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.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
@ -61,9 +67,12 @@ const (
// g_original_codepage - used to restore the original windows console code page when exiting
__global ( g_original_codepage = u32(0))
// utf8 to stdout needs C.SetConsoleOutputCP(C.CP_UTF8)
fn C.GetConsoleOutputCP() u32
fn C.SetConsoleOutputCP(wCodePageID u32) bool
fn restore_codepage() {
C.SetConsoleOutputCP(g_original_codepage)
}
@ -110,7 +119,9 @@ $if msvc {
sline64.f_size_of_struct = sizeof(Line64)
handle := C.GetCurrentProcess()
defer { C.SymCleanup(handle) }
defer {
C.SymCleanup(handle)
}
C.SymSetOptions(symopt_debug | symopt_load_lines | symopt_undname)
@ -132,7 +143,8 @@ $if msvc {
mut lineinfo := ''
if C.SymGetLineFromAddr64(handle, frame_addr, &offset, &sline64) == 1 {
file_name := tos3(sline64.f_file_name)
lineinfo = '${file_name}:${sline64.f_line_number}'
lnumber := sline64.f_line_number
lineinfo = '$file_name:$lnumber'
} else {
addr:
lineinfo = '?? : address = 0x${(&frame_addr):x}'
@ -165,10 +177,15 @@ fn print_backtrace_skipping_top_frames_mingw(skipframes int) bool {
}
fn C.tcc_backtrace(fmt charptr, other ...charptr) int
fn print_backtrace_skipping_top_frames_tcc(skipframes int) bool {
$if tinyc {
C.tcc_backtrace("Backtrace")
$if no_backtrace ? {
eprintln('backtraces are disabled')
} $else {
C.tcc_backtrace('Backtrace')
return false
}
} $else {
eprintln('print_backtrace_skipping_top_frames_tcc must be called only when the compiler is tcc')
return false
@ -182,7 +199,6 @@ pub:
// status_ constants
code u32
flags u32
record &ExceptionRecord
address voidptr
param_count u32
@ -202,6 +218,7 @@ pub:
type VectoredExceptionHandler = fn (&ExceptionPointers) int
fn C.AddVectoredExceptionHandler(int, C.PVECTORED_EXCEPTION_HANDLER)
fn add_vectored_exception_handler(handler VectoredExceptionHandler) {
C.AddVectoredExceptionHandler(1, C.PVECTORED_EXCEPTION_HANDLER(handler))
}
@ -228,6 +245,7 @@ fn add_unhandled_exception_handler() {
}
fn C.IsDebuggerPresent() bool
fn C.__debugbreak()
fn break_if_debugger_attached() {