service/debugger: support relative paths in location expressions (#1478)

If the user specifies a relative path in a location expression try to
match it relative to the path of the executable.

Fixes #1474
This commit is contained in:
chainhelen 2019-02-21 13:21:41 -06:00 committed by Derek Parker
parent ff7b81c407
commit 32c89cf12a

@ -3,6 +3,7 @@ package debugger
import (
"fmt"
"go/constant"
"path"
"path/filepath"
"reflect"
"runtime"
@ -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`
@ -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