diff --git a/example/back b/example/back new file mode 160000 index 0000000..a21ef04 --- /dev/null +++ b/example/back @@ -0,0 +1 @@ +Subproject commit a21ef046ad624ff1bdc6e8de77c38e8c32eec86b diff --git a/example/main_linux.odin b/example/main_linux.odin new file mode 100644 index 0000000..7c8fdc2 --- /dev/null +++ b/example/main_linux.odin @@ -0,0 +1,38 @@ +#+build linux, darwin, netbsd, openbsd, freebsd + +package main + +import "back" +import "base:runtime" + +import "core:fmt" +import "core:mem" +import "core:sys/posix" + +@(private="package") +_register_illegal_instruction_handler :: proc() { + posix.signal(.SIGILL, proc "c" (code: posix.Signal) { + context = runtime.default_context() + + space: [16*mem.Kilobyte]byte + arena: mem.Arena + mem.arena_init(&arena, space[:]) + allocator := mem.arena_allocator(&arena) + + context.allocator = allocator + context.temp_allocator = allocator + + backtrace: { + lines, err := back.lines(back.trace(), allocator, allocator) + if err != nil { + fmt.eprintf("Exception (Code: %i)\nCould not get backtrace: %v\n", code, err) + break backtrace + } + + fmt.eprintf("Exception (Code: %i)\n[back trace]\n", code) + back.print(lines, temp_allocator=allocator) + } + + runtime.exit(int(code)) + }) +} diff --git a/example/main_other.odin b/example/main_other.odin new file mode 100644 index 0000000..a9f000e --- /dev/null +++ b/example/main_other.odin @@ -0,0 +1,11 @@ +#+vet explicit-allocators +#+build !linux +#+build !darwin +#+build !netbsd +#+build !openbsd +#+build !freebsd +#+build !windows +package main + +@(private="package") +_register_illegal_instruction_handler :: proc() {}