提交 d9bd90d7 编写于 作者: A Alessandro Arzilli 提交者: Derek Parker

Pull Request #731 but with tests (#802)

* proc/eval: fix length calculation for string concatenation

* proc/variable: find package variables when the package has a path
上级 3a86b9fa
......@@ -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)
}
......@@ -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)
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册