Skip to content

Commit 1e3c447

Browse files
committed
dap: refactor how step in/step out works
Change how breakpoints and stepping works. These now work more how you would expect another programming language to work. Breakpoints happen before the step has been invoked rather than after which means you can inspect the state before the command runs. This has the advantage of being more intuitive for someone familiar with other debuggers. The negative is that you can't run to after a certain step as easily as you could before. Instead, you would run to that stage and then use next to go to the step directly afterwards. Step in and out also now have different behaviors. When a step has multiple inputs, the inputs of non-zero index are considered like "function calls". The most common cause of this is to use `COPY --from` or a bind mount. Stepping into these will cause it to jump to the beginning of the call chain for that branch. Using step out will exit back to the location where step in was used. This change also makes it so some steps may be invoked multiple times in the callgraph if multiple steps depend on them. The reused steps will still be cached, but you may end up stepping through more lines than the previous implementation. Stack traces now represent where these step in and step out areas happen rather than the previous steps. This can help you know from where a certain step is being used. Signed-off-by: Jonathan A. Sternberg <[email protected]>
1 parent fea53ad commit 1e3c447

File tree

4 files changed

+251
-298
lines changed

4 files changed

+251
-298
lines changed

dap/adapter.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -161,26 +161,21 @@ func (d *Adapter[C]) Next(c Context, req *dap.NextRequest, resp *dap.NextRespons
161161
}
162162

163163
func (d *Adapter[C]) StepIn(c Context, req *dap.StepInRequest, resp *dap.StepInResponse) error {
164-
var (
165-
subReq dap.NextRequest
166-
subResp dap.NextResponse
167-
)
164+
d.threadsMu.RLock()
165+
t := d.threads[req.Arguments.ThreadId]
166+
d.threadsMu.RUnlock()
168167

169-
subReq.Arguments.ThreadId = req.Arguments.ThreadId
170-
subReq.Arguments.SingleThread = req.Arguments.SingleThread
171-
subReq.Arguments.Granularity = req.Arguments.Granularity
172-
return d.Next(c, &subReq, &subResp)
168+
t.StepIn()
169+
return nil
173170
}
174171

175172
func (d *Adapter[C]) StepOut(c Context, req *dap.StepOutRequest, resp *dap.StepOutResponse) error {
176-
var (
177-
subReq dap.ContinueRequest
178-
subResp dap.ContinueResponse
179-
)
180-
181-
subReq.Arguments.ThreadId = req.Arguments.ThreadId
182-
subReq.Arguments.SingleThread = req.Arguments.SingleThread
183-
return d.Continue(c, &subReq, &subResp)
173+
d.threadsMu.RLock()
174+
t := d.threads[req.Arguments.ThreadId]
175+
d.threadsMu.RUnlock()
176+
177+
t.StepOut()
178+
return nil
184179
}
185180

186181
func (d *Adapter[C]) SetBreakpoints(c Context, req *dap.SetBreakpointsRequest, resp *dap.SetBreakpointsResponse) error {

dap/eval.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ func replCmd[Flags any, RetVal any](ctx Context, name string, resp *dap.Evaluate
9393
}
9494

9595
func (t *thread) Exec(ctx Context, args []string) (message string, retErr error) {
96+
if t.rCtx == nil {
97+
return "", errors.New("no container context for exec")
98+
}
99+
96100
cfg := &build.InvokeConfig{Tty: true}
97101
if len(cfg.Entrypoint) == 0 && len(cfg.Cmd) == 0 {
98102
cfg.Entrypoint = []string{"/bin/sh"} // launch shell by default

0 commit comments

Comments
 (0)