proc/variables: bugfix: disable cast to maps and channels

It's was implemented unintentionally and the unintentional
implementation doesn't work and causes a crash.
This commit is contained in:
aarzilli
2015-11-25 14:20:07 +01:00
committed by Derek Parker
parent 141fc4ed21
commit 8346a6ee08
3 changed files with 19 additions and 11 deletions

View File

@ -139,6 +139,9 @@ func (scope *EvalScope) evalTypeCast(node *ast.CallExpr) (*Variable, error) {
switch ttyp := typ.(type) { switch ttyp := typ.(type) {
case *dwarf.PtrType: case *dwarf.PtrType:
if ptrTypeKind(ttyp) != reflect.Ptr {
return nil, converr
}
switch argv.Kind { switch argv.Kind {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
// ok // ok

View File

@ -119,6 +119,20 @@ func (err *IsNilErr) Error() string {
return fmt.Sprintf("%s is nil", err.name) 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 { func newVariable(name string, addr uintptr, dwarfType dwarf.Type, thread *Thread) *Variable {
v := &Variable{ v := &Variable{
Name: name, Name: name,
@ -131,17 +145,7 @@ func newVariable(name string, addr uintptr, dwarfType dwarf.Type, thread *Thread
switch t := v.RealType.(type) { switch t := v.RealType.(type) {
case *dwarf.PtrType: case *dwarf.PtrType:
structtyp, isstruct := t.Type.(*dwarf.StructType) v.Kind = ptrTypeKind(t)
_, 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
}
case *dwarf.StructType: case *dwarf.StructType:
switch { switch {
case t.StructName == "string": case t.StructName == "string":

View File

@ -533,6 +533,7 @@ func TestEvalExpression(t *testing.T) {
{"nil[0]", false, "", "", "", fmt.Errorf("expression \"nil\" (nil) does not support indexing")}, {"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[2:10]", false, "", "", "", fmt.Errorf("can not slice \"nil\" (type nil)")},
{"nil.member", false, "", "", "", fmt.Errorf("type nil is not a struct")}, {"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<string,int>")},
// typecasts // typecasts
{"uint(i2)", false, "2", "", "uint", nil}, {"uint(i2)", false, "2", "", "uint", nil},