diff --git a/proc/eval.go b/proc/eval.go index 7f474dc5..7bc4e6f2 100644 --- a/proc/eval.go +++ b/proc/eval.go @@ -139,6 +139,9 @@ func (scope *EvalScope) evalTypeCast(node *ast.CallExpr) (*Variable, error) { switch ttyp := typ.(type) { case *dwarf.PtrType: + if ptrTypeKind(ttyp) != reflect.Ptr { + return nil, converr + } switch argv.Kind { case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: // ok diff --git a/proc/variables.go b/proc/variables.go index 084d7adf..677c3ab0 100644 --- a/proc/variables.go +++ b/proc/variables.go @@ -119,6 +119,20 @@ func (err *IsNilErr) Error() string { return fmt.Sprintf("%s is nil", err.name) } +func ptrTypeKind(t *dwarf.PtrType) reflect.Kind { + structtyp, isstruct := t.Type.(*dwarf.StructType) + _, isvoid := t.Type.(*dwarf.VoidType) + if isstruct && strings.HasPrefix(structtyp.StructName, "hchan<") { + return reflect.Chan + } else if isstruct && strings.HasPrefix(structtyp.StructName, "hash<") { + return reflect.Map + } else if isvoid { + return reflect.UnsafePointer + } else { + return reflect.Ptr + } +} + func newVariable(name string, addr uintptr, dwarfType dwarf.Type, thread *Thread) *Variable { v := &Variable{ Name: name, @@ -131,17 +145,7 @@ func newVariable(name string, addr uintptr, dwarfType dwarf.Type, thread *Thread switch t := v.RealType.(type) { case *dwarf.PtrType: - structtyp, isstruct := t.Type.(*dwarf.StructType) - _, isvoid := t.Type.(*dwarf.VoidType) - if isstruct && strings.HasPrefix(structtyp.StructName, "hchan<") { - v.Kind = reflect.Chan - } else if isstruct && strings.HasPrefix(structtyp.StructName, "hash<") { - v.Kind = reflect.Map - } else if isvoid { - v.Kind = reflect.UnsafePointer - } else { - v.Kind = reflect.Ptr - } + v.Kind = ptrTypeKind(t) case *dwarf.StructType: switch { case t.StructName == "string": diff --git a/service/test/variables_test.go b/service/test/variables_test.go index 58b8ace6..4dbb4cbd 100644 --- a/service/test/variables_test.go +++ b/service/test/variables_test.go @@ -533,6 +533,7 @@ func TestEvalExpression(t *testing.T) { {"nil[0]", false, "", "", "", fmt.Errorf("expression \"nil\" (nil) does not support indexing")}, {"nil[2:10]", false, "", "", "", fmt.Errorf("can not slice \"nil\" (type nil)")}, {"nil.member", false, "", "", "", fmt.Errorf("type nil is not a struct")}, + {"(map[string]int)(0x4000)", false, "", "", "", fmt.Errorf("can not convert \"0x4000\" to *struct hash")}, // typecasts {"uint(i2)", false, "2", "", "uint", nil},