* proc/eval: fix length calculation for string concatenation * proc/variable: find package variables when the package has a path
This commit is contained in:
parent
3a86b9fab4
commit
d9bd90d7e4
@ -51,5 +51,5 @@ func main() {
|
||||
m := t.Method(0)
|
||||
fmt.Println(m.Type.In(0))
|
||||
fmt.Println(m.Type.String())
|
||||
fmt.Println(badexpr, req, amap, amap2, dir0someType, dir1someType, amap3, anarray, achan, aslice, afunc, astruct, astruct2, iface2iface, iface3)
|
||||
fmt.Println(badexpr, req, amap, amap2, dir0someType, dir1someType, amap3, anarray, achan, aslice, afunc, astruct, astruct2, iface2iface, iface3, pkg.SomeVar)
|
||||
}
|
||||
|
||||
2
_fixtures/vendor/dir0/pkg/main.go
vendored
2
_fixtures/vendor/dir0/pkg/main.go
vendored
@ -11,3 +11,5 @@ func (s *SomeType) AMethod(x int) int {
|
||||
func (s *SomeType) AnotherMethod(x int) int {
|
||||
return x + 4
|
||||
}
|
||||
|
||||
var SomeVar SomeType
|
||||
|
||||
@ -850,6 +850,9 @@ func (scope *EvalScope) evalBinary(node *ast.BinaryExpr) (*Variable, error) {
|
||||
|
||||
r := xv.newVariable("", 0, typ)
|
||||
r.Value = rc
|
||||
if r.Kind == reflect.String {
|
||||
r.Len = xv.Len+yv.Len
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -2705,3 +2705,28 @@ func TestAttachDetach(t *testing.T) {
|
||||
|
||||
cmd.Process.Kill()
|
||||
}
|
||||
|
||||
func TestVarSum(t *testing.T) {
|
||||
withTestProcess("testvariables2", t, func(p proc.Process, fixture protest.Fixture) {
|
||||
assertNoError(proc.Continue(p), t, "Continue()")
|
||||
sumvar, err := evalVariable(p, "s1[0] + s1[1]")
|
||||
assertNoError(err, t, "EvalVariable")
|
||||
sumvarstr := constant.StringVal(sumvar.Value)
|
||||
if sumvarstr != "onetwo" {
|
||||
t.Fatalf("s1[0] + s1[1] == %q (expected \"onetwo\")", sumvarstr)
|
||||
}
|
||||
if sumvar.Len != int64(len(sumvarstr)) {
|
||||
t.Fatalf("sumvar.Len == %d (expected %d)", sumvar.Len, len(sumvarstr))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestPackageWithPathVar(t *testing.T) {
|
||||
withTestProcess("pkgrenames", t, func(p proc.Process, fixture protest.Fixture) {
|
||||
assertNoError(proc.Continue(p), t, "Continue()")
|
||||
_, err := evalVariable(p, "pkg.SomeVar")
|
||||
assertNoError(err, t, "EvalVariable(pkg.SomeVar)")
|
||||
_, err = evalVariable(p, "pkg.SomeVar.X")
|
||||
assertNoError(err, t, "EvalVariable(pkg.SomeVar.X)")
|
||||
})
|
||||
}
|
||||
|
||||
@ -657,7 +657,7 @@ func (scope *EvalScope) packageVarAddr(name string) (*Variable, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
if n == name {
|
||||
if n == name || strings.HasSuffix(n, "/"+name) {
|
||||
return scope.extractVarInfoFromEntry(entry, reader)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user