mirror of
				https://github.com/go-delve/delve.git
				synced 2025-10-30 18:27:37 +08:00 
			
		
		
		
	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:
		| @ -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 | ||||
|  | ||||
| @ -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": | ||||
|  | ||||
| @ -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<string,int>")}, | ||||
|  | ||||
| 		// typecasts | ||||
| 		{"uint(i2)", false, "2", "", "uint", nil}, | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 aarzilli
					aarzilli