From 14279180334ff170501abaa510ff0cd286f7100b Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Mon, 13 Nov 2023 00:08:37 +0100 Subject: [PATCH] Experiments --- .github/workflows/main.yml | 1 - lib/std/core/builtin.c3 | 4 ++-- lib/std/os/backtrace.c3 | 3 --- lib/std/os/linux/linux.c3 | 10 +++++----- resources/linux_stack.c3 | 26 +++++--------------------- src/compiler/compiler_internal.h | 1 - src/compiler/linker.c | 2 -- src/compiler/llvm_codegen_module.c | 2 +- src/compiler/target.c | 4 ---- 9 files changed, 13 insertions(+), 40 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 287b64ed2..d43a42868 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -370,7 +370,6 @@ jobs: ../build/c3c compile-run examples/factorial_macro.c3 ../build/c3c compile-run examples/fasta.c3 ../build/c3c compile-run examples/process.c3 - ../build/c3c compile-run linux_stack.c3 - name: Compile run unit tests run: | diff --git a/lib/std/core/builtin.c3 b/lib/std/core/builtin.c3 index d8f1b729b..31aaf4825 100644 --- a/lib/std/core/builtin.c3 +++ b/lib/std/core/builtin.c3 @@ -87,11 +87,11 @@ struct CallstackElement uint line; } -fn bool print_backtrace(String message, int backtraces_to_ignore) @if(env::DARWIN || env::LINUX) +fn bool print_backtrace(String message, int backtraces_to_ignore) @if(env::DARWIN) { @pool() { - BacktraceList! backtrace = backtrace::backtrace_load(mem::temp()); + BacktraceList! backtrace = darwin::backtrace_load(mem::temp()); if (catch backtrace) return false; if (backtrace.len() <= backtraces_to_ignore) return false; io::eprint("\nERROR: '"); diff --git a/lib/std/os/backtrace.c3 b/lib/std/os/backtrace.c3 index 15a6cc50d..4ee4ee63b 100644 --- a/lib/std/os/backtrace.c3 +++ b/lib/std/os/backtrace.c3 @@ -50,9 +50,6 @@ fn void Backtrace.free(&self) self.allocator.free(self.file); } -def backtrace_load = darwin::backtrace_load @if(env::DARWIN); -def backtrace_load = linux::backtrace_load @if(env::LINUX); - fn Backtrace* Backtrace.init(&self, uptr offset, String function, String object_file, String file = "", uint line = 0, Allocator* using = mem::heap()) { if (!using) diff --git a/lib/std/os/linux/linux.c3 b/lib/std/os/linux/linux.c3 index 0247b22cd..c4e6d442e 100644 --- a/lib/std/os/linux/linux.c3 +++ b/lib/std/os/linux/linux.c3 @@ -144,7 +144,8 @@ fn Backtrace! backtrace_load_element(void* addr, Allocator* allocator = mem::hea void* obj_address = addr - (uptr)info.dli_fbase + (uptr)elf_module_image_base(info.dli_fname.str_view())!; ZString obj_path = info.dli_fname; String s = process::execute_stdout_to_buffer(buf, { "addr2line", "-p", "-i", "-C", "-f", "-e", obj_path.str_view(), string::tformat("0x%x", obj_address) })!; - String[] parts = s.tsplit(" at "); + io::printfn("Result: [%s]", s); + String[] parts = s.tsplit(" at "); if (parts.len != 2) { return { @@ -157,16 +158,16 @@ fn Backtrace! backtrace_load_element(void* addr, Allocator* allocator = mem::hea } uint line = 0; String source = ""; - if (!parts[1].contains("?") && parts[1].contains(":")) + if (!parts[1].contains("?") || !parts[1].contains(":")) { usz index = parts[1].rindex_of_char(':')!; source = parts[1][:index]; line = parts[1][index + 1..].to_uint()!; } return { - .function = parts[0].copy(allocator), + .function = parts[0], .object_file = info.dli_fname.copy(allocator), - .file = source.copy(allocator), + .file = source, .line = line, .allocator = allocator }; @@ -177,7 +178,6 @@ fn BacktraceList! backtrace_load(Allocator* allocator) { void*[256] bt_buffer; CInt size = posix::backtrace(&bt_buffer, 256); - io::printfn("Backtrace list %s", size); BacktraceList list; list.init_new(size, allocator); defer catch diff --git a/resources/linux_stack.c3 b/resources/linux_stack.c3 index 522297df5..fcf56d883 100644 --- a/resources/linux_stack.c3 +++ b/resources/linux_stack.c3 @@ -3,28 +3,12 @@ import std::io; import std::collections::map; import std::os; -fn void! test2() +fn void! main() { - io::printn("Hello"); - //typeid y = int.typeid; + int x = 2; BacktraceList list = linux::backtrace_load(mem::heap())!; - foreach (Backtrace trace : list) - { - io::printfn(">%s", trace); + foreach (Backtrace trace : list) + { + io::printfn(">%s", trace); } - //builtin::panicf("FEHifej", "file", "fun", 123); - int x = 2; - int[1] y; -// int z = y[x]; -//assert(false, "ofkef"); -} - -fn void test1() -{ - io::printfn("Hello2"); - (void)test2(); -} -fn void main() -{ - test1(); } \ No newline at end of file diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index 9b1108024..9fd48fdb9 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -2367,7 +2367,6 @@ void codegen_setup_object_names(Module *module, const char **ir_filename, const void target_setup(BuildTarget *build_target); int target_alloca_addr_space(); bool os_is_apple(OsType os_type); -bool os_supports_stacktrace(OsType os_type); bool arch_is_wasm(ArchType type); const char *macos_sysroot(void); diff --git a/src/compiler/linker.c b/src/compiler/linker.c index b185db690..572789b21 100644 --- a/src/compiler/linker.c +++ b/src/compiler/linker.c @@ -390,7 +390,6 @@ static void linker_setup_linux(const char ***args_ref, LinkerType linker_type) { add_arg("-rdynamic"); } - vec_add(active_target.linker_libs, "dl"); add_arg("-pthread"); return; } @@ -438,7 +437,6 @@ static void linker_setup_linux(const char ***args_ref, LinkerType linker_type) add_arg("-L/usr/lib/"); add_arg("-L/lib/"); add_arg("-m"); - add_arg("-ldl"); add_arg(ld_target(platform_target.arch)); } diff --git a/src/compiler/llvm_codegen_module.c b/src/compiler/llvm_codegen_module.c index 0f9aa25f8..af98fd6a2 100644 --- a/src/compiler/llvm_codegen_module.c +++ b/src/compiler/llvm_codegen_module.c @@ -169,7 +169,7 @@ void gencontext_begin_module(GenContext *c) LLVMStructSetBody(c->debug.stack_type, types, 5, false); c->debug.current_stack_ptr = NULL; c->debug.enable_stacktrace = true; - c->debug.emulated_stacktrace = !os_supports_stacktrace(platform_target.os); + c->debug.emulated_stacktrace = !os_is_apple(platform_target.os); } } c->global_builder = LLVMCreateBuilder(); diff --git a/src/compiler/target.c b/src/compiler/target.c index 3a5ebaed1..4a61264ce 100644 --- a/src/compiler/target.c +++ b/src/compiler/target.c @@ -32,10 +32,6 @@ int target_alloca_addr_space() return platform_target.alloca_address_space; } -bool os_supports_stacktrace(OsType os_type) -{ - return os_type == OS_TYPE_LINUX || os_is_apple(os_type); -} bool os_is_apple(OsType os_type) { return os_type == OS_TYPE_TVOS || os_type == OS_TYPE_WATCHOS ||