Illegal instruction handler
This commit is contained in:
parent
e5fccefec0
commit
0545282292
5 changed files with 294 additions and 252 deletions
36
signal_handler_linux.odin
Normal file
36
signal_handler_linux.odin
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#+build linux
|
||||
|
||||
package main
|
||||
|
||||
import "libraries/back"
|
||||
import "core:sys/posix"
|
||||
import "base:runtime"
|
||||
import "core:mem"
|
||||
import "core:fmt"
|
||||
|
||||
_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))
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue