diff --git a/_fixtures/locationsprog.go b/_fixtures/locationsprog.go index cea5e8ce..7aca93fc 100644 --- a/_fixtures/locationsprog.go +++ b/_fixtures/locationsprog.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "io/ioutil" ) type SomeType struct { @@ -32,4 +33,5 @@ func main() { fmt.Printf("%s %s\n", a.String(), b.String()) a.SomeFunction() anotherFunction() + ioutil.ReadFile("nonexistent.file.txt") } diff --git a/service/debugger/locations.go b/service/debugger/locations.go index f20bfb47..17227dda 100644 --- a/service/debugger/locations.go +++ b/service/debugger/locations.go @@ -156,10 +156,6 @@ func readRegex(in string) (rx string, rest string) { } func parseFuncLocationSpec(in string) *FuncLocationSpec { - if strings.Index(in, "/") >= 0 { - return nil - } - v := strings.Split(in, ".") var spec FuncLocationSpec switch len(v) { @@ -171,6 +167,8 @@ func parseFuncLocationSpec(in string) *FuncLocationSpec { r := stripReceiverDecoration(v[0]) if r != v[0] { spec.ReceiverName = r + } else if strings.Index(r, "/") >= 0 { + spec.PackageName = r } else { spec.PackageOrReceiverName = r } @@ -184,6 +182,10 @@ func parseFuncLocationSpec(in string) *FuncLocationSpec { return nil } + if strings.Index(spec.BaseName, "/") >= 0 || strings.Index(spec.ReceiverName, "/") >= 0 { + return nil + } + return &spec } diff --git a/service/test/integration_test.go b/service/test/integration_test.go index 22d8caff..c38e027f 100644 --- a/service/test/integration_test.go +++ b/service/test/integration_test.go @@ -556,7 +556,7 @@ func findLocationHelper(t *testing.T, c service.Client, loc string, shouldErr bo func TestClientServer_FindLocations(t *testing.T) { withTestClient("locationsprog", t, func(c service.Client) { - someFunctionCallAddr := findLocationHelper(t, c, "locationsprog.go:26", false, 1, 0)[0] + someFunctionCallAddr := findLocationHelper(t, c, "locationsprog.go:27", false, 1, 0)[0] findLocationHelper(t, c, "anotherFunction:1", false, 1, someFunctionCallAddr) findLocationHelper(t, c, "main.anotherFunction:1", false, 1, someFunctionCallAddr) findLocationHelper(t, c, "anotherFunction", false, 1, someFunctionCallAddr) @@ -567,20 +567,23 @@ func TestClientServer_FindLocations(t *testing.T) { findLocationHelper(t, c, "String", true, 0, 0) findLocationHelper(t, c, "main.String", true, 0, 0) - someTypeStringFuncAddr := findLocationHelper(t, c, "locationsprog.go:14", false, 1, 0)[0] - otherTypeStringFuncAddr := findLocationHelper(t, c, "locationsprog.go:18", false, 1, 0)[0] + someTypeStringFuncAddr := findLocationHelper(t, c, "locationsprog.go:15", false, 1, 0)[0] + otherTypeStringFuncAddr := findLocationHelper(t, c, "locationsprog.go:19", false, 1, 0)[0] findLocationHelper(t, c, "SomeType.String", false, 1, someTypeStringFuncAddr) findLocationHelper(t, c, "(*SomeType).String", false, 1, someTypeStringFuncAddr) findLocationHelper(t, c, "main.SomeType.String", false, 1, someTypeStringFuncAddr) findLocationHelper(t, c, "main.(*SomeType).String", false, 1, someTypeStringFuncAddr) + // Issue #275 + findLocationHelper(t, c, "io/ioutil.ReadFile", false, 1, 0) + stringAddrs := findLocationHelper(t, c, "/^main.*Type.*String$/", false, 2, 0) if otherTypeStringFuncAddr != stringAddrs[0] && otherTypeStringFuncAddr != stringAddrs[1] { t.Fatalf("Wrong locations returned for \"/.*Type.*String/\", got: %v expected: %v and %v\n", stringAddrs, someTypeStringFuncAddr, otherTypeStringFuncAddr) } - _, err := c.CreateBreakpoint(&api.Breakpoint{FunctionName: "main.main", Line: 4, Tracepoint: false}) + _, err := c.CreateBreakpoint(&api.Breakpoint{FunctionName: "main.main", Line: 3, Tracepoint: false}) if err != nil { t.Fatalf("CreateBreakpoint(): %v\n", err) }