public static DebugType ResolveType(this INode expr, Debugger.AppDomain appDomain)
        {
            if (expr is TypeReference && expr.GetStaticType() != null)
            {
                return(expr.GetStaticType());
            }
            if (expr is TypeReferenceExpression && ((TypeReferenceExpression)expr).TypeReference.GetStaticType() != null)
            {
                return(((TypeReferenceExpression)expr).TypeReference.GetStaticType());
            }

            appDomain.Process.TraceMessage("Resolving {0}", expr.PrettyPrint());

            TypeReference typeRef = NormalizeTypeReference(expr);

            List <TypeReference> genTypeRefs;

            if (typeRef is InnerClassTypeReference)
            {
                genTypeRefs = ((InnerClassTypeReference)typeRef).CombineToNormalTypeReference().GenericTypes;
            }
            else
            {
                genTypeRefs = typeRef.GenericTypes;
            }

            List <DebugType> genArgs = new List <DebugType>();

            foreach (TypeReference genTypeRef in genTypeRefs)
            {
                genArgs.Add(ResolveType(genTypeRef, appDomain));
            }

            return(ResolveTypeInternal(typeRef, genArgs.ToArray(), appDomain));
        }
Esempio n. 2
0
        public static DebugType ResolveType(this AstNode expr, Debugger.AppDomain appDomain)
        {
            var result = expr.GetStaticType();

            if (result != null)
            {
                return(result);
            }

            return(DebugType.CreateFromType(appDomain, expr.Annotation <Type>()));
        }
Esempio n. 3
0
		public static List<TreeNode> GetDebugInfo(AppDomain appDomain, ICorDebugValue corValue)
		{
			List<TreeNode> items = new List<TreeNode>();
			
			if (corValue is ICorDebugValue) {
				InfoNode info = new InfoNode("ICorDebugValue", "");
				info.AddChild("Address", corValue.GetAddress().ToString("X8"));
				info.AddChild("Type", ((CorElementType)corValue.GetTheType()).ToString());
				info.AddChild("Size", corValue.GetSize().ToString());
				items.Add(info);
			}
			if (corValue is ICorDebugValue2) {
				InfoNode info = new InfoNode("ICorDebugValue2", "");
				ICorDebugValue2 corValue2 = (ICorDebugValue2)corValue;
				string fullname;
				try {
					fullname = DebugType.CreateFromCorType(appDomain, corValue2.GetExactType()).FullName;
				} catch (DebuggerException e) {
					fullname = e.Message;
				}
				info.AddChild("ExactType", fullname);
				items.Add(info);
			}
			if (corValue is ICorDebugGenericValue) {
				InfoNode info = new InfoNode("ICorDebugGenericValue", "");
				try {
					byte[] bytes = ((ICorDebugGenericValue)corValue).GetRawValue();
					for(int i = 0; i < bytes.Length; i += 8) {
						string val = "";
						for(int j = i; j < bytes.Length && j < i + 8; j++) {
							val += bytes[j].ToString("X2") + " ";
						}
						info.AddChild("Value" + i.ToString("X2"), val);
					}
				} catch (System.ArgumentException) {
					info.AddChild("Value", "N/A");
				}
				items.Add(info);
			}
			if (corValue is ICorDebugReferenceValue) {
				InfoNode info = new InfoNode("ICorDebugReferenceValue", "");
				ICorDebugReferenceValue refValue = (ICorDebugReferenceValue)corValue;
				info.AddChild("IsNull", (refValue.IsNull() != 0).ToString());
				if (refValue.IsNull() == 0) {
					info.AddChild("Value", refValue.GetValue().ToString("X8"));
					if (refValue.Dereference() != null) {
						info.AddChild("Dereference", "", GetDebugInfo(appDomain, refValue.Dereference()));
					} else {
						info.AddChild("Dereference", "N/A");
					}
				}
				items.Add(info);
			}
			if (corValue is ICorDebugHeapValue) {
				InfoNode info = new InfoNode("ICorDebugHeapValue", "");
				items.Add(info);
			}
			if (corValue is ICorDebugHeapValue2) {
				InfoNode info = new InfoNode("ICorDebugHeapValue2", "");
				items.Add(info);
			}
			if (corValue is ICorDebugObjectValue) {
				InfoNode info = new InfoNode("ICorDebugObjectValue", "");
				ICorDebugObjectValue objValue = (ICorDebugObjectValue)corValue;
				info.AddChild("Class", objValue.GetClass().GetToken().ToString("X8"));
				info.AddChild("IsValueClass", (objValue.IsValueClass() != 0).ToString());
				items.Add(info);
			}
			if (corValue is ICorDebugObjectValue2) {
				InfoNode info = new InfoNode("ICorDebugObjectValue2", "");
				items.Add(info);
			}
			if (corValue is ICorDebugBoxValue) {
				InfoNode info = new InfoNode("ICorDebugBoxValue", "");
				ICorDebugBoxValue boxValue = (ICorDebugBoxValue)corValue;
				info.AddChild("Object", "", GetDebugInfo(appDomain, boxValue.GetObject()));
				items.Add(info);
			}
			if (corValue is ICorDebugStringValue) {
				InfoNode info = new InfoNode("ICorDebugStringValue", "");
				ICorDebugStringValue stringValue = (ICorDebugStringValue)corValue;
				info.AddChild("Length", stringValue.GetLength().ToString());
				info.AddChild("String", stringValue.GetString());
				items.Add(info);
			}
			if (corValue is ICorDebugArrayValue) {
				InfoNode info = new InfoNode("ICorDebugArrayValue", "");
				info.AddChild("...", "...");
				items.Add(info);
			}
			if (corValue is ICorDebugHandleValue) {
				InfoNode info = new InfoNode("ICorDebugHandleValue", "");
				ICorDebugHandleValue handleValue = (ICorDebugHandleValue)corValue;
				info.AddChild("HandleType", handleValue.GetHandleType().ToString());
				items.Add(info);
			}
			
			return items;
		}
