Example #1
0
 public static bool CheckForCollection(DebugType type)
 {
     string name = type.FullName;
     int ind = name.IndexOf('<');
     if (ind != -1) name = name.Substring(0, ind);
     return ht[name] != null;
 }
Example #2
0
		internal PropertyInfo(DebugType declaringType,string name, MethodInfo getMethod, MethodInfo setMethod): base(declaringType)
		{
			if (getMethod == null && setMethod == null) throw new ArgumentNullException("Both getter and setter can not be null.");
			this.name = name;
			this.getMethod = getMethod;
			this.setMethod = setMethod;
		}
Example #3
0
        public ValueItem(NamedValue val, DebugType declaringType)
        {
            this.val = val;
			this.declaringType = declaringType;
			
			try
            {
				//this.primitive = val.IsPrimitive;
            }
			catch(System.Exception e)
            {
                if (val.Type.IsByRef()) this.primitive = false;
            }
            val.Changed += delegate { OnChanged(new ListItemEventArgs(this)); };
        }
Example #4
0
 public ValueItem(Value val, string name, DebugType declaringType)
 {
 	this.val = val;
 	this.declaringType = declaringType;
 	this.name = name;
 	val.Changed += delegate { OnChanged(new ListItemEventArgs(this)); };
 }
Example #5
0
        public BaseTypeItem(DebugType type, Type mt)
        {
        	this.type = type;
        	this.managed_type = mt;
//        	if (mt.IsValueType)
//        		this.imageIndex = CodeCompletionProvider.ImagesProvider.IconNumberStruct;
//        	else
        		this.imageIndex = CodeCompletionProvider.ImagesProvider.IconNumberClass;
        }
