Skip to content

Commit 817da05

Browse files
committed
Experiments
1 parent 399150d commit 817da05

File tree

9 files changed

+10
-37
lines changed

9 files changed

+10
-37
lines changed

.github/workflows/main.yml

-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ jobs:
370370
../build/c3c compile-run examples/factorial_macro.c3
371371
../build/c3c compile-run examples/fasta.c3
372372
../build/c3c compile-run examples/process.c3
373-
../build/c3c compile-run linux_stack.c3
374373
375374
- name: Compile run unit tests
376375
run: |

lib/std/core/builtin.c3

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ struct CallstackElement
8787
uint line;
8888
}
8989

90-
fn bool print_backtrace(String message, int backtraces_to_ignore) @if(env::DARWIN || env::LINUX)
90+
fn bool print_backtrace(String message, int backtraces_to_ignore) @if(env::DARWIN)
9191
{
9292
@pool()
9393
{
94-
BacktraceList! backtrace = backtrace::backtrace_load(mem::temp());
94+
BacktraceList! backtrace = darwin::backtrace_load(mem::temp());
9595
if (catch backtrace) return false;
9696
if (backtrace.len() <= backtraces_to_ignore) return false;
9797
io::eprint("\nERROR: '");

lib/std/os/backtrace.c3

-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ fn void Backtrace.free(&self)
5050
self.allocator.free(self.file);
5151
}
5252

53-
def backtrace_load = darwin::backtrace_load @if(env::DARWIN);
54-
def backtrace_load = linux::backtrace_load @if(env::LINUX);
55-
5653
fn Backtrace* Backtrace.init(&self, uptr offset, String function, String object_file, String file = "", uint line = 0, Allocator* using = mem::heap())
5754
{
5855
if (!using)

lib/std/os/linux/linux.c3

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ fn Backtrace! backtrace_load_element(void* addr, Allocator* allocator = mem::hea
144144
void* obj_address = addr - (uptr)info.dli_fbase + (uptr)elf_module_image_base(info.dli_fname.str_view())!;
145145
ZString obj_path = info.dli_fname;
146146
String s = process::execute_stdout_to_buffer(buf, { "addr2line", "-p", "-i", "-C", "-f", "-e", obj_path.str_view(), string::tformat("0x%x", obj_address) })!;
147-
String[] parts = s.tsplit(" at ");
147+
io::printfn("Result: [%s]", s);
148+
String[] parts = s.tsplit(" at ");
148149
if (parts.len != 2)
149150
{
150151
return {
@@ -177,7 +178,6 @@ fn BacktraceList! backtrace_load(Allocator* allocator)
177178
{
178179
void*[256] bt_buffer;
179180
CInt size = posix::backtrace(&bt_buffer, 256);
180-
io::printfn("Backtrace list %s", size);
181181
BacktraceList list;
182182
list.init_new(size, allocator);
183183
defer catch

resources/linux_stack.c3

+5-21
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,12 @@ import std::io;
33
import std::collections::map;
44
import std::os;
55

6-
fn void! test2()
6+
fn void! main()
77
{
8-
io::printn("Hello");
9-
//typeid y = int.typeid;
8+
int x = 2;
109
BacktraceList list = linux::backtrace_load(mem::heap())!;
11-
foreach (Backtrace trace : list)
12-
{
13-
io::printfn(">%s", trace);
10+
foreach (Backtrace trace : list)
11+
{
12+
io::printfn(">%s", trace);
1413
}
15-
//builtin::panicf("FEHifej", "file", "fun", 123);
16-
int x = 2;
17-
int[1] y;
18-
// int z = y[x];
19-
//assert(false, "ofkef");
20-
}
21-
22-
fn void test1()
23-
{
24-
io::printfn("Hello2");
25-
(void)test2();
26-
}
27-
fn void main()
28-
{
29-
test1();
3014
}

src/compiler/compiler_internal.h

-1
Original file line numberDiff line numberDiff line change
@@ -2367,7 +2367,6 @@ void codegen_setup_object_names(Module *module, const char **ir_filename, const
23672367
void target_setup(BuildTarget *build_target);
23682368
int target_alloca_addr_space();
23692369
bool os_is_apple(OsType os_type);
2370-
bool os_supports_stacktrace(OsType os_type);
23712370
bool arch_is_wasm(ArchType type);
23722371

23732372
const char *macos_sysroot(void);

src/compiler/linker.c

-2
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ static void linker_setup_linux(const char ***args_ref, LinkerType linker_type)
390390
{
391391
add_arg("-rdynamic");
392392
}
393-
vec_add(active_target.linker_libs, "dl");
394393
add_arg("-pthread");
395394
return;
396395
}
@@ -438,7 +437,6 @@ static void linker_setup_linux(const char ***args_ref, LinkerType linker_type)
438437
add_arg("-L/usr/lib/");
439438
add_arg("-L/lib/");
440439
add_arg("-m");
441-
add_arg("-ldl");
442440
add_arg(ld_target(platform_target.arch));
443441
}
444442

src/compiler/llvm_codegen_module.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ void gencontext_begin_module(GenContext *c)
169169
LLVMStructSetBody(c->debug.stack_type, types, 5, false);
170170
c->debug.current_stack_ptr = NULL;
171171
c->debug.enable_stacktrace = true;
172-
c->debug.emulated_stacktrace = !os_supports_stacktrace(platform_target.os);
172+
c->debug.emulated_stacktrace = !os_is_apple(platform_target.os);
173173
}
174174
}
175175
c->global_builder = LLVMCreateBuilder();

src/compiler/target.c

-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ int target_alloca_addr_space()
3232
return platform_target.alloca_address_space;
3333
}
3434

35-
bool os_supports_stacktrace(OsType os_type)
36-
{
37-
return os_type == OS_TYPE_LINUX || os_is_apple(os_type);
38-
}
3935
bool os_is_apple(OsType os_type)
4036
{
4137
return os_type == OS_TYPE_TVOS || os_type == OS_TYPE_WATCHOS ||

0 commit comments

Comments
 (0)