Fix: absolute path confused for regexp in FindLocation

This commit is contained in:
aarzilli
2015-09-08 22:00:38 +02:00
committed by Derek Parker
parent c0a0e0bdc1
commit 017ce2ae4e
2 changed files with 47 additions and 30 deletions

View File

@ -65,14 +65,18 @@ func parseLocationSpec(locStr string) (LocationSpec, error) {
return &OffsetLocationSpec{offset}, nil return &OffsetLocationSpec{offset}, nil
case '/': case '/':
rx, rest := readRegex(rest[1:]) if rest[len(rest)-1] == '/' {
if len(rest) < 0 { rx, rest := readRegex(rest[1:])
return nil, malformed("non-terminated regular expression") if len(rest) < 0 {
return nil, malformed("non-terminated regular expression")
}
if len(rest) > 1 {
return nil, malformed("no line offset can be specified for regular expression locations")
}
return &RegexLocationSpec{rx}, nil
} else {
return parseLocationSpecDefault(locStr, rest)
} }
if len(rest) > 1 {
return nil, malformed("no line offset can be specified for regular expression locations")
}
return &RegexLocationSpec{rx}, nil
case '*': case '*':
rest = rest[1:] rest = rest[1:]
@ -86,35 +90,43 @@ func parseLocationSpec(locStr string) (LocationSpec, error) {
return &AddrLocationSpec{uint64(addr)}, nil return &AddrLocationSpec{uint64(addr)}, nil
default: default:
v := strings.SplitN(rest, ":", 2) return parseLocationSpecDefault(locStr, rest)
}
}
if len(v) == 1 { func parseLocationSpecDefault(locStr, rest string) (LocationSpec, error) {
n, err := strconv.ParseInt(v[0], 0, 64) malformed := func(reason string) error {
if err == nil { return fmt.Errorf("Malformed breakpoint location \"%s\" at %d: %s", locStr, len(locStr)-len(rest), reason)
return &LineLocationSpec{int(n)}, nil }
}
v := strings.SplitN(rest, ":", 2)
if len(v) == 1 {
n, err := strconv.ParseInt(v[0], 0, 64)
if err == nil {
return &LineLocationSpec{int(n)}, nil
} }
}
spec := &NormalLocationSpec{} spec := &NormalLocationSpec{}
spec.Base = v[0] spec.Base = v[0]
spec.FuncBase = parseFuncLocationSpec(spec.Base) spec.FuncBase = parseFuncLocationSpec(spec.Base)
if len(v) < 2 {
spec.LineOffset = -1
return spec, nil
}
rest = v[1]
var err error
spec.LineOffset, err = strconv.Atoi(rest)
if err != nil || spec.LineOffset < 0 {
return nil, malformed("line offset negative or not a number")
}
if len(v) < 2 {
spec.LineOffset = -1
return spec, nil return spec, nil
} }
rest = v[1]
var err error
spec.LineOffset, err = strconv.Atoi(rest)
if err != nil || spec.LineOffset < 0 {
return nil, malformed("line offset negative or not a number")
}
return spec, nil
} }
func readRegex(in string) (rx string, rest string) { func readRegex(in string) (rx string, rest string) {
@ -225,7 +237,11 @@ func (loc *AddrLocationSpec) Find(d *Debugger, pc uint64, locStr string) ([]api.
} }
func (loc *NormalLocationSpec) FileMatch(path string) bool { func (loc *NormalLocationSpec) FileMatch(path string) bool {
return strings.HasSuffix(path, loc.Base) && (path[len(path)-len(loc.Base)-1] == filepath.Separator) if len(loc.Base) < len(path)-1 {
return strings.HasSuffix(path, loc.Base) && (path[len(path)-len(loc.Base)-1] == filepath.Separator)
} else {
return loc.Base == path
}
} }
type AmbiguousLocationError struct { type AmbiguousLocationError struct {

View File

@ -586,6 +586,7 @@ func TestClientServer_FindLocations(t *testing.T) {
<-c.Continue() <-c.Continue()
locationsprog34Addr := findLocationHelper(t, c, "locationsprog.go:34", false, 1, 0)[0] locationsprog34Addr := findLocationHelper(t, c, "locationsprog.go:34", false, 1, 0)[0]
findLocationHelper(t, c, fmt.Sprintf("%s:34", testProgPath(t, "locationsprog")), false, 1, locationsprog34Addr)
findLocationHelper(t, c, "+1", false, 1, locationsprog34Addr) findLocationHelper(t, c, "+1", false, 1, locationsprog34Addr)
findLocationHelper(t, c, "34", false, 1, locationsprog34Addr) findLocationHelper(t, c, "34", false, 1, locationsprog34Addr)
findLocationHelper(t, c, "-1", false, 1, findLocationHelper(t, c, "locationsprog.go:32", false, 1, 0)[0]) findLocationHelper(t, c, "-1", false, 1, findLocationHelper(t, c, "locationsprog.go:32", false, 1, 0)[0])