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{}
|
|
|
|
}
|
|
|
|
|
|
|
|
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()}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (hs *variablesHandlesMap) create(value *proc.Variable) int {
|
|
|
|
return hs.m.create(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (hs *variablesHandlesMap) get(handle int) (*proc.Variable, bool) {
|
|
|
|
v, ok := hs.m.get(handle)
|
|
|
|
if !ok {
|
|
|
|
return nil, false
|
|
|
|
}
|
|
|
|
return v.(*proc.Variable), true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (hs *variablesHandlesMap) reset() {
|
|
|
|
hs.m.reset()
|
|
|
|
}
|