debugger/locations: prioritize exact matches of function names (#651)
If the location specification matches the name of a function exactly return that function as a match event if the expression matches other functions as well. Without this some functions, like math/rand.Intn are unmatchable.
This commit is contained in:
parent
f6e8fb37a4
commit
6e882c50fa
12
_fixtures/locationsprog3.go
Normal file
12
_fixtures/locationsprog3.go
Normal file
@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func main() {
|
||||
runtime.Breakpoint()
|
||||
fmt.Println(rand.Intn(10))
|
||||
}
|
@ -346,10 +346,14 @@ func (loc *NormalLocationSpec) Find(d *Debugger, scope *proc.EvalScope, locStr s
|
||||
continue
|
||||
}
|
||||
if loc.FuncBase.Match(f.Sym) {
|
||||
candidates = append(candidates, f.Name)
|
||||
if len(candidates) >= maxFindLocationCandidates {
|
||||
if loc.Base == f.Name {
|
||||
// if an exact match for the function name is found use it
|
||||
candidates = []string{f.Name}
|
||||
break
|
||||
}
|
||||
if len(candidates) < maxFindLocationCandidates {
|
||||
candidates = append(candidates, f.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -666,6 +666,18 @@ func TestClientServer_FindLocationsAddr(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestClientServer_FindLocationsExactMatch(t *testing.T) {
|
||||
// if an expression matches multiple functions but one of them is an exact
|
||||
// match it should be used anyway.
|
||||
// In this example "math/rand.Intn" would normally match "math/rand.Intn"
|
||||
// and "math/rand.(*Rand).Intn" but since the first match is exact it
|
||||
// should be prioritized.
|
||||
withTestClient2("locationsprog3", t, func(c service.Client) {
|
||||
<-c.Continue()
|
||||
findLocationHelper(t, c, "math/rand.Intn", false, 1, 0)
|
||||
})
|
||||
}
|
||||
|
||||
func TestClientServer_EvalVariable(t *testing.T) {
|
||||
withTestClient2("testvariables", t, func(c service.Client) {
|
||||
state := <-c.Continue()
|
||||
|
Loading…
Reference in New Issue
Block a user