DebugType(Process process, ICorDebugType corType) { if (corType == null) { throw new ArgumentNullException("corType"); } this.process = process; this.corType = corType; this.corElementType = (CorElementType)corType.Type; if (this.IsClass || this.IsValueType) { this.corClass = corType.Class; this.module = process.GetModule(corClass.Module); this.classProps = module.MetaData.GetTypeDefProps(corClass.Token); } if (this.IsClass || this.IsValueType || this.IsArray || this.IsPointer) { foreach (ICorDebugType t in corType.EnumerateTypeParameters().Enumerator) { typeArguments.Add(DebugType.Create(process, t)); } } this.fullName = GetFullName(); }
static public DebugType Create(Process process, ICorDebugClass corClass, params ICorDebugType[] typeArguments) { MetaData metaData = process.GetModule(corClass.Module).MetaData; bool isValueType = false; uint superClassToken = metaData.GetTypeDefProps(corClass.Token).SuperClassToken; if ((superClassToken & 0xFF000000) == 0x02000000) // TypeDef { if (metaData.GetTypeDefProps(superClassToken).Name == "System.ValueType") { isValueType = true; } } if ((superClassToken & 0xFF000000) == 0x01000000) // TypeRef { if (metaData.GetTypeRefProps(superClassToken).Name == "System.ValueType") { isValueType = true; } } int getArgsCount = metaData.GetGenericParamCount(corClass.Token); Array.Resize(ref typeArguments, getArgsCount); ICorDebugType corType = corClass.CastTo <ICorDebugClass2>().GetParameterizedType( isValueType ? (uint)CorElementType.VALUETYPE : (uint)CorElementType.CLASS, typeArguments ); return(Create(process, corType)); }
internal LocalVariable(string name, Process process, IExpirable[] expireDependencies, IMutable[] mutateDependencies, CorValueGetter corValueGetter) : base(name, process, expireDependencies, mutateDependencies, corValueGetter) { }
internal ArrayElement(uint[] indicies, Process process, IExpirable[] expireDependencies, IMutable[] mutateDependencies, CorValueGetter corValueGetter) : base(GetNameFromIndices(indicies), process, expireDependencies, mutateDependencies, corValueGetter) { this.indicies = indicies; }
internal MemberValue(MemberInfo memberInfo, Process process, IExpirable[] expireDependencies, IMutable[] mutateDependencies, CorValueGetter corValueGetter) : base(memberInfo.Name, process, expireDependencies, mutateDependencies, corValueGetter) { this.memberInfo = memberInfo; }
internal MethodArgument(string name, int index, Process process, IExpirable[] expireDependencies, IMutable[] mutateDependencies, CorValueGetter corValueGetter) : base(name, process, expireDependencies, mutateDependencies, corValueGetter) { this.index = index; }
public static DebugType Create(Process process, uint?domainID, string fullTypeName) { foreach (Module module in process.Modules) { if (!domainID.HasValue || domainID == module.CorModule.Assembly.AppDomain.ID) { try { uint token = module.MetaData.FindTypeDefPropsByName(fullTypeName, 0 /* enclosing class for nested */).Token; return(Create(process, module.CorModule.GetClassFromToken(token))); } catch { continue; } } } throw new DebuggerException("Can not find type " + fullTypeName); }
/// <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); }
/// <summary> /// Get a method from a managed type, method name and argument count /// </summary> public static MethodInfo GetFromName(Process process, System.Type type, string name, int paramCount) { if (type.IsNested) { throw new DebuggerException("Not implemented for nested types"); } if (type.IsGenericType) { throw new DebuggerException("Not implemented for generic types"); } if (type.IsGenericParameter) { throw new DebuggerException("Type can not be generic parameter"); } foreach (Module module in process.Modules) { TypeDefProps typeDefProps; try { typeDefProps = module.MetaData.FindTypeDefByName(type.FullName, 0 /* enclosing class for nested */); } catch { continue; } foreach (MethodProps methodProps in module.MetaData.EnumMethodsWithName(typeDefProps.Token, name)) { if (module.MetaData.GetParamCount(methodProps.Token) == paramCount) { ICorDebugFunction corFunction = module.CorModule.GetFunctionFromToken(methodProps.Token); ICorDebugClass2 corClass = corFunction.Class.As <ICorDebugClass2>(); ICorDebugType corType = corClass.GetParameterizedType(type.IsValueType ? (uint)CorElementType.VALUETYPE : (uint)CorElementType.CLASS, 0, new ICorDebugType[] {}); return(new MethodInfo(DebugType.Create(process, corType), methodProps)); } } } throw new DebuggerException("Not found"); }
internal NamedValue(string name, Process process, IExpirable[] expireDependencies, IMutable[] mutateDependencies, CorValueGetter corValueGetter) : base(process, expireDependencies, mutateDependencies, corValueGetter) { this.name = name; // TODO: clean up if (name.StartsWith("<") && name.Contains(">") && name != "<Base class>") { string middle = name.TrimStart('<').Split('>')[0]; // Get text between '<' and '>' if (middle != "") { this.name = middle; } } }