public static bool GetSystemNullableFields(this CorType type, out TokenAndName hasValueInfo, out TokenAndName valueInfo, out CorType nullableElemType) { nullableElemType = null; if (!type.GetSystemNullableFields(out hasValueInfo, out valueInfo)) return false; nullableElemType = type.FirstTypeParameter; return nullableElemType != null; }
public CorFieldInfo(CorType ownerType, uint token, string name, TypeSig fieldType, FieldAttributes attrs, object constant, CorElementType constantType, DebuggerBrowsableState? debuggerBrowsableState, bool compilerGeneratedAttribute) { this.OwnerType = ownerType; this.Token = token; this.Name = name; this.FieldType = fieldType; this.Attributes = attrs; this.Constant = constant; this.ConstantType = constantType; this.DebuggerBrowsableState = debuggerBrowsableState; this.CompilerGeneratedAttribute = compilerGeneratedAttribute; }
public DebuggerType(Debugger debugger, CorType type, uint token = 0) { debugger.Dispatcher.VerifyAccess(); this.debugger = debugger; this.type = type; this.hashCode = type.GetHashCode(); this.elementType = (CorElementType)type.ElementType; this.attributes = type.GetTypeAttributes(); this.token = token; this.tokenInitd = token != 0; }
public CorPropertyInfo(CorType ownerType, uint token, uint getToken, uint setToken, string name, MethodSig getSig, MethodSig setSig, MethodAttributes getMethodAttributes, DebuggerBrowsableState? debuggerBrowsableState) { this.OwnerType = ownerType; this.Token = token; this.GetToken = getToken; this.SetToken = setToken; this.Name = name; this.GetSig = getSig; this.SetSig = setSig; this.GetMethodAttributes = getMethodAttributes; this.DebuggerBrowsableState = debuggerBrowsableState; }
bool IsAssignableFrom(CorEvaluationContext ctx, Type baseType, CorType ctype) { string tname = baseType.FullName; string ctypeName = GetTypeName(ctx, ctype); if (tname == "System.Object") { return(true); } if (tname == ctypeName) { return(true); } if (CorMetadataImport.CoreTypes.ContainsKey(ctype.Type)) { return(false); } switch (ctype.Type) { case CorElementType.ELEMENT_TYPE_ARRAY: case CorElementType.ELEMENT_TYPE_SZARRAY: case CorElementType.ELEMENT_TYPE_BYREF: case CorElementType.ELEMENT_TYPE_PTR: return(false); } while (ctype != null) { if (GetTypeName(ctx, ctype) == tname) { return(true); } ctype = ctype.Base; } return(false); }
private bool IsCatchpoint(CorException2EventArgs e) { // Build up the exception type hierachy CorValue v = e.Thread.CurrentException; List <string> exceptions = new List <string>(); CorType t = v.ExactType; while (t != null) { exceptions.Add(t.GetTypeInfo(this).FullName); t = t.Base; } // See if a catchpoint is set for this exception. foreach (Catchpoint cp in Breakpoints.GetCatchpoints()) { if (cp.Enabled && exceptions.Contains(cp.ExceptionName)) { return(true); } } return(false); }
public EvalResult? Call(CorFunction func, CorType[] typeArgs, CorValue[] args, out int hr) { return WaitForResult(hr = eval.CallParameterizedFunction(func, typeArgs, args)); }
string GetEnumValue(CorType type, out byte[] bytes) { bytes = null; Debug.Assert(type != null && type.IsEnum); if (text == string.Empty) { return(dnSpy_Debugger_Resources.LocalsEditValue_Error_EnterSomeText); } var etype = type.EnumUnderlyingType; if (etype == CorElementType.End) { return("Internal error: type is not an enum"); } var consts = text.Split('|').Select(a => a.Trim()).ToArray(); bool isFlagsAttr = type.HasAttribute("System.FlagsAttribute"); var fields = type.GetFields(false).Where(a => a.Constant != null && (a.Attributes & (FieldAttributes.Literal | FieldAttributes.Static)) == (FieldAttributes.Literal | FieldAttributes.Static)); bool isInteger = !(etype == CorElementType.R4 || etype == CorElementType.R8); if (isFlagsAttr && isInteger) { var dict = new Dictionary <string, object>(); foreach (var f in fields) { if (!dict.ContainsKey(f.Name)) { dict[f.Name] = f.Constant; } } ulong value = 0; foreach (var c in consts) { ulong? newv; object o; string error; if (dict.TryGetValue(c, out o)) { newv = IntegerToUInt64ZeroExtend(o); } else { newv = ParseIntegerConstant(etype, c, out error); } if (newv == null) { return(string.Format(dnSpy_Debugger_Resources.LocalsEditValue_Error_UnknownEnumValue, c)); } value |= newv.Value; } bytes = Convert(etype, ConvertUInt64(etype, value)); if (bytes != null) { return(null); } } else { if (consts.Length != 1) { return(dnSpy_Debugger_Resources.LocalsEditValue_Error_InvalidEnumValue); } var c = consts[0]; foreach (var field in fields) { if (field.Name == c) { bytes = Convert(etype, field.Constant); if (bytes != null) { return(null); } } } if (isInteger) { string error; var newv = ParseIntegerConstant(etype, c, out error); if (newv != null) { bytes = Convert(etype, ConvertUInt64(etype, newv.Value)); if (bytes != null) { return(null); } } } else { if (etype == CorElementType.R4) { float v; if (float.TryParse(c, out v)) { bytes = BitConverter.GetBytes(v); return(null); } } else { Debug.Assert(etype == CorElementType.R8); double v; if (double.TryParse(c, out v)) { bytes = BitConverter.GetBytes(v); return(null); } } } } return(dnSpy_Debugger_Resources.LocalsEditValue_Error_InvalidEnumValue); }
string GetEnumValue(CorType type, out byte[] bytes) { bytes = null; Debug.Assert(type != null && type.IsEnum); if (text == string.Empty) return dnSpy_Debugger_Resources.LocalsEditValue_Error_EnterSomeText; var etype = type.EnumUnderlyingType; if (etype == CorElementType.End) return "Internal error: type is not an enum"; var consts = text.Split('|').Select(a => a.Trim()).ToArray(); bool isFlagsAttr = type.HasAttribute("System.FlagsAttribute"); var fields = type.GetFields(false).Where(a => a.Constant != null && (a.Attributes & (FieldAttributes.Literal | FieldAttributes.Static)) == (FieldAttributes.Literal | FieldAttributes.Static)); bool isInteger = !(etype == CorElementType.R4 || etype == CorElementType.R8); if (isFlagsAttr && isInteger) { var dict = new Dictionary<string, object>(); foreach (var f in fields) { if (!dict.ContainsKey(f.Name)) dict[f.Name] = f.Constant; } ulong value = 0; foreach (var c in consts) { ulong? newv; object o; string error; if (dict.TryGetValue(c, out o)) newv = IntegerToUInt64ZeroExtend(o); else newv = ParseIntegerConstant(etype, c, out error); if (newv == null) return string.Format(dnSpy_Debugger_Resources.LocalsEditValue_Error_UnknownEnumValue, c); value |= newv.Value; } bytes = Convert(etype, ConvertUInt64(etype, value)); if (bytes != null) return null; } else { if (consts.Length != 1) return dnSpy_Debugger_Resources.LocalsEditValue_Error_InvalidEnumValue; var c = consts[0]; foreach (var field in fields) { if (field.Name == c) { bytes = Convert(etype, field.Constant); if (bytes != null) return null; } } if (isInteger) { string error; var newv = ParseIntegerConstant(etype, c, out error); if (newv != null) { bytes = Convert(etype, ConvertUInt64(etype, newv.Value)); if (bytes != null) return null; } } else { if (etype == CorElementType.R4) { float v; if (float.TryParse(c, out v)) { bytes = BitConverter.GetBytes(v); return null; } } else { Debug.Assert(etype == CorElementType.R8); double v; if (double.TryParse(c, out v)) { bytes = BitConverter.GetBytes(v); return null; } } } } return dnSpy_Debugger_Resources.LocalsEditValue_Error_InvalidEnumValue; }
public PropertyReference(EvaluationContext ctx, PropertyInfo prop, CorValRef thisobj, CorType declaringType, CorValRef[] index) : base(ctx) { this.prop = prop; this.declaringType = declaringType; if (declaringType.Type == CorElementType.ELEMENT_TYPE_ARRAY || declaringType.Type == CorElementType.ELEMENT_TYPE_SZARRAY) { this.module = ((CorType)((CorEvaluationContext)ctx).Adapter.GetType(ctx, "System.Object")).Class.Module; } else { this.module = declaringType.Class.Module; } this.index = index; if (!prop.GetGetMethod(true).IsStatic) { this.thisobj = thisobj; } flags = GetFlags(prop); loader = delegate { return(((CorValRef)Value).Val); }; }
/// <summary> /// Gets the full class path of the function /// </summary> /// <param name="sb">string builder to be used to create full class path</param> /// <param name="ct">The cortype of the function</param> // Ignore the complexity warning - don't want to rewrite it now. private void GetFunctionClassPath(StringBuilder sb, CorType ct) { //StringBuilder sb, CorType ct, CorMetadataImport importer switch (ct.Type) { case CorElementType.ELEMENT_TYPE_CLASS: case CorElementType.ELEMENT_TYPE_VALUETYPE: // We need to get the name from the metadata. We can get a cached metadata importer // from a MDbgModule, or we could get a new one from the CorModule directly. // Is this hash lookup to get a MDbgModule cheaper than just re-querying for the importer? CorClass cc = ct.Class; Type tn = metaImporter.GetType(cc.Token); sb.Append(tn.FullName); //AddGenericArgs(sb, proc, ct.TypeParameters); return; // Primitives case CorElementType.ELEMENT_TYPE_BOOLEAN: sb.Append("System.Boolean"); return; case CorElementType.ELEMENT_TYPE_CHAR: sb.Append("System.Char"); return; case CorElementType.ELEMENT_TYPE_I1: sb.Append("System.SByte"); return; case CorElementType.ELEMENT_TYPE_U1: sb.Append("System.Byte"); return; case CorElementType.ELEMENT_TYPE_I2: sb.Append("System.Int16"); return; case CorElementType.ELEMENT_TYPE_U2: sb.Append("System.UInt16"); return; case CorElementType.ELEMENT_TYPE_I4: sb.Append("System.Int32"); return; case CorElementType.ELEMENT_TYPE_U4: sb.Append("System.Uint32"); return; case CorElementType.ELEMENT_TYPE_I8: sb.Append("System.Int64"); return; case CorElementType.ELEMENT_TYPE_U8: sb.Append("System.UInt64"); return; case CorElementType.ELEMENT_TYPE_I: sb.Append("System.IntPtr"); return; case CorElementType.ELEMENT_TYPE_U: sb.Append("System.UIntPtr"); return; case CorElementType.ELEMENT_TYPE_R4: sb.Append("System.Single"); return; case CorElementType.ELEMENT_TYPE_R8: sb.Append("System.Double"); return; // Well known class-types. case CorElementType.ELEMENT_TYPE_OBJECT: sb.Append("System.Object"); return; case CorElementType.ELEMENT_TYPE_STRING: sb.Append("System.String"); return; // Special compound types. Based off first type-param case CorElementType.ELEMENT_TYPE_SZARRAY: case CorElementType.ELEMENT_TYPE_ARRAY: case CorElementType.ELEMENT_TYPE_BYREF: case CorElementType.ELEMENT_TYPE_PTR: CorType t = ct.FirstTypeParameter; GetFunctionClassPath(sb, t); switch (ct.Type) { case CorElementType.ELEMENT_TYPE_SZARRAY: sb.Append("[]"); return; case CorElementType.ELEMENT_TYPE_ARRAY: int rank = ct.Rank; sb.Append('['); for (int i = 0; i < rank - 1; i++) { // <strip>@todo- could we print out exact boundaries? // Probably would have to do some sort of func-eval on the array object.</strip> sb.Append(','); } sb.Append(']'); return; case CorElementType.ELEMENT_TYPE_BYREF: sb.Append("&"); return; case CorElementType.ELEMENT_TYPE_PTR: sb.Append("*"); return; } Debug.Assert(false); // shouldn't have gotten here. return; // <strip>Other wacky stuff. // @todo - can we do a better job of printing these?</strip> case CorElementType.ELEMENT_TYPE_FNPTR: sb.Append("*(...)"); return; case CorElementType.ELEMENT_TYPE_TYPEDBYREF: sb.Append("typedbyref"); return; default: sb.Append("<unknown>"); return; } }
/// <summary> /// Read the pdb file for this module and frame /// Retrieve infomation about the function /// </summary> /// <remarks> /// When an unmanaged app like reflector loads CLR, "Function.Module.Name" /// doesn't return a valid value and so this function returns null. /// </remarks> /// <returns>SourcePosition of the function</returns> private SourcePosition GetMetaDataInfo(CorMetadataImport importer) { SourcePosition functionPos = null; //position in this function where we are try { moduleFullName = thisFrame.Function.Module.Name; moduleShortName = System.IO.Path.GetFileName(moduleFullName); } catch (ArgumentException) { moduleFullName = ""; moduleShortName = ""; return(null); } //TODO: Implement a better method to determine the symbol path than just assuming it's in the same // directory string sympath = "."; //dealing with readinf the source in the module ISymbolReader metaReader = null; ISymbolBinder1 symbolBinder = new SymbolBinder(); try { if (moduleFullName.Length > 0) { metaReader = (symbolBinder as SymbolBinder). GetReaderForFile(importer.RawCOMObject, moduleFullName, sympath); } } catch (COMException) { //Debug.WriteLine(ed.ToString(CultureInfo.CurrentCulture.NumberFormat)); //will get here for any function which we cant read the .pdb file for //its not a big deal we just wont have source and line info } if (metaReader != null) { ISymbolMethod symMethod = null; try { symMethod = metaReader.GetMethod(new SymbolToken((int)thisFrame.Function.Token), thisFrame.Function.Version); int sequenceCount = symMethod.SequencePointCount; symDocs = new ISymbolDocument[sequenceCount]; offsets = new int[sequenceCount]; startLines = new int[sequenceCount]; startColumns = new int[sequenceCount]; endLines = new int[sequenceCount]; endColumns = new int[sequenceCount]; //Get the sequence points and store them in the apporpriate arrays. Seqeunce points //represent the different points in the files which correlate to il instruction and lines symMethod.GetSequencePoints(offsets, symDocs, startLines, startColumns, endLines, endColumns); functionPos = GetSourcePositionFromFrame(); } catch (COMException) { functionPos = null; } finally { symDocs = null; symMethod = null; } } CorType ctype = GetClassType(); if (ctype != null) { StringBuilder sb = new StringBuilder(); GetFunctionClassPath(sb, ctype); functionFullName = sb.ToString(); } else { functionFullName = ""; } MethodInfo methIn = importer.GetMethodInfo(thisFrame.Function.Token); functionFullName += "." + methIn.Name; functionShortName = methIn.Name; return(functionPos); }
static CorFieldInfo ReadFieldInfo(IMetaDataImport mdi, uint token, CorType type) { if (mdi == null) return null; var name = GetFieldName(mdi, token); if (name == null) return null; var fieldType = GetFieldTypeSig(mdi, token); if (fieldType == null) return null; var attrs = GetFieldAttributes(mdi, token); CorElementType constantType; var constant = GetFieldConstant(mdi, token, out constantType); var browseState = GetDebuggerBrowsableState(mdi, token); bool compilerGeneratedAttribute = GetCompilerGeneratedAttribute(mdi, token); return new CorFieldInfo(type, token, name, fieldType, attrs, constant, constantType, browseState, compilerGeneratedAttribute); }
unsafe static CorPropertyInfo ReadPropertyInfo(IMetaDataImport mdi, uint token, CorType type) { if (mdi == null) return null; uint chProperty, dwPropFlags, mdSetter, mdGetter; int hr = mdi.GetPropertyProps(token, IntPtr.Zero, IntPtr.Zero, 0, out chProperty, out dwPropFlags, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, out mdSetter, out mdGetter, IntPtr.Zero, 0, IntPtr.Zero); char[] nameBuf = null; if (hr >= 0 && chProperty != 0) { nameBuf = new char[chProperty]; fixed (char* p = &nameBuf[0]) hr = mdi.GetPropertyProps(token, IntPtr.Zero, new IntPtr(p), (uint)nameBuf.Length, out chProperty, out dwPropFlags, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, out mdSetter, out mdGetter, IntPtr.Zero, 0, IntPtr.Zero); } if (hr < 0) return null; string name = chProperty <= 1 ? string.Empty : new string(nameBuf, 0, (int)chProperty - 1); var getSig = GetMethodSignature(mdi, mdGetter); var setSig = GetMethodSignature(mdi, mdSetter); if (getSig == null) return null; if (getSig.ParamsAfterSentinel != null) return null; if (getSig.GenParamCount != 0) return null; if (getSig.Params.Count != 0) return null; if (getSig.RetType.RemovePinnedAndModifiers().GetElementType() == ElementType.Void) return null; if (setSig != null && setSig.ParamsAfterSentinel != null) setSig = null; if (setSig != null && setSig.GenParamCount != 0) setSig = null; if (setSig != null && setSig.Params.Count != 1) setSig = null; if (setSig != null && setSig.RetType.RemovePinnedAndModifiers().GetElementType() != ElementType.Void) setSig = null; if (setSig != null && getSig.HasThis != setSig.HasThis) setSig = null; if (setSig != null && !Equals(getSig.RetType.RemovePinnedAndModifiers(), setSig.Params[0].RemovePinnedAndModifiers())) setSig = null; if (setSig == null) mdSetter = 0; MethodAttributes getMethodAttrs; MethodImplAttributes dwImplAttrs; IntPtr pvSigBlob; hr = mdi.GetMethodProps(mdGetter, IntPtr.Zero, IntPtr.Zero, 0, out chProperty, out getMethodAttrs, out pvSigBlob, out chProperty, out chProperty, out dwImplAttrs); if (hr < 0) return null; var browseState = GetDebuggerBrowsableState(mdi, token); return new CorPropertyInfo(type, token, mdGetter, mdSetter, name, getSig, setSig, getMethodAttrs, browseState); }
protected override TypeDisplayData OnGetTypeDisplayData(EvaluationContext ctx, object gtype) { CorType type = (CorType)gtype; CorEvaluationContext wctx = (CorEvaluationContext)ctx; Type t = type.GetTypeInfo(wctx.Session); if (t == null) { return(null); } string proxyType = null; string nameDisplayString = null; string typeDisplayString = null; string valueDisplayString = null; Dictionary <string, DebuggerBrowsableState> memberData = null; bool hasTypeData = false; foreach (object att in t.GetCustomAttributes(false)) { DebuggerTypeProxyAttribute patt = att as DebuggerTypeProxyAttribute; if (patt != null) { proxyType = patt.ProxyTypeName; hasTypeData = true; continue; } DebuggerDisplayAttribute datt = att as DebuggerDisplayAttribute; if (datt != null) { hasTypeData = true; nameDisplayString = datt.Name; typeDisplayString = datt.Type; valueDisplayString = datt.Value; continue; } } ArrayList mems = new ArrayList(); mems.AddRange(t.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance)); mems.AddRange(t.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance)); foreach (MemberInfo m in mems) { object[] atts = m.GetCustomAttributes(typeof(DebuggerBrowsableAttribute), false); if (atts.Length == 0) { atts = m.GetCustomAttributes(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute), false); if (atts.Length > 0) { atts[0] = new DebuggerBrowsableAttribute(DebuggerBrowsableState.Never); } } if (atts.Length > 0) { hasTypeData = true; if (memberData == null) { memberData = new Dictionary <string, DebuggerBrowsableState> (); } memberData[m.Name] = ((DebuggerBrowsableAttribute)atts[0]).State; } } if (hasTypeData) { return(new TypeDisplayData(proxyType, valueDisplayString, typeDisplayString, nameDisplayString, false, memberData)); } else { return(null); } }
public override string CallToString(EvaluationContext ctx, object objr) { CorValue obj = GetRealObject(ctx, objr); if ((obj is CorReferenceValue) && ((CorReferenceValue)obj).IsNull) { return(string.Empty); } CorStringValue stringVal = obj as CorStringValue; if (stringVal != null) { return(stringVal.String); } CorArrayValue arr = obj as CorArrayValue; if (arr != null) { StringBuilder tn = new StringBuilder(GetDisplayTypeName(ctx, arr.ExactType.FirstTypeParameter)); tn.Append("["); int[] dims = arr.GetDimensions(); for (int n = 0; n < dims.Length; n++) { if (n > 0) { tn.Append(','); } tn.Append(dims[n]); } tn.Append("]"); return(tn.ToString()); } CorEvaluationContext cctx = (CorEvaluationContext)ctx; CorObjectValue co = obj as CorObjectValue; if (co != null) { if (IsEnum(ctx, co.ExactType)) { MetadataType rt = co.ExactType.GetTypeInfo(cctx.Session) as MetadataType; bool isFlags = rt != null && rt.ReallyIsFlagsEnum; string enumName = GetTypeName(ctx, co.ExactType); ValueReference val = GetMember(ctx, null, objr, "value__"); ulong nval = (ulong)System.Convert.ChangeType(val.ObjectValue, typeof(ulong)); ulong remainingFlags = nval; string flags = null; foreach (ValueReference evals in GetMembers(ctx, co.ExactType, null, BindingFlags.Public | BindingFlags.Static)) { ulong nev = (ulong)System.Convert.ChangeType(evals.ObjectValue, typeof(ulong)); if (nval == nev) { return(evals.Name); } if (isFlags && nev != 0 && (nval & nev) == nev) { if (flags == null) { flags = enumName + "." + evals.Name; } else { flags += " | " + enumName + "." + evals.Name; } remainingFlags &= ~nev; } } if (isFlags) { if (remainingFlags == nval) { return(nval.ToString()); } if (remainingFlags != 0) { flags += " | " + remainingFlags; } return(flags); } else { return(nval.ToString()); } } CorType targetType = (CorType)GetValueType(ctx, objr); MethodInfo met = OverloadResolve(cctx, "ToString", targetType, new CorType[0], BindingFlags.Public | BindingFlags.Instance, false); if (met != null && met.DeclaringType.FullName != "System.Object") { object[] args = new object[0]; object ores = RuntimeInvoke(ctx, targetType, objr, "ToString", args, args); CorStringValue res = GetRealObject(ctx, ores) as CorStringValue; if (res != null) { return(res.String); } } return(GetDisplayTypeName(ctx, targetType)); } CorGenericValue genVal = obj as CorGenericValue; if (genVal != null) { return(genVal.GetValue().ToString()); } return(base.CallToString(ctx, obj)); }
unsafe static CorPropertyInfo ReadPropertyInfo(IMetaDataImport mdi, uint token, CorType type) { if (mdi == null) return null; var name = MDAPI.GetPropertyName(mdi, token); if (name == null) return null; uint mdSetter, mdGetter; if (!MDAPI.GetPropertyGetterSetter(mdi, token, out mdGetter, out mdSetter)) return null; var getSig = GetMethodSignature(mdi, mdGetter); var setSig = GetMethodSignature(mdi, mdSetter); if (getSig == null) return null; if (getSig.ParamsAfterSentinel != null) return null; if (getSig.GenParamCount != 0) return null; if (getSig.Params.Count != 0) return null; if (getSig.RetType.RemovePinnedAndModifiers().GetElementType() == ElementType.Void) return null; if (setSig != null && setSig.ParamsAfterSentinel != null) setSig = null; if (setSig != null && setSig.GenParamCount != 0) setSig = null; if (setSig != null && setSig.Params.Count != 1) setSig = null; if (setSig != null && setSig.RetType.RemovePinnedAndModifiers().GetElementType() != ElementType.Void) setSig = null; if (setSig != null && getSig.HasThis != setSig.HasThis) setSig = null; if (setSig != null && !Equals(getSig.RetType.RemovePinnedAndModifiers(), setSig.Params[0].RemovePinnedAndModifiers())) setSig = null; if (setSig == null) mdSetter = 0; MethodAttributes getMethodAttrs; MethodImplAttributes getMethodImplAttrs; if (!MDAPI.GetMethodAttributes(mdi, mdGetter, out getMethodAttrs, out getMethodImplAttrs)) return null; var browseState = GetDebuggerBrowsableState(mdi, token); return new CorPropertyInfo(type, token, mdGetter, mdSetter, name, getSig, setSig, getMethodAttrs, browseState); }
public PropertyReference(EvaluationContext ctx, PropertyInfo prop, CorValRef thisobj, CorType declaringType, CorValRef[] index) : base(ctx) { this.prop = prop; this.declaringType = declaringType; this.module = declaringType.Class.Module; this.index = index; if (!prop.GetGetMethod(true).IsStatic) { this.thisobj = thisobj; } loader = delegate { return(((CorValRef)Value).Val); }; }
// Helper to get all the fields, including static fields and base types. private MDbgValue[] InternalGetFields() { List <MDbgValue> al = new List <MDbgValue>(); //dereference && (unbox); CorValue value = Dereference(CorValue, null); if (value == null) { throw new MDbgValueException("null value"); } Unbox(ref value); CorObjectValue ov = value.CastToObjectValue(); CorType cType = ov.ExactType; CorFrame cFrame = null; if (Process.Threads.HaveActive) { // we need a current frame to display thread local static values if (Process.Threads.Active.HaveCurrentFrame) { MDbgFrame temp = Process.Threads.Active.CurrentFrame; while (temp != null && !temp.IsManaged) { temp = temp.NextUp; } if (temp != null) { cFrame = temp.CorFrame; } } } MDbgModule classModule; // initialization CorClass corClass = ov.Class; classModule = Process.Modules.Lookup(corClass.Module); // iteration through class hierarchy while (true) { Type classType = classModule.Importer.GetType(corClass.Token); foreach (MetadataFieldInfo fi in classType.GetFields()) { CorValue fieldValue = null; try { if (fi.IsLiteral) { fieldValue = null; // for now we just hide the constant fields. continue; } else if (fi.IsStatic) { if (cFrame == null) { // Without a frame, we won't be able to find static values. So // just skip this guy continue; } fieldValue = cType.GetStaticFieldValue(fi.MetadataToken, cFrame); } else { // we are asuming normal field value fieldValue = ov.GetFieldValue(corClass, fi.MetadataToken); } } catch (COMException) { // we won't report any problems. } al.Add(new MDbgValue(Process, fi.Name, fieldValue)); } cType = cType.Base; if (cType == null) { break; } corClass = cType.Class; classModule = Process.Modules.Lookup(corClass.Module); } return(al.ToArray()); }
public FieldReference(EvaluationContext ctx, CorValRef thisobj, CorType type, FieldInfo field) : this(ctx, thisobj, type, field, null, ObjectValueFlags.Field) { }
static CorMethodInfo ReadMethodInfo(IMetaDataImport mdi, uint token, CorType type) { if (mdi == null) return null; MethodAttributes attrs; MethodImplAttributes implAttrs; var name = GetMethodDefName(mdi, token, out attrs, out implAttrs); if (name == null) return null; var sig = GetMethodSignature(mdi, token); if (sig == null) return null; bool compilerGeneratedAttribute = GetCompilerGeneratedAttribute(mdi, token); return new CorMethodInfo(type, token, name, sig, attrs, implAttrs, compilerGeneratedAttribute); }
//社团类别添加 public static bool AddCorType(CorType c) { return(AdminService.AddCorType(c)); }
public CorMethodInfo(CorType ownerType, uint token, string name, MethodSig methodSig, MethodAttributes attrs, MethodImplAttributes implAttrs, bool compilerGeneratedAttribute) { this.OwnerType = ownerType; this.Token = token; this.Name = name; this.MethodSig = methodSig; this.MethodAttributes = attrs; this.MethodImplAttributes = implAttrs; this.CompilerGeneratedAttribute = compilerGeneratedAttribute; }
public override bool IsEnum(EvaluationContext ctx, object val) { CorType type = (CorType)GetValueType(ctx, val); return(IsEnum(ctx, type)); }
public LinkedList <T> this[CorType type] => Values[type];
public static IEnumerable<CorFieldInfo> GetFieldInfos(CorType type, bool checkBaseClasses = true) { for (; type != null; type = type.Base) { var cls = type.Class; var mod = cls == null ? null : cls.Module; var mdi = mod == null ? null : mod.GetMetaDataInterface<IMetaDataImport>(); var fdTokens = GetFieldTokens(mdi, cls == null ? 0 : cls.Token); foreach (var fdToken in fdTokens) { var info = ReadFieldInfo(mdi, fdToken, type); Debug.Assert(info != null); if (info != null) yield return info; } if (!checkBaseClasses) break; } }
public override object TryCast(EvaluationContext ctx, object val, object type) { CorType ctype = (CorType)GetValueType(ctx, val); CorValue obj = GetRealObject(ctx, val); string tname = GetTypeName(ctx, type); string ctypeName = GetValueTypeName(ctx, val); if (tname == "System.Object") { return(val); } if (tname == ctypeName) { return(val); } if (obj is CorStringValue) { return(ctypeName == tname ? val : null); } if (obj is CorArrayValue) { return((ctypeName == tname || ctypeName == "System.Array") ? val : null); } if (obj is CorObjectValue) { CorObjectValue co = (CorObjectValue)obj; if (IsEnum(ctx, co.ExactType)) { ValueReference rval = GetMember(ctx, null, val, "value__"); return(TryCast(ctx, rval.Value, type)); } while (ctype != null) { if (GetTypeName(ctx, ctype) == tname) { return(val); } ctype = ctype.Base; } return(null); } CorGenericValue genVal = obj as CorGenericValue; if (genVal != null) { Type t = Type.GetType(tname); if (t != null && t.IsPrimitive && t != typeof(string)) { object pval = genVal.GetValue(); try { pval = System.Convert.ChangeType(pval, t); } catch { return(null); } return(CreateValue(ctx, pval)); } else if (IsEnum(ctx, (CorType)type)) { return(CreateEnum(ctx, (CorType)type, val)); } } return(null); }
public static IEnumerable<CorPropertyInfo> GetProperties(CorType type, bool checkBaseClasses = true) { for (; type != null; type = type.Base) { uint token; var mdi = type.GetMetaDataImport(out token); var pdTokens = GetPropertyTokens(mdi, token); foreach (var pdToken in pdTokens) { var info = ReadPropertyInfo(mdi, pdToken, type); if (info != null) yield return info; } if (!checkBaseClasses) break; } }
public bool IsEnum(EvaluationContext ctx, CorType targetType) { return((targetType.Type == CorElementType.ELEMENT_TYPE_VALUETYPE || targetType.Type == CorElementType.ELEMENT_TYPE_CLASS) && targetType.Base != null && GetTypeName(ctx, targetType.Base) == "System.Enum"); }
public static CorMethodInfo GetToStringMethod(CorType type) { //TODO: Check for method overrides! for (; type != null; type = type.Base) { uint token; var mdi = type.GetMetaDataImport(out token); var mdTokens = GetMethodTokens(mdi, token); foreach (var mdToken in mdTokens) { var info = ReadMethodInfo(mdi, mdToken, type); if (info == null) continue; if (IsToString(info)) return info; } } return null; }
public CorValue CreateSZArray(CorType type, int numElems) { int hr; var res = WaitForResult(hr = eval.NewParameterizedArray(type, new uint[1] { (uint)numElems })); if (res == null || res.Value.WasException) throw new EvalException(hr, string.Format("Could not create an array, HR=0x{0:X8}", hr)); return res.Value.ResultOrException; }
// Print CorType to the given string builder. // Will print generic info. internal static void PrintCorType(StringBuilder sb, MDbgProcess proc, CorType ct) { switch (ct.Type) { case CorElementType.ELEMENT_TYPE_CLASS: case CorElementType.ELEMENT_TYPE_VALUETYPE: // We need to get the name from the metadata. We can get a cached metadata importer // from a MDbgModule, or we could get a new one from the CorModule directly. // Is this hash lookup to get a MDbgModule cheaper than just re-querying for the importer? CorClass cc = ct.Class; MDbgModule m = proc.Modules.Lookup(cc.Module); Type tn = m.Importer.GetType(cc.Token); sb.Append(tn.FullName); AddGenericArgs(sb, proc, ct.TypeParameters); return; // Primitives case CorElementType.ELEMENT_TYPE_BOOLEAN: sb.Append("System.Boolean"); return; case CorElementType.ELEMENT_TYPE_CHAR: sb.Append("System.Char"); return; case CorElementType.ELEMENT_TYPE_I1: sb.Append("System.SByte"); return; case CorElementType.ELEMENT_TYPE_U1: sb.Append("System.Byte"); return; case CorElementType.ELEMENT_TYPE_I2: sb.Append("System.Int16"); return; case CorElementType.ELEMENT_TYPE_U2: sb.Append("System.UInt16"); return; case CorElementType.ELEMENT_TYPE_I4: sb.Append("System.Int32"); return; case CorElementType.ELEMENT_TYPE_U4: sb.Append("System.Uint32"); return; case CorElementType.ELEMENT_TYPE_I8: sb.Append("System.Int64"); return; case CorElementType.ELEMENT_TYPE_U8: sb.Append("System.UInt64"); return; case CorElementType.ELEMENT_TYPE_I: sb.Append("System.IntPtr"); return; case CorElementType.ELEMENT_TYPE_U: sb.Append("System.UIntPtr"); return; case CorElementType.ELEMENT_TYPE_R4: sb.Append("System.Single"); return; case CorElementType.ELEMENT_TYPE_R8: sb.Append("System.Double"); return; // Well known class-types. case CorElementType.ELEMENT_TYPE_OBJECT: sb.Append("System.Object"); return; case CorElementType.ELEMENT_TYPE_STRING: sb.Append("System.String"); return; // Special compound types. Based off first type-param case CorElementType.ELEMENT_TYPE_SZARRAY: case CorElementType.ELEMENT_TYPE_ARRAY: case CorElementType.ELEMENT_TYPE_BYREF: case CorElementType.ELEMENT_TYPE_PTR: CorType t = ct.FirstTypeParameter; PrintCorType(sb, proc, t); switch (ct.Type) { case CorElementType.ELEMENT_TYPE_SZARRAY: sb.Append("[]"); return; case CorElementType.ELEMENT_TYPE_ARRAY: int rank = ct.Rank; sb.Append('['); for (int i = 0; i < rank - 1; i++) { sb.Append(','); } sb.Append(']'); return; case CorElementType.ELEMENT_TYPE_BYREF: sb.Append("&"); return; case CorElementType.ELEMENT_TYPE_PTR: sb.Append("*"); return; } Debug.Assert(false); // shouldn't have gotten here. return; case CorElementType.ELEMENT_TYPE_FNPTR: sb.Append("*(...)"); return; case CorElementType.ELEMENT_TYPE_TYPEDBYREF: sb.Append("typedbyref"); return; default: sb.Append("<unknown>"); return; } } // end PrintClass
public EvalResult CallConstructor(CorFunction ctor, CorType[] typeArgs, CorValue[] args) { int hr; var res = CallConstructor(ctor, typeArgs, args, out hr); if (res != null) return res.Value; throw new EvalException(hr, string.Format("Could not call .ctor {0:X8}, HR=0x{1:X8}", ctor.Token, hr)); }
public PropertyReference(EvaluationContext ctx, PropertyInfo prop, CorValRef thisobj, CorType declaringType) : this(ctx, prop, thisobj, declaringType, null) { }
public CorValue CreateValue(CorType type) => eval.CreateValueForType(type);
public string GetPrimitiveValue(CorType type, out byte[] bytes) { bytes = null; if (type == null) return "Internal error: CorType is null"; if (type.IsEnum) return GetEnumValue(type, out bytes); string error; var etype = type.TryGetPrimitiveType(); switch (etype) { case CorElementType.Boolean: { var value = NumberVMUtils.ParseBoolean(text, out error); if (!string.IsNullOrEmpty(error)) return error; bytes = BitConverter.GetBytes(value); return null; } case CorElementType.Char: { var value = NumberVMUtils.ParseChar(text, out error); if (!string.IsNullOrEmpty(error)) return error; bytes = BitConverter.GetBytes(value); return null; } case CorElementType.R4: { var value = NumberVMUtils.ParseSingle(text, out error); if (!string.IsNullOrEmpty(error)) return error; bytes = BitConverter.GetBytes(value); return null; } case CorElementType.R8: { var value = NumberVMUtils.ParseDouble(text, out error); if (!string.IsNullOrEmpty(error)) return error; bytes = BitConverter.GetBytes(value); return null; } case CorElementType.Class: case CorElementType.ValueType: if (type.IsSystemDecimal) { var value = NumberVMUtils.ParseDecimal(text, out error); if (!string.IsNullOrEmpty(error)) return error; bytes = GetBytes(value); return null; } return null; case CorElementType.I: case CorElementType.U: case CorElementType.Ptr: case CorElementType.FnPtr: if (text.Trim() == "null") { bytes = new byte[IntPtr.Size]; return null; } break; } ulong? res = ParseIntegerConstant(etype, text, out error); if (res == null) return error ?? dnSpy_Debugger_Resources.LocalsEditValue_Error_InvalidNumber; switch (etype) { case CorElementType.I1: bytes = new byte[1] { (byte)res.Value }; return null; case CorElementType.U1: bytes = new byte[1] { (byte)res.Value }; return null; case CorElementType.I2: bytes = BitConverter.GetBytes((short)res.Value); return null; case CorElementType.U2: bytes = BitConverter.GetBytes((ushort)res.Value); return null; case CorElementType.I4: bytes = BitConverter.GetBytes((int)res.Value); return null; case CorElementType.U4: bytes = BitConverter.GetBytes((uint)res.Value); return null; case CorElementType.I8: bytes = BitConverter.GetBytes((long)res.Value); return null; case CorElementType.U8: bytes = BitConverter.GetBytes(res.Value); return null; case CorElementType.I: case CorElementType.U: case CorElementType.Ptr: case CorElementType.FnPtr: if (IntPtr.Size == 4) goto case CorElementType.I4; goto case CorElementType.I8; } return "Unknown number type"; }
public EvalResult? CreateDontCallConstructor(CorType type, out int hr) { if (!type.HasClass) { hr = -1; return null; } return WaitForResult(hr = eval.NewParameterizedObjectNoConstructor(type.Class, type.TypeParameters.ToArray())); }
public string GetPrimitiveValue(CorType type, out byte[] bytes) { bytes = null; if (type == null) { return("Internal error: CorType is null"); } if (type.IsEnum) { return(GetEnumValue(type, out bytes)); } string error; var etype = type.TryGetPrimitiveType(); switch (etype) { case CorElementType.Boolean: { var value = SimpleTypeConverter.ParseBoolean(text, out error); if (!string.IsNullOrEmpty(error)) { return(error); } bytes = BitConverter.GetBytes(value); return(null); } case CorElementType.Char: { var value = SimpleTypeConverter.ParseChar(text, out error); if (!string.IsNullOrEmpty(error)) { return(error); } bytes = BitConverter.GetBytes(value); return(null); } case CorElementType.R4: { var value = SimpleTypeConverter.ParseSingle(text, out error); if (!string.IsNullOrEmpty(error)) { return(error); } bytes = BitConverter.GetBytes(value); return(null); } case CorElementType.R8: { var value = SimpleTypeConverter.ParseDouble(text, out error); if (!string.IsNullOrEmpty(error)) { return(error); } bytes = BitConverter.GetBytes(value); return(null); } case CorElementType.Class: case CorElementType.ValueType: if (type.IsSystemDecimal) { var value = SimpleTypeConverter.ParseDecimal(text, out error); if (!string.IsNullOrEmpty(error)) { return(error); } bytes = GetBytes(value); return(null); } return(null); case CorElementType.I: case CorElementType.U: case CorElementType.Ptr: case CorElementType.FnPtr: if (text.Trim() == "null") { bytes = new byte[IntPtr.Size]; return(null); } break; } ulong?res = ParseIntegerConstant(etype, text, out error); if (res == null) { return(error ?? dnSpy_Debugger_Resources.LocalsEditValue_Error_InvalidNumber); } switch (etype) { case CorElementType.I1: bytes = new byte[1] { (byte)res.Value }; return(null); case CorElementType.U1: bytes = new byte[1] { (byte)res.Value }; return(null); case CorElementType.I2: bytes = BitConverter.GetBytes((short)res.Value); return(null); case CorElementType.U2: bytes = BitConverter.GetBytes((ushort)res.Value); return(null); case CorElementType.I4: bytes = BitConverter.GetBytes((int)res.Value); return(null); case CorElementType.U4: bytes = BitConverter.GetBytes((uint)res.Value); return(null); case CorElementType.I8: bytes = BitConverter.GetBytes((long)res.Value); return(null); case CorElementType.U8: bytes = BitConverter.GetBytes(res.Value); return(null); case CorElementType.I: case CorElementType.U: case CorElementType.Ptr: case CorElementType.FnPtr: if (IntPtr.Size == 4) { goto case CorElementType.I4; } goto case CorElementType.I8; } return("Unknown number type"); }
public EvalResult? CallConstructor(CorFunction func, CorType[] typeArgs, CorValue[] args, out int hr) => WaitForResult(hr = eval.NewParameterizedObject(func, typeArgs, args));
public EvalResult Call(CorFunction func, CorType[] typeArgs, CorValue[] args) { int hr; var res = Call(func, typeArgs, args, out hr); if (res != null) return res.Value; throw new EvalException(hr, string.Format("Could not call method {0:X8}, HR=0x{1:X8}", func.Token, hr)); }
/// <summary> /// Returns a string that represents current frame /// Currently supported formats: /// null or empty string: returns short frame format (just frame name) /// "v" : returns long frame format (including module & arguments) /// </summary> /// <param name="format">Which format to use.</param> /// <returns>The formatted string that represtents the current frame.</returns> public override string ToString(string format) { string fn; switch (m_frame.FrameType) { case CorFrameType.ILFrame: MDbgSourcePosition sl = SourcePosition; string sp; if (sl != null) { string filePath = sl.Path; if (!Thread.m_threadMgr.m_process.m_engine.Options.ShowFullPaths) { filePath = Path.GetFileName(sl.Path); } sp = " (" + filePath + ":" + sl.Line.ToString(System.Globalization.CultureInfo.CurrentUICulture) + ")"; } else { sp = " (source line information unavailable)"; } StringBuilder sbFuncName = new StringBuilder(); MDbgModule module = this.Function.Module; MDbgProcess proc = Thread.m_threadMgr.m_process; // Get class name w/ generic args. CorType tClass = this.FunctionType; if (tClass != null) { InternalUtil.PrintCorType(sbFuncName, proc, tClass); } sbFuncName.Append('.'); // Get method name w/ generic args. MethodInfo mi = this.Function.MethodInfo; sbFuncName.Append(mi.Name); InternalUtil.AddGenericArgs(sbFuncName, proc, this.FunctionTypeParameters); string stFuncName = sbFuncName.ToString(); if (format == "v") { CorModule m = module.CorModule; // verbose frame output // in verbose output we'll print module name + arguments to the functions StringBuilder sb = new StringBuilder(); bool bFirst = true; foreach (MDbgValue v in this.Function.GetArguments(this)) { if (sb.Length != 0) { sb.Append(", "); } // skip this references if (!(bFirst && v.Name == "this")) { sb.Append(v.Name).Append("=").Append(v.GetStringValue(0)); } bFirst = false; } if (m.IsDynamic || m.IsInMemory) { fn = m.Name; } else { fn = System.IO.Path.GetFileName(m.Name); } MDbgAppDomain ad = this.Thread.m_threadMgr.m_process.AppDomains.Lookup(m.Assembly.AppDomain); fn += "#" + ad.Number + "!" + stFuncName + "(" + sb.ToString() + ") " + sp; } else { fn = stFuncName + sp; } break; case CorFrameType.NativeFrame: fn = "[IL Method without Metadata]"; break; case CorFrameType.InternalFrame: switch (m_frame.InternalFrameType) { case CorDebugInternalFrameType.STUBFRAME_NONE: fn = "None"; break; case CorDebugInternalFrameType.STUBFRAME_M2U: fn = "M-->U"; break; case CorDebugInternalFrameType.STUBFRAME_U2M: fn = "U-->M"; break; case CorDebugInternalFrameType.STUBFRAME_APPDOMAIN_TRANSITION: fn = "AD Switch"; break; case CorDebugInternalFrameType.STUBFRAME_LIGHTWEIGHT_FUNCTION: fn = "LightWeight"; break; case CorDebugInternalFrameType.STUBFRAME_FUNC_EVAL: fn = "FuncEval"; break; case CorDebugInternalFrameType.STUBFRAME_INTERNALCALL: fn = "InternalCall"; break; case CorDebugInternalFrameType.STUBFRAME_CLASS_INIT: fn = "ClassInit"; break; case CorDebugInternalFrameType.STUBFRAME_EXCEPTION: fn = "Exception"; break; case CorDebugInternalFrameType.STUBFRAME_SECURITY: fn = "Security"; break; case CorDebugInternalFrameType.STUBFRAME_JIT_COMPILATION: fn = "JitCompilation"; break; default: fn = "UNKNOWN"; break; } fn = "[Internal Frame, '" + fn + "']"; break; default: fn = "UNKNOWN Frame Type"; break; } return(fn); }
public CorValueResult CallResult(CorFunction func, CorType[] typeArgs, CorValue[] args, out int hr) { var res = Call(func, typeArgs, args, out hr); if (res == null || res.Value.WasException || res.Value.ResultOrException == null) return new CorValueResult(); return res.Value.ResultOrException.Value; }
public DmdType Create(CorType type) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (recursionCounter++ > 100) { throw new InvalidOperationException(); } DmdType result; List <DmdType> types; switch (type.ElementType) { case CorElementType.Void: result = reflectionAppDomain.System_Void; break; case CorElementType.Boolean: result = reflectionAppDomain.System_Boolean; break; case CorElementType.Char: result = reflectionAppDomain.System_Char; break; case CorElementType.I1: result = reflectionAppDomain.System_SByte; break; case CorElementType.U1: result = reflectionAppDomain.System_Byte; break; case CorElementType.I2: result = reflectionAppDomain.System_Int16; break; case CorElementType.U2: result = reflectionAppDomain.System_UInt16; break; case CorElementType.I4: result = reflectionAppDomain.System_Int32; break; case CorElementType.U4: result = reflectionAppDomain.System_UInt32; break; case CorElementType.I8: result = reflectionAppDomain.System_Int64; break; case CorElementType.U8: result = reflectionAppDomain.System_UInt64; break; case CorElementType.R4: result = reflectionAppDomain.System_Single; break; case CorElementType.R8: result = reflectionAppDomain.System_Double; break; case CorElementType.String: result = reflectionAppDomain.System_String; break; case CorElementType.TypedByRef: result = reflectionAppDomain.System_TypedReference; break; case CorElementType.I: result = reflectionAppDomain.System_IntPtr; break; case CorElementType.U: result = reflectionAppDomain.System_UIntPtr; break; case CorElementType.Object: result = reflectionAppDomain.System_Object; break; case CorElementType.Ptr: result = Create(type.FirstTypeParameter).MakePointerType(); break; case CorElementType.ByRef: result = Create(type.FirstTypeParameter).MakeByRefType(); break; case CorElementType.SZArray: result = Create(type.FirstTypeParameter).MakeArrayType(); break; case CorElementType.Array: result = Create(type.FirstTypeParameter).MakeArrayType((int)type.Rank); break; case CorElementType.ValueType: case CorElementType.Class: var cl = type.Class ?? throw new InvalidOperationException(); var module = engine.TryGetModule(cl.Module)?.GetReflectionModule() ?? throw new InvalidOperationException(); var reflectionType = module.ResolveType((int)cl.Token, DmdResolveOptions.ThrowOnError); if (reflectionType.GetGenericArguments().Count != 0) { types = GetTypesList(); foreach (var t in type.TypeParameters) { types.Add(Create(t)); } Debug.Assert(types.Count == 0 || reflectionType.GetGenericArguments().Count == types.Count); if (types.Count != 0) { reflectionType = reflectionType.MakeGenericType(types.ToArray()); } FreeTypesList(ref types); } result = reflectionType; break; case CorElementType.FnPtr: DmdType returnType = null; types = null; foreach (var t in type.TypeParameters) { if ((object)returnType == null) { returnType = Create(t); } else { if (types == null) { types = GetTypesList(); } types.Add(Create(t)); } } if ((object)returnType == null) { throw new InvalidOperationException(); } //TODO: Guessing FnPtr calling convention const DmdSignatureCallingConvention fnPtrCallingConvention = DmdSignatureCallingConvention.C; //TODO: We're assuming varArgsParameterTypes is empty result = reflectionAppDomain.MakeFunctionPointerType(fnPtrCallingConvention, 0, returnType, types?.ToArray() ?? Array.Empty <DmdType>(), Array.Empty <DmdType>(), null); FreeTypesList(ref types); break; case CorElementType.GenericInst: case CorElementType.Var: case CorElementType.MVar: case CorElementType.End: case CorElementType.ValueArray: case CorElementType.R: case CorElementType.CModReqd: case CorElementType.CModOpt: case CorElementType.Internal: case CorElementType.Module: case CorElementType.Sentinel: case CorElementType.Pinned: default: Debug.Fail($"Unsupported element type: {type.ElementType}"); throw new InvalidOperationException(); } recursionCounter--; return(result); }
public CorType Create(DmdType type) { if ((object)type == null) { throw new ArgumentNullException(nameof(type)); } if (recursionCounter++ > 100) { throw new InvalidOperationException(); } CorType result; int i; ReadOnlyCollection <DmdType> types; CorType[] corTypes; DnModule dnModule; switch (type.TypeSignatureKind) { case DmdTypeSignatureKind.Type: if (!engine.TryGetDnModule(type.Module.GetDebuggerModule() ?? throw new InvalidOperationException(), out dnModule)) { throw new InvalidOperationException(); } Debug.Assert((type.MetadataToken >> 24) == 0x02); result = dnModule.CorModule.GetClassFromToken((uint)type.MetadataToken).GetParameterizedType(type.IsValueType ? CorElementType.ValueType : CorElementType.Class); break; case DmdTypeSignatureKind.Pointer: result = Create(type.GetElementType()); result = appDomain.GetPtr(result); break; case DmdTypeSignatureKind.ByRef: result = Create(type.GetElementType()); result = appDomain.GetByRef(result); break; case DmdTypeSignatureKind.TypeGenericParameter: case DmdTypeSignatureKind.MethodGenericParameter: throw new InvalidOperationException(); case DmdTypeSignatureKind.SZArray: result = Create(type.GetElementType()); result = appDomain.GetSZArray(result); break; case DmdTypeSignatureKind.MDArray: result = Create(type.GetElementType()); result = appDomain.GetArray(result, (uint)type.GetArrayRank()); break; case DmdTypeSignatureKind.GenericInstance: result = Create(type.GetGenericTypeDefinition()); types = type.GetGenericArguments(); corTypes = new CorType[types.Count]; for (i = 0; i < corTypes.Length; i++) { corTypes[i] = Create(types[i]); } result = result.Class.GetParameterizedType(type.IsValueType ? CorElementType.ValueType : CorElementType.Class, corTypes); break; case DmdTypeSignatureKind.FunctionPointer: var methodSig = type.GetFunctionPointerMethodSignature(); types = methodSig.GetParameterTypes(); corTypes = new CorType[1 + types.Count + methodSig.GetVarArgsParameterTypes().Count]; corTypes[0] = Create(methodSig.ReturnType); for (i = 0; i < types.Count; i++) { corTypes[i + 1] = Create(types[i]); } types = methodSig.GetVarArgsParameterTypes(); for (i = 0; i < types.Count; i++) { corTypes[i + 1 + methodSig.GetParameterTypes().Count] = Create(types[i]); } result = appDomain.GetFnPtr(corTypes); break; default: throw new InvalidOperationException(); } if (result == null) { throw new InvalidOperationException(); } recursionCounter--; return(result); }
private MDbgValue[] InternalGetFields() { ArrayList al = new ArrayList(); //dereference && (unbox); CorValue value = Dereference(CorValue); if (value == null) { throw new MDbgValueException("null value"); } Unbox(ref value); CorObjectValue ov = value.CastToObjectValue(); CorType cType = ov.ExactType; CorFrame cFrame = null; if (Process.Threads.HaveActive) { // we need a current frame to display thread local static values if (Process.Threads.Active.HaveCurrentFrame) { cFrame = Process.Threads.Active.CurrentFrame.CorFrame; } } MDbgModule classModule; // initialization CorClass corClass = ov.Class; classModule = Process.Modules.Lookup(corClass.Module); // iteration through class hierarchy do { Type classType; //int parentToken; classType = classModule.Importer.GetType(corClass.Token); //classModule.Importer.GetTypeNameFromDef(classToken,out parentToken); foreach (MetadataFieldInfo fi in classType.GetFields()) { CorValue fieldValue = null; try { if (fi.IsLiteral) { fieldValue = null; // for now we just hide the constant fields. continue; } else if (fi.IsStatic) { fieldValue = cType.GetStaticFieldValue(fi.MetadataToken, cFrame); } else // we are asuming normal field value // GetFieldValueForTYpe Supersedes GetFieldValue // Will replace when all issues are resolved. //fieldValue = ov.GetFieldValueForType(cType, (uint)fi.Token); { fieldValue = ov.GetFieldValue(corClass, fi.MetadataToken); } } catch (COMException) { // we won't report any problems. } al.Add(new MDbgValue(Process, fi.Name, fieldValue)); } cType = cType.Base; if (cType == null) { break; } corClass = cType.Class; classModule = Process.Modules.Lookup(corClass.Module); }while (true); return((MDbgValue[])al.ToArray(typeof(MDbgValue))); }