Skip to content

Commit

Permalink
service/debugger: support relative paths in location expressions
Browse files Browse the repository at this point in the history
If the user specifies a relative path in a location expression try to
match it relative to the path of the executable.

Fixes go-delve#1474
  • Loading branch information
chainhelen committed Feb 14, 2019
1 parent 2e0a331 commit d07c223
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion service/debugger/locations.go
Expand Up @@ -3,6 +3,7 @@ package debugger
import (
"fmt"
"go/constant"
"path"
"path/filepath"
"reflect"
"runtime"
Expand Down Expand Up @@ -293,6 +294,10 @@ func (loc *NormalLocationSpec) FileMatch(path string) bool {
return partialPathMatch(loc.Base, path)
}

func tryMatchRelativePathByProc(expr, debugname, file string) bool {
return len(expr) > 0 && expr[0] == '.' && file == path.Join(path.Dir(debugname), expr)
}

func partialPathMatch(expr, path string) bool {
if runtime.GOOS == "windows" {
// Accept `expr` which is case-insensitive and slash-insensitive match to `path`
Expand Down Expand Up @@ -329,7 +334,7 @@ func (loc *NormalLocationSpec) Find(d *Debugger, scope *proc.EvalScope, locStr s
limit := maxFindLocationCandidates
var candidateFiles []string
for _, file := range d.target.BinInfo().Sources {
if loc.FileMatch(file) {
if loc.FileMatch(file) || (len(d.processArgs) >= 1 && tryMatchRelativePathByProc(loc.Base, d.processArgs[0], file)) {
candidateFiles = append(candidateFiles, file)
if len(candidateFiles) >= limit {
break
Expand Down

0 comments on commit d07c223

Please sign in to comment.