-
Notifications
You must be signed in to change notification settings - Fork 7
/
back_other.odin
100 lines (79 loc) · 2.3 KB
/
back_other.odin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package back
@require import "base:runtime"
@require import "core:fmt"
when USE_FALLBACK {
when ODIN_OPTIMIZATION_MODE == .None {
#panic("the `back` package's `other` mode requires at least `-o:minimal` to work (it requires `#force_inline` to actually be applied)")
}
@(no_instrumentation)
other_instrumentation_enter :: #force_inline proc "contextless" (a, b: rawptr, loc: runtime.Source_Code_Location) {
_other_instrumentation_enter(a, b, loc)
}
@(no_instrumentation)
other_instrumentation_exit :: #force_inline proc "contextless" (a, b: rawptr, loc: runtime.Source_Code_Location) {
_other_instrumentation_exit(a, b, loc)
}
@(private="package")
_Trace_Entry :: runtime.Source_Code_Location
@(private="package")
_trace :: proc(buf: Trace) -> (n: int) {
lframe := frame
for lframe != nil && n < len(buf) {
buf[n] = lframe.loc
n += 1
lframe = lframe.prev
}
return
}
@(private="package")
_lines_destroy :: proc(lines: []Line) {
for line in lines {
delete(line.location)
}
}
@(private="package")
_lines :: proc(bt: Trace) -> (out: []Line, err: Lines_Error) {
out = make([]Line, len(bt))
for t, i in bt {
out[i].symbol = t.procedure
out[i].location = fmt.aprintf("%s(%v:%v)", t.file_path, t.line, t.column)
}
return
}
when ODIN_OS != .Linux && ODIN_OS != .Darwin {
@(private="package")
_register_segfault_handler :: proc() {}
}
@(private="file")
Frame :: struct {
prev: ^Frame,
loc: runtime.Source_Code_Location,
}
@(thread_local, private="file")
frame: ^Frame
when OTHER_CUSTOM_INSTRUMENTATION {
@(no_instrumentation, private="file")
_other_instrumentation_enter :: #force_inline proc "contextless" (_, _: rawptr, loc: runtime.Source_Code_Location) {
frame = &Frame{
prev = frame,
loc = loc,
}
}
@(no_instrumentation, private="file")
_other_instrumentation_exit :: #force_inline proc "contextless" (_, _: rawptr, loc: runtime.Source_Code_Location) {
frame = frame.prev
}
} else {
@(instrumentation_enter, private="file")
_other_instrumentation_enter :: #force_inline proc "contextless" (_, _: rawptr, loc: runtime.Source_Code_Location) {
frame = &Frame{
prev = frame,
loc = loc,
}
}
@(instrumentation_exit, private="file")
_other_instrumentation_exit :: #force_inline proc "contextless" (_, _: rawptr, loc: runtime.Source_Code_Location) {
frame = frame.prev
}
}
}