Example #6
0
		IEnumerable<NamedValue> GetObjectMembersEnum(DebugType type, BindingFlags bindingFlags)
		{
			DebugType currentType = type ?? this.Type;
			while (currentType != null) {
				foreach(FieldInfo field in currentType.GetFields(bindingFlags)) {
					yield return field.GetValue(this);
				}
				foreach(PropertyInfo property in currentType.GetProperties(bindingFlags)) {
					yield return property.GetValue(this);
				}
				if (type == null) {
					currentType = currentType.BaseType;
				} else {
					yield break;
				}
			}
		}
        public override void visit(dot_node _dot_node)
        {
            bool tmp2 = by_dot;
            by_dot = true;
            _dot_node.left.visit(this);
            by_dot = tmp2;
            RetValue rv = eval_stack.Pop();
            RetValue res = new RetValue();
            if (rv.obj_val != null)
            {
                if (rv.obj_val.Dereference != null)
                    rv.obj_val = rv.obj_val.Dereference;
                if (_dot_node.right is ident)
                {
                    if (rv.obj_val.IsNull)
                        throw new CommonEvaluationError(new NullReferenceException());
                    ident id = _dot_node.right as ident;
                    names.Add("." + id.name);
                    //IList<Debugger.MemberInfo> members = rv.obj_val.Type.GetMember(id.name, BindingFlags.All);
                    if (rv.obj_val.IsArray)
                    {
                        if (string.Compare(id.name, "Length", true) == 0)
                            res.prim_val = rv.obj_val.ArrayLenght;
                        else
                            if (string.Compare(id.name, "Rank", true) == 0)
                                res.prim_val = rv.obj_val.ArrayRank;
                    }
                    else
                    {
                        res.obj_val = rv.obj_val.GetMember(id.name);
                        if (res.obj_val == null)
                            throw new UnknownName(id.name);
                        if (res.obj_val is MemberValue && (res.obj_val as MemberValue).MemberInfo is PropertyInfo)
                            last_obj = rv.obj_val;
                    }
                    declaringType = rv.obj_val.Type;
                }
            }
            else if (_dot_node.right is ident)
            {
                ident id = _dot_node.right as ident;
                names.Add("." + id.name);
                string name = build_name(_dot_node.left);
                if (name != null)
                {
                    Type t = AssemblyHelper.GetType(name);
                    if (t != null)
                    {
                        //DebugType dt = DebugType.Create(this.debuggedProcess.GetModule(name),(uint)t.MetadataToken);
                        DebugType dt = DebugUtils.GetDebugType(t);
                        IList<MemberInfo> mis = new List<MemberInfo>();//dt.GetMember(id.name,BindingFlags.All);
                        declaringType = dt;
                        DebugType tmp = dt;
                        while (tmp != null && mis.Count == 0)
                        {
                            try
                            {
                                mis = tmp.GetMember(id.name, BindingFlags.All);
                                tmp = tmp.BaseType;
                            }
                            catch
                            {

                            }
                        }
                        if (mis.Count > 0)
                        {
                            if (mis[0] is FieldInfo)
                            {
                                FieldInfo fi = mis[0] as FieldInfo;
                                res.obj_val = fi.GetValue(null);
                                if (res.obj_val == null)
                                    throw new UnknownName(id.name);
                                check_for_static(res.obj_val, id.name);
                            }
                            else if (mis[0] is PropertyInfo)
                            {
                                PropertyInfo pi = mis[0] as PropertyInfo;
                                res.obj_val = pi.GetValue(null);
                                if (res.obj_val == null)
                                    throw new UnknownName(id.name);
                                check_for_static(res.obj_val, id.name);
                            }
                        }
                        else
                        {
                            System.Reflection.FieldInfo fi = t.GetField(id.name);
                            if (fi != null)
                                res.prim_val = fi.GetRawConstantValue();
                            else
                                throw new UnknownName(id.name);
                        }
                    }
                    else
                    {
                        t = AssemblyHelper.GetType(name + "." + id.name);
                        if (t != null)
                        {
                            res.type = DebugUtils.GetDebugType(t);//DebugType.Create(this.debuggedProcess.GetModule(name),(uint)t.MetadataToken);
                            res.managed_type = t;
                        }
                        //						else 
                        //							throw new UnknownName(id.name);
                    }
                }
            }
            eval_stack.Push(res);
        }
 public RetValue GetValueForExpression(string expr, out string preformat)
 {
     declaringType = null;
     for_immediate = false;
     ret_val = default(RetValue);
     preformat = expr.Trim(' ', '\n', '\r', '\t');
     names.Clear();
     string fileName = "test" + System.IO.Path.GetExtension(this.FileName);
     List<PascalABCCompiler.Errors.Error> Errors = new List<PascalABCCompiler.Errors.Error>();
     expression e = vec.StandartCompiler.ParsersController.GetExpression(fileName, expr, Errors);
     RetValue res = new RetValue(); res.syn_err = false;
     try
     {
         if (e != null && Errors.Count == 0)
         {
             e.visit(this);
             if (eval_stack.Count > 0)
             {
                 res = eval_stack.Pop();
                 preformat = string.Join("", names.ToArray());
                 return res;
             }
         }
     }
     catch (System.Exception ex)
     {
         //throw new System.Exception(ex.Message);
     }
     finally
     {
         if (eval_stack.Count > 0) eval_stack.Clear();
     }
     return new RetValue();
 }
Example #9
0
		/// <summary> Determines whether the current type is sublass of 
		/// the the given type. That is, it derives from the given type. </summary>
		/// <remarks> Returns false if the given type is same as the current type </remarks>
		public bool IsSubclassOf(DebugType superType)
		{
			DebugType type = this;
			while (type != null) {
				if (type.Equals(superType)) return true;
				if (superType.IsInterface) {
					// Does this 'type' implement the interface?
					foreach(DebugType inter in type.Interfaces) {
						if (inter == superType) return true;
					}
				}
				type = type.BaseType;
			}
			return false;
		}
Example #10
0
 public static string WrapTypeName(DebugType type)
 {
     if (type.IsArray)
         if (WorkbenchServiceFactory.DebuggerManager.parser != null)
             return WorkbenchServiceFactory.DebuggerManager.parser.LanguageInformation.GetArrayDescription(WrapTypeName(type.GetElementType()), type.GetArrayRank());
         else
             return "array of " + WrapTypeName(type.GetElementType());
     return internalWrapTypeName(type.FullName);
 }
