Files
buildx/dap/handler.go
T
Jonathan A. Sternberg 4f2e23a9b8 dap: add stack traces with next and continue functionality
It is now possible to send next and continue as separate signals. When
executing a build, the debug adapter will divide the LLB graph into
regions. Each region corresponds to an uninterrupted chain of
instructions. It will also record which regions depend on which other
ones.

This determines the execution order and it also determines what the
stack traces look like.

When continue is used, we will attempt to evaluate the last leaf node
(the head). If we push next, we will determine which digest would be the
next one to be processed.

In the future, this will be used to also support breakpoints.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2025-07-03 09:18:55 -05:00

61 lines
1.9 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]
Evaluate HandlerFunc[*dap.EvaluateRequest, *dap.EvaluateResponse]
Source HandlerFunc[*dap.SourceRequest, *dap.SourceResponse]
}