public IDebuggerValue ReadStaticField(IStackFrame frame, uint token) { return(debugger.Dispatcher.UI(() => { var value = type.GetStaticFieldValue(token, ((StackFrame)frame).CorFrame); return value == null ? null : new DebuggerValue(debugger, value); })); }
// 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()); }
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))); }