proc: set OnlyAddr on variables created by typecast to pointer (#2142)

If OnlyAddr is not set pretty printing an interface will fail with an
index out of bounds error.
This commit is contained in:
Alessandro Arzilli 2020-08-24 22:37:06 +02:00 committed by GitHub
parent 7dde930033
commit 0fa2ac5a9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

@ -846,6 +846,7 @@ func (scope *EvalScope) evalTypeCast(node *ast.CallExpr) (*Variable, error) {
n, _ := constant.Int64Val(argv.Value)
v.Children = []Variable{*(newVariable("", uintptr(n), ttyp.Type, scope.BinInfo, scope.Mem))}
v.Children[0].OnlyAddr = true
return v, nil
case *godwarf.UintType:
@ -1348,6 +1349,7 @@ func (scope *EvalScope) evalPointerDeref(node *ast.StarExpr) (*Variable, error)
if len(xev.Children) == 1 {
// this branch is here to support pointers constructed with typecasts from ints
xev.Children[0].OnlyAddr = false
return &(xev.Children[0]), nil
}
rv := xev.maybeDereference()

@ -1130,3 +1130,11 @@ func TestPrintOnTracepoint(t *testing.T) {
}
})
}
func TestPrintCastToInterface(t *testing.T) {
withTestTerminal("testvariables2", t, func(term *FakeTerminal) {
term.MustExec("continue")
out := term.MustExec(`p (*"interface {}")(uintptr(&iface2))`)
t.Logf("%q", out)
})
}