Esempio n. 4
0
		public static InfoNode GetDebugInfoRoot(AppDomain appDomain, ICorDebugValue corValue)
		{
			return new InfoNode("ICorDebug", "", GetDebugInfo(appDomain, corValue));
		}
Esempio n. 5
0
        Eval(Thread evalThread, string description, EvalStarter evalStarter)
        {
            if (evalThread == null)
            {
                throw new DebuggerException("No evaluation thread was provided");
            }

            this.appDomain   = evalThread.AppDomain;
            this.process     = appDomain.Process;
            this.description = description;
            this.state       = EvalState.Evaluating;
            this.thread      = evalThread;

            if (evalThread.Suspended)
            {
                throw new GetValueException("Can not evaluate because thread is suspended");
            }
            if (evalThread.IsInNativeCode)
            {
                throw new GetValueException("Can not evaluate because thread is in native code");
            }
            if (!evalThread.IsAtSafePoint)
            {
                throw new GetValueException("Can not evaluate because thread is not at safe point");
            }

            this.corEval = evalThread.CorThread.CreateEval();

            try {
                evalStarter(this);
            } 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 if ((uint)e.ErrorCode == 0x80131C22)
                {
                    // The operation is illegal because of a stack overflow.
                    throw new GetValueException("Can not evaluate after stack overflow");
                }
                else if ((uint)e.ErrorCode == 0x80131313)
                {
                    // Func eval cannot work. Bad starting point.
                    // Reproduction circumstancess are unknown
                    throw new GetValueException("Func eval cannot work. Bad starting point.");
                }
                else
                {
                                        #if DEBUG
                    throw;                     // Expose for more diagnostics
                                        #else
                    throw new GetValueException(e.Message);
                                        #endif
                }
            }

            appDomain.Process.activeEvals.Add(this);

            appDomain.Process.AsyncContinue(DebuggeeStateAction.Keep, evalThread);
        }
        /// <summary>
        /// For performance this is separate method.
        /// 'genArgs' should hold type for each generic parameter in 'typeRef'.
        /// </summary>
        static DebugType ResolveTypeInternal(TypeReference typeRef, DebugType[] genArgs, Debugger.AppDomain appDomain)
        {
            DebugType type = null;

            // Try to construct non-nested type
            // If there are generic types up in the tree, it must be nested type
            if (genArgs.Length == typeRef.GenericTypes.Count)
            {
                string name = GetNameWithArgCounts(typeRef);
                type = DebugType.CreateFromNameOrNull(appDomain, name, null, genArgs);
            }

            // Try to construct nested type
            if (type == null && typeRef is InnerClassTypeReference)
            {
                DebugType[] outterGenArgs = genArgs;
                // Do not pass our generic arguments to outter type
                Array.Resize(ref outterGenArgs, genArgs.Length - typeRef.GenericTypes.Count);

                DebugType outter     = ResolveTypeInternal(((InnerClassTypeReference)typeRef).BaseType, outterGenArgs, appDomain);
                string    nestedName = typeRef.GenericTypes.Count == 0 ? typeRef.Type : typeRef.Type + "`" + typeRef.GenericTypes.Count;
                type = DebugType.CreateFromNameOrNull(appDomain, nestedName, outter, genArgs);
            }

            if (type == null)
            {
                throw new GetValueException("Can not resolve " + typeRef.PrettyPrint());
            }

            for (int i = 0; i < typeRef.PointerNestingLevel; i++)
            {
                type = (DebugType)type.MakePointerType();
            }
            if (typeRef.RankSpecifier != null)
            {
                for (int i = typeRef.RankSpecifier.Length - 1; i >= 0; i--)
                {
                    type = (DebugType)type.MakeArrayType(typeRef.RankSpecifier[i] + 1);
                }
            }
            return(type);
        }