Files
buildx/dap/handler.go
T
Jonathan A. Sternberg 1886e232c5 dap: implement variable references
Implement variable references to inspect the state of a stack frame.

Variable reference ids are composed of two sections. A thread mask that
is the first 8 bytes and the remainder is an increasing number that gets
reset each time a thread is resumed. This allows the adapter to know
which thread to delegate the variables request to and allows the
variable references to still remain confined to each thread. An int32 is
used for this because variable references need to be in the range of
(0, 2^32).

At the moment, only the platform variables and some of the exec
operations for an operation. These are labeled as "arguments" to the
stack frame.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2025-07-14 10:59:05 -05:00

63 lines
2.0 KiB
Go

package dap
import (
"context"
"reflect"
"github.com/google/go-dap"
"github.com/pkg/errors"
)
type Context interface {
context.Context
C() chan<- dap.Message
Go(f func(c Context)) bool
}
type dispatchContext struct {
context.Context
srv *Server
ch chan<- dap.Message
}
func (c *dispatchContext) C() chan<- dap.Message {
return c.ch
}
func (c *dispatchContext) Go(f func(c Context)) bool {
return c.srv.Go(f)
}
type HandlerFunc[Req dap.RequestMessage, Resp dap.ResponseMessage] func(c Context, req Req, resp Resp) error
func (h HandlerFunc[Req, Resp]) Do(c Context, req Req) (resp Resp, err error) {
if h == nil {
return resp, errors.New("not implemented")
}
respT := reflect.TypeFor[Resp]()
rv := reflect.New(respT.Elem())
resp = rv.Interface().(Resp)
err = h(c, req, resp)
return resp, err
}
type Handler struct {
Initialize HandlerFunc[*dap.InitializeRequest, *dap.InitializeResponse]
Launch HandlerFunc[*dap.LaunchRequest, *dap.LaunchResponse]
Attach HandlerFunc[*dap.AttachRequest, *dap.AttachResponse]
SetBreakpoints HandlerFunc[*dap.SetBreakpointsRequest, *dap.SetBreakpointsResponse]
ConfigurationDone HandlerFunc[*dap.ConfigurationDoneRequest, *dap.ConfigurationDoneResponse]
Disconnect HandlerFunc[*dap.DisconnectRequest, *dap.DisconnectResponse]
Terminate HandlerFunc[*dap.TerminateRequest, *dap.TerminateResponse]
Continue HandlerFunc[*dap.ContinueRequest, *dap.ContinueResponse]
Next HandlerFunc[*dap.NextRequest, *dap.NextResponse]
Restart HandlerFunc[*dap.RestartRequest, *dap.RestartResponse]
Threads HandlerFunc[*dap.ThreadsRequest, *dap.ThreadsResponse]
StackTrace HandlerFunc[*dap.StackTraceRequest, *dap.StackTraceResponse]
Scopes HandlerFunc[*dap.ScopesRequest, *dap.ScopesResponse]
Variables HandlerFunc[*dap.VariablesRequest, *dap.VariablesResponse]
Evaluate HandlerFunc[*dap.EvaluateRequest, *dap.EvaluateResponse]
Source HandlerFunc[*dap.SourceRequest, *dap.SourceResponse]
}