Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions dap/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"io"
"path"
"path/filepath"
"slices"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -598,22 +597,22 @@ func (b *breakpointMap) Set(fname string, sbps []dap.SourceBreakpoint) (breakpoi
return breakpoints
}

func (b *breakpointMap) Intersect(ctx Context, src *pb.Source, ws string) map[digest.Digest]int {
func (b *breakpointMap) Intersect(ctx Context, src *pb.Source) map[digest.Digest]int {
b.mu.Lock()
defer b.mu.Unlock()

digests := make(map[digest.Digest]int)

for dgst, locs := range src.Locations {
if id := b.intersect(ctx, src, locs, ws); id > 0 {
if id := b.intersect(ctx, src, locs); id > 0 {
digests[digest.Digest(dgst)] = id
}
}

// Mark unverified breakpoints as failed at this point since we couldn't find an area
// in the source where they applied.
for _, info := range src.Infos {
fname := filepath.Join(ws, info.Filename)
fname := info.Filename

bps := b.byPath[fname]
for _, bp := range bps {
Expand All @@ -633,7 +632,7 @@ func (b *breakpointMap) Intersect(ctx Context, src *pb.Source, ws string) map[di
return digests
}

func (b *breakpointMap) intersect(ctx Context, src *pb.Source, locs *pb.Locations, ws string) int {
func (b *breakpointMap) intersect(ctx Context, src *pb.Source, locs *pb.Locations) int {
overlaps := func(r *pb.Range, bp *dap.Breakpoint) bool {
if bp.Line < int(r.Start.Line) || bp.Line > int(r.End.Line) {
return false
Expand All @@ -654,7 +653,7 @@ func (b *breakpointMap) intersect(ctx Context, src *pb.Source, locs *pb.Location
r := loc.Ranges[0]

info := src.Infos[loc.SourceIndex]
fname := filepath.Join(ws, info.Filename)
fname := info.Filename

bps := b.byPath[fname]
if len(bps) == 0 {
Expand Down
4 changes: 2 additions & 2 deletions dap/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ func TestBreakpointMapIntersectVerified(t *testing.T) {
src := &pb.Source{
Locations: srcLocs,
Infos: []*pb.SourceInfo{
{Filename: filename},
{Filename: fpath},
},
}

ctx := newBreakpointTestContext(t)
digests := bm.Intersect(ctx, src, ws)
digests := bm.Intersect(ctx, src)
wantMatches := 0
for _, bc := range breakpointCases {
if bc.expectVerified {
Expand Down
43 changes: 26 additions & 17 deletions dap/thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package dap

import (
"context"
"path"
"path/filepath"
"slices"
"strings"
"sync"

"github.com/docker/buildx/build"
Expand All @@ -31,10 +31,10 @@ type thread struct {
variables *variableReferences

// Inputs to the evaluate call.
c gateway.Client
ref gateway.Reference
meta map[string][]byte
sourcePath string
c gateway.Client
ref gateway.Reference
meta map[string][]byte
sourceInfoMap func(*pb.Source) *pb.Source

// LLB state for the evaluate call.
def *llb.Definition
Expand Down Expand Up @@ -107,14 +107,21 @@ func (t *thread) init(ctx Context, c gateway.Client, ref gateway.Reference, meta
t.c = c
t.ref = ref
t.meta = meta

// Combine the dockerfile directory with the context path to find the
// real base path. The frontend will report the base path as the filename.
dir := path.Dir(inputs.DockerfilePath)
if !path.IsAbs(dir) {
dir = path.Join(inputs.ContextPath, dir)
t.sourceInfoMap = func(s *pb.Source) *pb.Source {
s = s.CloneVT()
for _, sinfo := range s.Infos {
// Map the filename from the source info from the frontend location to the
// client location.
fname := strings.Replace(sinfo.Filename, inputs.DockerfileMappingDst, inputs.DockerfileMappingSrc, 1)

// Convert to an absolute path.
if abspath, err := filepath.Abs(fname); err == nil {
fname = abspath
}
sinfo.Filename = fname
}
return s
}
t.sourcePath = dir

if err := t.getLLBState(ctx); err != nil {
return err
Expand Down Expand Up @@ -252,7 +259,7 @@ func (t *thread) getStackFrame(dgst digest.Digest, next *step) *frame {
f.setNameFromMeta(meta)
}
if loc, ok := t.def.Source.Locations[string(dgst)]; ok {
f.fillLocation(t.def, loc, t.sourcePath, next)
f.fillLocation(t.def, loc, next)
}
t.frames[int32(f.Id)] = f
return f
Expand Down Expand Up @@ -296,7 +303,6 @@ func (t *thread) reset() {
t.c = nil
t.ref = nil
t.meta = nil
t.sourcePath = ""
t.ops = nil
}

Expand Down Expand Up @@ -462,9 +468,12 @@ func (t *thread) getLLBState(ctx Context) error {
return err
}

if t.sourceInfoMap != nil {
t.def.Source = t.sourceInfoMap(t.def.Source)
}

for _, src := range t.def.Source.Infos {
fname := filepath.Join(t.sourcePath, src.Filename)
t.sourceMap.Put(ctx, fname, src.Data)
t.sourceMap.Put(ctx, src.Filename, src.Data)
}

t.ops = make(map[digest.Digest]*pb.Op, len(t.def.Def))
Expand All @@ -483,7 +492,7 @@ func (t *thread) getLLBState(ctx Context) error {
}

func (t *thread) setBreakpoints(ctx Context) {
t.bps = t.breakpointMap.Intersect(ctx, t.def.Source, t.sourcePath)
t.bps = t.breakpointMap.Intersect(ctx, t.def.Source)
}

func (t *thread) seekNext(ctx Context, from *step, action stepType) (string, *step, map[string]gateway.Reference, error) {
Expand Down
4 changes: 2 additions & 2 deletions dap/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (f *frame) setNameFromMeta(meta llb.OpMetadata) {
// TODO: should we infer the name from somewhere else?
}

func (f *frame) fillLocation(def *llb.Definition, loc *pb.Locations, ws string, next *step) {
func (f *frame) fillLocation(def *llb.Definition, loc *pb.Locations, next *step) {
for _, l := range loc.Locations {
for _, r := range l.Ranges {
if next != nil && f.Line != 0 {
Expand All @@ -57,7 +57,7 @@ func (f *frame) fillLocation(def *llb.Definition, loc *pb.Locations, ws string,
info := def.Source.Infos[l.SourceIndex]
f.Source = &dap.Source{
Name: path.Base(info.Filename),
Path: filepath.Join(ws, info.Filename),
Path: info.Filename,
}

// If we do not have a next operation, then we don't have
Expand Down
Loading