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:
parent
7dde930033
commit
0fa2ac5a9c
@ -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)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user