Example #11
0
 public static bool IsSortedList(DebugType type)
 {
     return type.FullName == "System.Collections.SortedList" || type.FullName.StartsWith("System.Collections.Generic.SortedList");
 }
 internal FieldInfo(DebugType declaringType, FieldProps fieldProps) : base(declaringType)
 {
     this.fieldProps = fieldProps;
 }
Example #13
0
		internal MemberInfo(DebugType declaringType)
		{
			this.declaringType = declaringType;
		}
Example #14
0
        static Value GetLiteralValue(DebugFieldInfo fieldInfo)
        {
            CorElementType corElemType = (CorElementType)fieldInfo.FieldProps.ConstantType;

            if (corElemType == CorElementType.CLASS)
            {
                // Only null literals are allowed
                return(Eval.CreateValue(fieldInfo.AppDomain, null));
            }
            else if (corElemType == CorElementType.STRING)
            {
                string str = Marshal.PtrToStringUni(fieldInfo.FieldProps.ConstantPtr, (int)fieldInfo.FieldProps.ConstantStringLength);
                return(Eval.CreateValue(fieldInfo.AppDomain, str));
            }
            else
            {
                DebugType type = DebugType.CreateFromType(fieldInfo.AppDomain.Mscorlib, DebugType.CorElementTypeToManagedType(corElemType));
                if (fieldInfo.FieldType.IsEnum && fieldInfo.FieldType.GetEnumUnderlyingType() == type)
                {
                    Value val          = Eval.NewObjectNoConstructor((DebugType)fieldInfo.FieldType);
                    Value backingField = val.GetMemberValue("value__");
                    backingField.CorGenericValue.SetValue(fieldInfo.FieldProps.ConstantPtr);
                    return(val);
                }
                else
                {
                    Value val = Eval.NewObjectNoConstructor(type);
                    val.CorGenericValue.SetValue(fieldInfo.FieldProps.ConstantPtr);
                    return(val);
                }
            }
        }
Example #15
0
 public static MethodInfo GetMethod(DebugType t, string name)
 {
     return t.GetMember(name, Debugger.BindingFlags.All)[0] as MethodInfo;
 }
Example #16
0
 public static List<DebugType> GetUsesTypes(Process p, DebugType dt)
 {
 	if (unit_debug_types == null)
 	{
 		unit_debug_types = new List<DebugType>();
 		foreach (Type t in unit_types)
 			unit_debug_types.Add(DebugType.Create(p.GetModule(t.Assembly.ManifestModule.ScopeName),(uint)t.MetadataToken));
 	}
 	return unit_debug_types;
 }
Example #17
0
 public static PropertyInfo GetProperty(DebugType t, string name)
 {
     return t.GetMember(name, Debugger.BindingFlags.All)[0] as PropertyInfo;
 }
Example #18
0
		/*static Eval CreateEval(Process process, string description, EvalStarter evalStarter)
		{
			ICorDebugEval corEval = CreateCorEval(process);
			
			Eval newEval = new Eval(process, description, corEval);
			
			try {
				evalStarter(newEval);
			} catch (COMException e) {
				if ((uint)e.ErrorCode == 0x80131C26) {
					throw new GetValueException("Can not evaluate in optimized code");
				} else if ((uint)e.ErrorCode == 0x80131C28) {
					throw new GetValueException("Object is in wrong AppDomain");
				} else if ((uint)e.ErrorCode == 0x8013130A) {
					// Happens on getting of Sytem.Threading.Thread.ManagedThreadId; See SD2-1116
					throw new GetValueException("Function does not have IL code");
				} else if ((uint)e.ErrorCode == 0x80131C23) {
					// The operation failed because it is a GC unsafe point. (Exception from HRESULT: 0x80131C23)
					// This can probably happen when we break and the thread is in native code
					throw new GetValueException("Thread is in GC unsafe point");
				} else {
					throw;
				}
			}
			
			process.NotifyEvaluationStarted(newEval);
			process.AsyncContinue(DebuggeeStateAction.Keep);
			
			return newEval;
		}*/
		
		public static Eval AsyncNewObjectNoConstructor(DebugType debugType)
		{
			return new Eval(
				debugType.Process,
				"New object: " + debugType.FullName,
				delegate(ICorDebugEval corEval) {
					corEval.CastTo<ICorDebugEval2>().NewParameterizedObjectNoConstructor(debugType.CorType.Class, (uint)debugType.GenericArguments.Count, debugType.GenericArgumentsAsCorDebugType);
				}
			);
		}
