delve/pkg/dwarf
Alessandro Arzilli 2c700230de
proc: use stack machine to evaluate expressions (#3508)
* proc: use stack machine to evaluate expressions

This commit splits expression evaluation into two parts. The first part (in
pkg/proc/evalop/evalcompile.go) "compiles" as ast.Expr into a list of
instructions (defined in pkg/proc/evalop/ops.go) for a stack machine
(defined by `proc.(*evalStack)`).
The second part is a stack machine (implemented by `proc.(*EvalScope).eval`
and `proc.(*EvalScope).evalOne`) that has two modes of operation: in the
main mode it executes inteructions from the list (by calling `evalOne`), in
the second mode it executes the call injection protocol by calling
`funcCallStep` repeatedly until it either the protocol finishes, needs more
input from the stack machine (to set call arguments) or fails.

This approach has several benefits:

- it is now possible to remove the goroutine we use to evaluate expression
  and the channel used to communicate with the Continue loop.
- every time we resume the target to execute the call injection protocol we
  need to update several local variables to match the changed state of the
  target, this is now done at the top level of the evaluation loop instead of
  being hidden inside a recurisive evaluator
- using runtime.Pin to pin addresses returned by an injected call would
  allow us to use a more natural evaluation order for function calls, which
  would solve some bugs #3310, allow users to inspect values returned by a
  call injection #1599 and allow implementing some other features #1465. Doing
  this with the recursive evaluator, while keeping backwards compatibility
  with versions of Go that do not have runtime.Pin is very hard. However after
  this change we can simply conditionally change how compileFunctionCall works
  and add some opcodes.

* review round 1

* review round 2
2023-10-17 11:21:59 -07:00
..
dwarfbuilder all: use "len == 0" rather than "len <= 0" when checking empty slice/string (#3439) 2023-07-13 11:30:32 -07:00
frame all: replace deprecated io/ioutil with io and os (#3509) 2023-09-25 11:41:59 -07:00
godwarf proc: use stack machine to evaluate expressions (#3508) 2023-10-17 11:21:59 -07:00
leb128 proc/dwarf: LEB128 encode/decode in separate pkg (#3235) 2023-01-10 12:29:58 -08:00
line all: replace deprecated io/ioutil with io and os (#3509) 2023-09-25 11:41:59 -07:00
loclist proc/dwarf: Move util functions to dwarf package (#3252) 2023-01-16 09:20:20 -08:00
op pkg,service: make receiver names consistent (#3473) 2023-08-17 14:24:43 -07:00
reader dwarf: ignore DeclLine for function args (#3400) 2023-05-31 09:58:47 -07:00
regnum pky/proc: enable function call injection in Delve for linux/ppc64le (#3449) 2023-09-21 10:39:57 -07:00
parseutil_test.go proc/dwarf: Move util functions to dwarf package (#3252) 2023-01-16 09:20:20 -08:00
parseutil.go proc/dwarf: Move util functions to dwarf package (#3252) 2023-01-16 09:20:20 -08:00