Skip to content

Commit

Permalink
use libunwind instead of relying on frame-pointers for macos
Browse files Browse the repository at this point in the history
  • Loading branch information
laytan committed Dec 30, 2023
1 parent 55310eb commit 832563c
Show file tree
Hide file tree
Showing 8 changed files with 312 additions and 187 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
indent_style = tab
indent_size = 4
trim_trailing_whitespace = true

[*.yml]
indent_style = space
indent_size = 2
26 changes: 26 additions & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Examples
on:
push:
workflow_dispatch:

env:
FORCE_COLOR: "1"

jobs:
examples:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- uses: laytan/setup-odin@v1
- name: manual
run: odin run examples/manual -vet -strict-style
- name: allocator
run: odin run examples/allocator -vet -strict-style
- name: segfault
run: odin run examples/segfault -vet-strict-style
- name: assert
run: odin run examples/assert_backtrace -vet-strict-style
12 changes: 6 additions & 6 deletions allocator.odin
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ Result_Type :: enum {

tracking_allocator_print_results :: proc(t: ^Tracking_Allocator, type: Result_Type = .Both) {
context.allocator = t.internals_allocator

Work :: struct {
trace: Backtrace,
result: []Message,
Expand All @@ -218,7 +218,7 @@ tracking_allocator_print_results :: proc(t: ^Tracking_Allocator, type: Result_Ty
i += 1
}
}

if type == .Both || type == .Bad_Frees {
for bad_free in t.bad_free_array {
work[i].trace = bad_free.backtrace
Expand All @@ -230,7 +230,7 @@ tracking_allocator_print_results :: proc(t: ^Tracking_Allocator, type: Result_Ty

extra_threads_done: sync.Wait_Group
sync.wait_group_add(&extra_threads_done, extra_threads + 1)

// Processes the slice of work given.
thread_proc :: proc(work: ^[]Work, start: int, end: int, extra_threads_done: ^sync.Wait_Group) {
defer sync.wait_group_done(extra_threads_done)
Expand All @@ -257,7 +257,7 @@ tracking_allocator_print_results :: proc(t: ^Tracking_Allocator, type: Result_Ty
for _, leak in t.allocation_map {
defer li+=1

fmt.eprintf("\x1b[31m%v leaked %v bytes\x1b[0m\n", leak.location, leak.size)
fmt.eprintf("\x1b[31m%v leaked %m\x1b[0m\n", leak.location, leak.size)
fmt.eprintln("[back trace]")

work_leak := work_leaks[li]
Expand All @@ -273,7 +273,7 @@ tracking_allocator_print_results :: proc(t: ^Tracking_Allocator, type: Result_Ty

if len(t.bad_free_array) > 0 do fmt.eprintln()
}

if type == .Both || type == .Bad_Frees {
for bad_free, fi in t.bad_free_array {
fmt.eprintf(
Expand All @@ -291,7 +291,7 @@ tracking_allocator_print_results :: proc(t: ^Tracking_Allocator, type: Result_Ty
}

format(work_free.result)

if fi + 1 < len(t.bad_free_array) do fmt.eprintln()
}
}
Expand Down
29 changes: 6 additions & 23 deletions obacktracing.odin
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ import "core:os"
import "core:runtime"
import "core:text/table"

_ :: os

BACKTRACE_SIZE :: #config(BACKTRACE_SIZE, 16)

backtrace_get :: proc(max_len: i32, allocator := context.allocator) -> Backtrace {
return _backtrace_get(max_len, allocator)
backtrace_get :: #force_no_inline proc(max_len: i32, allocator := context.allocator) -> Backtrace {
return #force_inline _backtrace_get(max_len, allocator)
}

backtrace_delete :: proc(b: Backtrace) {
_backtrace_delete(b)
backtrace_delete :: proc(b: Backtrace, allocator := context.allocator) {
_backtrace_delete(b, allocator)
}

Backtrace :: _Backtrace
Expand All @@ -26,23 +24,8 @@ Message :: struct {
symbol: string,
}

messages_delete :: proc(msgs: []Message) {
for msg in msgs do message_delete(msg)
delete(msgs)
}

message_delete :: proc(m: Message) {
delete(m.location)

when ODIN_OS == .Windows {
delete(m.symbol)
return
}

// There is no symbol info outside of debug mode.
when ODIN_DEBUG {
if m.symbol != "" && m.symbol != "??" do delete(m.symbol)
}
messages_delete :: proc(msgs: []Message, allocator := context.allocator) {
_messages_delete(msgs, allocator)
}

EAGAIN :: os.EAGAIN when ODIN_OS != .Windows else 5
Expand Down
Loading

0 comments on commit 832563c

Please sign in to comment.