2020-07-01 18:01:17 +00:00
|
|
|
package dap
|
|
|
|
|
2020-07-07 13:21:18 +00:00
|
|
|
import "github.com/go-delve/delve/pkg/proc"
|
|
|
|
|
2020-07-01 18:01:17 +00:00
|
|
|
const startHandle = 1000
|
|
|
|
|
|
|
|
// handlesMap maps arbitrary values to unique sequential ids.
|
|
|
|
// This provides convenient abstraction of references, offering
|
|
|
|
// opacity and allowing simplification of complex identifiers.
|
|
|
|
// Based on
|
|
|
|
// https://github.com/microsoft/vscode-debugadapter-node/blob/master/adapter/src/handles.ts
|
|
|
|
type handlesMap struct {
|
|
|
|
nextHandle int
|
|
|
|
handleToVal map[int]interface{}
|
|
|
|
}
|
|
|
|
|
2021-01-14 18:53:12 +00:00
|
|
|
type fullyQualifiedVariable struct {
|
|
|
|
*proc.Variable
|
|
|
|
// A way to load this variable by either using all names in the hierarchic
|
|
|
|
// sequence above this variable (most readable when referenced by the UI)
|
|
|
|
// if available or a special expression based on:
|
|
|
|
// https://github.com/go-delve/delve/blob/master/Documentation/api/ClientHowto.md#loading-more-of-a-variable
|
|
|
|
// Empty if the variable cannot or should not be reloaded.
|
|
|
|
fullyQualifiedNameOrExpr string
|
|
|
|
// True if this represents variable scope
|
|
|
|
isScope bool
|
2021-06-10 16:34:20 +00:00
|
|
|
// startIndex is the index of the first child for an array or slice.
|
|
|
|
// This variable represents a chunk of the array, slice or map.
|
|
|
|
startIndex int
|
2021-01-14 18:53:12 +00:00
|
|
|
}
|
|
|
|
|
2020-07-01 18:01:17 +00:00
|
|
|
func newHandlesMap() *handlesMap {
|
|
|
|
return &handlesMap{startHandle, make(map[int]interface{})}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (hs *handlesMap) reset() {
|
|
|
|
hs.nextHandle = startHandle
|
|
|
|
hs.handleToVal = make(map[int]interface{})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (hs *handlesMap) create(value interface{}) int {
|
|
|
|
next := hs.nextHandle
|
|
|
|
hs.nextHandle++
|
|
|
|
hs.handleToVal[next] = value
|
|
|
|
return next
|
|
|
|
}
|
|
|
|
|
|
|
|
func (hs *handlesMap) get(handle int) (interface{}, bool) {
|
|
|
|
v, ok := hs.handleToVal[handle]
|
|
|
|
return v, ok
|
|
|
|
}
|
2020-07-07 13:21:18 +00:00
|
|
|
|
|
|
|
type variablesHandlesMap struct {
|
|
|
|
m *handlesMap
|
|
|
|
}
|
|
|
|
|
|
|
|
func newVariablesHandlesMap() *variablesHandlesMap {
|
|
|
|
return &variablesHandlesMap{newHandlesMap()}
|
|
|
|
}
|
|
|
|
|
2021-01-14 18:53:12 +00:00
|
|
|
func (hs *variablesHandlesMap) create(value *fullyQualifiedVariable) int {
|
2020-07-07 13:21:18 +00:00
|
|
|
return hs.m.create(value)
|
|
|
|
}
|
|
|
|
|
2021-01-14 18:53:12 +00:00
|
|
|
func (hs *variablesHandlesMap) get(handle int) (*fullyQualifiedVariable, bool) {
|
2020-07-07 13:21:18 +00:00
|
|
|
v, ok := hs.m.get(handle)
|
|
|
|
if !ok {
|
|
|
|
return nil, false
|
|
|
|
}
|
2021-01-14 18:53:12 +00:00
|
|
|
return v.(*fullyQualifiedVariable), true
|
2020-07-07 13:21:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (hs *variablesHandlesMap) reset() {
|
|
|
|
hs.m.reset()
|
|
|
|
}
|