Skip to content

Commit

Permalink
Experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Nov 12, 2023
1 parent 399150d commit 1427918
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 40 deletions.
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
4 changes: 2 additions & 2 deletions lib/std/core/builtin.c3
Original file line number Diff line number Diff line change
Expand Up @@ -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: '");
Expand Down
3 changes: 0 additions & 3 deletions lib/std/os/backtrace.c3
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions lib/std/os/linux/linux.c3
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
};
Expand All @@ -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
Expand Down
26 changes: 5 additions & 21 deletions resources/linux_stack.c3
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
1 change: 0 additions & 1 deletion src/compiler/compiler_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/compiler/linker.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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));
}

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/llvm_codegen_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 0 additions & 4 deletions src/compiler/target.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down

0 comments on commit 1427918

Please sign in to comment.