Example #19
0
 public static bool IsQueue(DebugType type)
 {
     return type.FullName == "System.Collections.Queue" || type.FullName.StartsWith("System.Collections.Generic.Queue");
 }
 private string get_type_name(DebugType t)
 {
     string name = t.FullName;
     int ind = name.IndexOf('<');
     if (ind != -1)
     {
         name = name.Substring(0, ind);
         name += "`" + t.GetGenericArguments().Length.ToString();
     }
     return name;
 }
Example #21
0
 public static bool IsHashtable(DebugType type)
 {
     return type.FullName == "System.Collections.Hashtable";
 }
 private MethodInfo select_method(MethodInfo[] meths, DebugType[] args)
 {
     if (meths.Length > 0)
         return meths[0];
     return null;
 }
Example #23
0
 public static bool IsLinkedList(DebugType type)
 {
     return type.FullName.StartsWith("System.Collections.Generic.LinkedList");
 }
Example #24
0
		/// <summary>
		/// Get fields and properties of an object which are defined by a given type.
		/// </summary>
		/// <param name="type"> Limit to type, null for all types </param>
		/// <param name="bindingFlags"> Get only members with certain flags </param>
		public NamedValueCollection GetMembers(DebugType type, BindingFlags bindingFlags)
		{
			if (IsObject) {
				return new NamedValueCollection(GetObjectMembersEnum(type, bindingFlags));
			} else {
				return NamedValueCollection.Empty;
			}
		}
Example #25
0
 public static bool IsDictionary(DebugType type)
 {
     return type.FullName.StartsWith("System.Collections.Generic.Dictionary");
 }
Example #26
0
 public BaseTypeItem(Value val, DebugType type)
 {
     this.val = val;
     this.type = type;
 }
Example #27
0
 internal MethodInfo(DebugType declaringType, MethodProps methodProps) : base(declaringType)
 {
     this.methodProps = methodProps;
 }
Example #28
0
 public ValueItem(Value val, string name, DebugType declaringType, bool is_in_collect)
 {
 	this.val = val;
 	this.declaringType = declaringType;
 	this.name = name;
 	if (is_in_collect)
 		this.imageIndex = 1;
 	val.Changed += delegate { OnChanged(new ListItemEventArgs(this)); };
 }
Example #29
0
 public static Value NewObjectNoConstructor(DebugType debugType)
 {
     return(AsyncNewObjectNoConstructor(debugType).EvaluateNow());
 }
Example #30
0
 public ArrayValueItem(NamedValue val, DebugType type, Value arr, Value sz_arr, int ind):base(val,type)
 {
     this.arr = arr;
     this.ind = ind;
     System.Reflection.FieldInfo tmp_fi = AssemblyHelper.GetType(arr.Type.FullName).GetField("LowerIndex");
     if (!tmp_fi.FieldType.IsEnum)
         low_bound = tmp_fi.GetRawConstantValue();
     else
         low_bound = tmp_fi.GetValue(sz_arr);
 }
