File: ops.go

package info (click to toggle)
delve 1.24.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 14,092 kB
  • sloc: ansic: 111,943; sh: 169; asm: 141; makefile: 43; python: 23
file content (326 lines) | stat: -rw-r--r-- 8,899 bytes parent folder | download
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
package evalop

import (
	"go/ast"
	"go/constant"

	"github.com/go-delve/delve/pkg/dwarf/godwarf"
)

// Op is a stack machine opcode
type Op interface {
	depthCheck() (npop, npush int)
}

// PushCurg pushes the current goroutine on the stack.
type PushCurg struct {
}

func (*PushCurg) depthCheck() (npop, npush int) { return 0, 1 }

// PushFrameoff pushes the frame offset for the current frame on the stack.
type PushFrameoff struct {
}

func (*PushFrameoff) depthCheck() (npop, npush int) { return 0, 1 }

// PushThreadID pushes the ID of the current thread on the stack.
type PushThreadID struct {
}

func (*PushThreadID) depthCheck() (npop, npush int) { return 0, 1 }

// PushRangeParentOffset pushes the frame offset of the range-over-func closure body parent.
type PushRangeParentOffset struct {
}

func (*PushRangeParentOffset) depthCheck() (npop, npush int) { return 0, 1 }

// PushConst pushes a constant on the stack.
type PushConst struct {
	Value constant.Value
}

func (*PushConst) depthCheck() (npop, npush int) { return 0, 1 }

// PushLocal pushes the local variable with the given name on the stack.
type PushLocal struct {
	Name  string
	Frame int64
}

func (*PushLocal) depthCheck() (npop, npush int) { return 0, 1 }

// PushIdent pushes a local or global variable or a predefined identifier
// (true, false, etc) or the value of a register on the stack.
type PushIdent struct {
	Name string
}

func (*PushIdent) depthCheck() (npop, npush int) { return 0, 1 }

// PushPackageVarOrSelect pushes the value of Name.Sel on the stack, which
// could either be a global variable (with the package name specified), or a
// field of a local variable.
type PushPackageVarOrSelect struct {
	Name, Sel    string
	NameIsString bool
}

func (*PushPackageVarOrSelect) depthCheck() (npop, npush int) { return 0, 1 }

// PushNil pushes an untyped nil on the stack.
type PushNil struct {
}

func (*PushNil) depthCheck() (npop, npush int) { return 0, 1 }

// PushLen pushes the length of the variable at the top of the stack into
// the stack.
type PushLen struct {
}

func (*PushLen) depthCheck() (npop, npush int) { return 1, 2 }

// Select replaces the topmost stack variable v with v.Name.
type Select struct {
	Name string
}

func (*Select) depthCheck() (npop, npush int) { return 1, 1 }

// TypeAssert replaces the topmost stack variable v with v.(DwarfType).
type TypeAssert struct {
	DwarfType godwarf.Type
	Node      *ast.TypeAssertExpr
}

func (*TypeAssert) depthCheck() (npop, npush int) { return 1, 1 }

// PointerDeref replaces the topmost stack variable v with *v.
type PointerDeref struct {
	Node *ast.StarExpr
}

func (*PointerDeref) depthCheck() (npop, npush int) { return 1, 1 }

// Unary applies the given unary operator to the topmost stack variable.
type Unary struct {
	Node *ast.UnaryExpr
}

func (*Unary) depthCheck() (npop, npush int) { return 1, 1 }

// AddrOf replaces the topmost stack variable v with &v.
type AddrOf struct {
	Node *ast.UnaryExpr
}

func (*AddrOf) depthCheck() (npop, npush int) { return 1, 1 }

// TypeCast replaces the topmost stack variable v with (DwarfType)(v).
type TypeCast struct {
	DwarfType godwarf.Type
	Node      *ast.CallExpr
}

func (*TypeCast) depthCheck() (npop, npush int) { return 1, 1 }

// Reslice implements a reslice operation.
// If HasHigh is set it pops three variables, low, high and v, and pushes
// v[low:high].
// Otherwise it pops two variables, low and v, and pushes v[low:].
// If TrustLen is set when the variable resulting from the reslice is loaded it will be fully loaded.
type Reslice struct {
	HasHigh  bool
	TrustLen bool
	Node     *ast.SliceExpr
}

func (op *Reslice) depthCheck() (npop, npush int) {
	if op.HasHigh {
		return 3, 1
	} else {
		return 2, 1
	}
}

// Index pops two variables, idx and v, and pushes v[idx].
type Index struct {
	Node *ast.IndexExpr
}

func (*Index) depthCheck() (npop, npush int) { return 2, 1 }

// Jump looks at the topmost stack variable and if it satisfies the
// condition specified by When it jumps to the stack machine instruction at
// Target+1.
// If Pop is set the topmost stack variable is also popped.
type Jump struct {
	When   JumpCond
	Pop    bool
	Target int
	Node   ast.Expr
}

