-
Notifications
You must be signed in to change notification settings - Fork 16
/
breakpoint.go
47 lines (37 loc) · 948 Bytes
/
breakpoint.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
// Copyright (c) 2020 Timo Savola. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package codegen
import (
"errors"
"gate.computer/wag/internal/gen"
"gate.computer/wag/internal/reader"
)
func makeDebugger(breakpoints map[uint32]gen.Breakpoint, r reader.R) gen.Debugger {
if len(breakpoints) == 0 {
return gen.Debugger{}
}
source, ok := r.(gen.Teller)
if !ok {
panic(errors.New("setting breakpoints without position-aware reader"))
}
return gen.Debugger{
Breakpoints: breakpoints,
Source: source,
CodeOffset: source.Tell(),
}
}
func genBreakpoint(f *gen.Func) {
if f.Debugger.Source == nil {
return
}
offset := uint32(f.Debugger.Source.Tell() - f.Debugger.CodeOffset)
bp, found := f.Debugger.Breakpoints[offset]
if !found {
return
}
opSaveOperands(f)
asm.Breakpoint(f)
bp.Set = true
f.Debugger.Breakpoints[offset] = bp
}