Example #31
0
        /// <exception cref="GetValueException"><c>GetValueException</c>.</exception>
        static void MethodInvokeStarter(Eval eval, DebugMethodInfo method, Value thisValue, Value[] args)
        {
            List <ICorDebugValue> corArgs = new List <ICorDebugValue>();

            args = args ?? new Value[0];
            if (args.Length != method.ParameterCount)
            {
                throw new GetValueException("Invalid parameter count");
            }
            if (!method.IsStatic)
            {
                if (thisValue == null)
                {
                    throw new GetValueException("'this' is null");
                }
                if (thisValue.IsNull)
                {
                    throw new GetValueException("Null reference");
                }
                // if (!(thisValue.IsObject)) // eg Can evaluate on array
                if (!method.DeclaringType.IsInstanceOfType(thisValue))
                {
                    throw new GetValueException(
                              "Can not evaluate because the object is not of proper type.  " +
                              "Expected: " + method.DeclaringType.FullName + "  Seen: " + thisValue.Type.FullName
                              );
                }
                corArgs.Add(thisValue.CorValue);
            }
            for (int i = 0; i < args.Length; i++)
            {
                Value     arg       = args[i];
                DebugType paramType = (DebugType)method.GetParameters()[i].ParameterType;
                if (!arg.Type.CanImplicitelyConvertTo(paramType))
                {
                    throw new GetValueException("Inncorrect parameter type");
                }
                // Implicitely convert to correct primitve type
                if (paramType.IsPrimitive && args[i].Type != paramType)
                {
                    object oldPrimVal = arg.PrimitiveValue;
                    object newPrimVal = Convert.ChangeType(oldPrimVal, paramType.PrimitiveType);
                    arg = CreateValue(method.AppDomain, newPrimVal);
                }
                // It is importatnt to pass the parameted in the correct form (boxed/unboxed)
                if (paramType.IsValueType)
                {
                    corArgs.Add(arg.CorGenericValue);
                }
                else
                {
                    if (args[i].Type.IsValueType)
                    {
                        corArgs.Add(arg.Box().CorValue);
                    }
                    else
                    {
                        corArgs.Add(arg.CorValue);
                    }
                }
            }

            ICorDebugType[] genericArgs = ((DebugType)method.DeclaringType).GenericArgumentsAsCorDebugType;
            eval.CorEval2.CallParameterizedFunction(
                method.CorFunction,
                (uint)genericArgs.Length, genericArgs,
                (uint)corArgs.Count, corArgs.ToArray()
                );
        }
Example #32
0
		internal FieldInfo(DebugType declaringType, FieldProps fieldProps):base (declaringType)
		{
			this.fieldProps = fieldProps;
		}
Example #33
0
 public static Value NewArray(DebugType type, uint length, uint?lowerBound)
 {
     return(AsyncNewArray(type, length, lowerBound).WaitForResult());
 }
Example #34
0
		/// <summary> Obtains instance of DebugType. Same types will return identical instance. </summary>
		static internal DebugType Create(Process process, ICorDebugType corType)
		{
			DateTime startTime = Util.HighPrecisionTimer.Now;
			
			DebugType type = new DebugType(process, corType);
			
			// Get types with matching names from cache
			List<DebugType> typesWithMatchingName;
			if (!loadedTypes.TryGetValue(type.FullName, out typesWithMatchingName)) {
				// No types with such name - create a new list
				typesWithMatchingName = new List<DebugType>(1);
				loadedTypes.Add(type.FullName, typesWithMatchingName);
			}
			
			// Try to find the type
			foreach(DebugType loadedType in typesWithMatchingName) {
				if (loadedType.Equals(type)) {
					TimeSpan totalTime = Util.HighPrecisionTimer.Now - startTime;
					//process.TraceMessage("Type " + type.FullName + " was loaded already (" + totalTime.TotalMilliseconds + " ms)");
					return loadedType; // Type was loaded before
				}
			}
			
			// The type is not in the cache, finish loading it and add it to the cache
			if (type.IsClass || type.IsValueType || type.ManagedType == typeof(string)) {
				type.LoadMemberInfo();
			}
			typesWithMatchingName.Add(type);
			type.Process.Expired += delegate { typesWithMatchingName.Remove(type); };
			
			TimeSpan totalTime2 = Util.HighPrecisionTimer.Now - startTime;
			process.TraceMessage("Loaded type " + type.FullName + " (" + totalTime2.TotalMilliseconds + " ms)");
			
			return type;
		}
Example #35
0
 public static Value NewObjectNoConstructor(DebugType debugType)
 {
     return(AsyncNewObjectNoConstructor(debugType).WaitForResult());
 }
Example #36
0
		internal MethodInfo(DebugType declaringType, MethodProps methodProps):base (declaringType)
		{
			this.methodProps = methodProps;
		}
Example #37
0
		public static Value NewObjectNoConstructor(DebugType debugType)
		{
			return AsyncNewObjectNoConstructor(debugType).EvaluateNow();
		}