-
Notifications
You must be signed in to change notification settings - Fork 2
/
regdmp.go
189 lines (166 loc) · 3.89 KB
/
regdmp.go
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package ebpflog
import (
"fmt"
"io"
"strings"
)
func getStateMap(in string) map[string]string {
state := struct {
isKey bool
depth int
key string
val string
kv map[string]string
}{
kv: make(map[string]string),
}
state.isKey = true
for _, ch := range in {
switch ch {
case ' ':
if state.depth == 0 && !state.isKey {
state.isKey = true
state.kv[state.key] = state.val
state.key = ""
state.val = ""
continue
}
case '=':
if state.depth == 0 && state.isKey {
state.isKey = false
state.key = state.val
state.val = ""
continue
}
case '(':
state.depth++
case ')':
state.depth--
}
state.val += string(ch)
}
return state.kv
}
type registerInfo struct {
init bool
liveness struct {
read bool
write bool
done bool
}
value string
}
const (
StackInvalid = iota //'?',
StackSpill //'r',
StackMisc //'m',
StackZero //'0',
StackDynptr //'d',
StackIter //'i',
StackMapValue
StackCtx
StackImm
)
type stateDump struct {
regs [11]registerInfo
stack [512 / 8]registerInfo
}
func newRegisterDump(in string) stateDump {
sm := getStateMap(in)
sd := stateDump{}
for k, v := range sm {
if strings.HasPrefix(k, "R") {
idx := 0
flg := ""
cnt, _ := fmt.Sscanf(k, "R%d_%s", &idx, &flg)
if cnt == 0 {
panic(k)
}
sd.regs[idx].init = true
sd.regs[idx].value = v
if strings.ContainsRune(flg, 'r') {
sd.regs[idx].liveness.read = true
}
if strings.ContainsRune(flg, 'w') {
sd.regs[idx].liveness.write = true
}
if strings.ContainsRune(flg, 'D') {
sd.regs[idx].liveness.done = true
}
} else if strings.HasPrefix(k, "fp") {
off := 0
flg := ""
cnt, _ := fmt.Sscanf(k, "fp-%d_%s", &off, &flg)
if cnt == 0 {
panic(k)
}
off -= 8
idx := off / 8
sd.stack[idx].init = true
sd.stack[idx].value = v
if strings.ContainsRune(flg, 'r') {
sd.stack[idx].liveness.read = true
}
if strings.ContainsRune(flg, 'w') {
sd.stack[idx].liveness.write = true
}
if strings.ContainsRune(flg, 'D') {
sd.stack[idx].liveness.done = true
}
} else {
panic(k)
}
}
return sd
}
var gTblId = 0
func (l *logContext) processRegisterDump(in string, w io.Writer) {
sd := newRegisterDump(in)
gTblId++
fmt.Fprintf(w, "<div class=\"regdump\">\n")
fmt.Fprintf(w, "<a class=\"button\" onclick=\"toggleshow(this)\">%sShow/hide preceding state</a>\n", getIcon("👁"))
fmt.Fprintf(w, "<div class=\"regdumpcontent\">\n")
fmt.Fprintf(w, "<div class=\"registers\">Registers\n")
fmt.Fprintf(w, "<table cellspacing=0 class=\"registerst\">\n")
fmt.Fprintf(w, "<tr><th>Reg</th><th>Liveness</th><th>Value</th></tr>\n")
for idx, r := range sd.regs {
liv := ""
if r.liveness.read {
liv += "+read "
}
if r.liveness.write {
liv += "+write "
}
if r.liveness.done {
liv += "+done "
}
fmt.Fprintf(w, "<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n", l.regname(idx), liv, r.value)
}
fmt.Fprintf(w, "</table><!-- registerst -->\n") // registerst
fmt.Fprintf(w, "</div><!-- registers -->\n") // registers
// stack
fmt.Fprintf(w, "<div class=\"registers\">Stack dump\n") // stack
fmt.Fprintf(w, "<table cellspacing=0 class=\"registerst\">\n")
fmt.Fprintf(w, "<tr><th>Offset</th><th>Liveness</th><th>Value</th></tr>\n")
for idx, r := range sd.stack {
if !r.init {
continue
}
liv := ""
if r.liveness.read {
liv += "+read "
}
if r.liveness.write {
liv += "+write "
}
if r.liveness.done {
liv += "+done "
}
stk := fmt.Sprintf("fp-%d", 8*(idx+1))
fmt.Fprintf(w, "<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n", stk, liv, r.value)
}
fmt.Fprintf(w, "</table><!-- registerst -->\n") // registerst
fmt.Fprintf(w, "</div><!-- registerst -->\n") // registers
fmt.Fprintf(w, "</div><!-- regdumpcontent -->\n") // regdumpcontent
fmt.Fprintf(w, "</div><!-- regdump -->\n") // regdump
}