func (jmpif *Jump) depthCheck() (npop, npush int) {
	switch jmpif.When {
	case JumpIfTrue, JumpIfFalse, JumpIfAllocStringChecksFail:
		if jmpif.Pop {
			return 1, 0
		} else {
			return 1, 1
		}
	}
	return 0, 0
}

// JumpCond specifies a condition for the Jump instruction.
type JumpCond uint8

const (
	JumpIfFalse JumpCond = iota
	JumpIfTrue
	JumpIfAllocStringChecksFail
	JumpAlways
	JumpIfPinningDone
)

// Binary pops two variables from the stack, applies the specified binary
// operator to them and pushes the result back on the stack.
type Binary struct {
	Node *ast.BinaryExpr
}

func (*Binary) depthCheck() (npop, npush int) { return 2, 1 }

// BoolToConst pops the topmost variable from the stack, which must be a
// boolean variable, and converts it to a constant.
type BoolToConst struct {
}

func (*BoolToConst) depthCheck() (npop, npush int) { return 1, 1 }

// Pop removes the topmost variable from the stack.
type Pop struct {
}

func (*Pop) depthCheck() (npop, npush int) { return 1, 0 }

// Roll removes the n-th element of the stack and pushes it back in at the top
type Roll struct {
	N int
}

func (*Roll) depthCheck() (npop, npush int) { return 1, 1 }

// BuiltinCall pops len(Args) argument from the stack, calls the specified
// builtin on them and pushes the result back on the stack.
type BuiltinCall struct {
	Name string
	Args []ast.Expr
}

func (bc *BuiltinCall) depthCheck() (npop, npush int) {
	return len(bc.Args), 1
}

// CallInjectionStart starts call injection by calling
// runtime.debugCallVn.
type CallInjectionStart struct {
	id      int  // identifier for all the call injection instructions that belong to the same sequence, this only exists to make reading listings easier
	HasFunc bool // target function already pushed on the stack
	Node    *ast.CallExpr
}

func (*CallInjectionStart) depthCheck() (npop, npush int) { return 0, 1 }

// CallInjectionSetTarget starts the call injection, after
// runtime.debugCallVn set up the stack for us, by copying the entry point
// of the function, setting the closure register and copying the receiver.
type CallInjectionSetTarget struct {
	id int
}

func (*CallInjectionSetTarget) depthCheck() (npop, npush int) { return 1, 0 }

// CallInjectionCopyArg copies one argument for call injection.
type CallInjectionCopyArg struct {
	id      int
	ArgNum  int
	ArgExpr ast.Expr
}

func (*CallInjectionCopyArg) depthCheck() (npop, npush int) { return 1, 0 }

// CallInjectionComplete resumes target execution so that the injected call can run.
// If DoPinning is true it stops after the call is completed without undoing
// the call injection frames so that address pinning for the return value
// can be performed, see CallInjectionComplete2.
type CallInjectionComplete struct {
	id        int
	DoPinning bool
}

func (op *CallInjectionComplete) depthCheck() (npop, npush int) {
	if op.DoPinning {
		return 0, 0
	} else {
		return 0, 1
	}
}

// CallInjectionComplete2 if DoPinning was passed to CallInjectionComplete
// this will finish the call injection protocol and push the evaluation
// result on the stack.
type CallInjectionComplete2 struct {
	id int
}

func (*CallInjectionComplete2) depthCheck() (npop, npush int) { return 0, 1 }

// CallInjectionStartSpecial starts call injection for a function with a
// name and arguments known at compile time.
type CallInjectionStartSpecial struct {
	id     int
	FnName string
	ArgAst []ast.Expr
}

func (*CallInjectionStartSpecial) depthCheck() (npop, npush int) { return 0, 1 }

// ConvertAllocToString pops two variables from the stack, a constant string
// and the return value of runtime.mallocgc (mallocv), copies the contents
// of the string at the address in mallocv and pushes on the stack a new
// string value that uses the backing storage of mallocv.
type ConvertAllocToString struct {
}

func (*ConvertAllocToString) depthCheck() (npop, npush int) { return 2, 1 }

// SetValue pops to variables from the stack, lhv and rhv, and sets lhv to
// rhv.
type SetValue struct {
	lhe, Rhe ast.Expr
}

func (*SetValue) depthCheck() (npop, npush int) { return 2, 0 }

// SetDebugPinner pops one variable from the stack and uses it as the saved debug pinner.
type SetDebugPinner struct {
}

func (*SetDebugPinner) depthCheck() (npop, npush int) { return 1, 0 }

// PushDebugPinner pushes the debug pinner on the stack.
type PushDebugPinner struct {
}

func (*PushDebugPinner) depthCheck() (npop, npush int) { return 0, 1 }

// PushPinAddress pushes an address to pin on the stack (as an
// unsafe.Pointer) and removes it from the list of addresses to pin.
type PushPinAddress struct {
}

func (*PushPinAddress) depthCheck() (npop, npush int) { return 0, 1 }