diff --git a/source/VisualStudio.Extension/CorDebug/CorDebugClass.cs b/source/VisualStudio.Extension/CorDebug/CorDebugClass.cs index bbfb0742..f4d7433b 100644 --- a/source/VisualStudio.Extension/CorDebug/CorDebugClass.cs +++ b/source/VisualStudio.Extension/CorDebug/CorDebugClass.cs @@ -21,8 +21,8 @@ public CorDebugClass(CorDebugAssembly assembly, Pdbx.Class cls) m_assembly = assembly; m_pdbxClass = cls; } - - public CorDebugClass (CorDebugAssembly assembly, uint tkSymbolless) : this(assembly, null) + + public CorDebugClass(CorDebugAssembly assembly, uint tkSymbolless) : this(assembly, null) { m_tkSymbolless = tkSymbolless; } @@ -45,10 +45,10 @@ public CorDebugAssembly Assembly public bool IsEnum { - get + get { - if(HasSymbols) - return MetaData.Helper.ClassIsEnum(Assembly.MetaDataImport, m_pdbxClass.Token.CLR ); + if (HasSymbols) + return MetaData.Helper.ClassIsEnum(Assembly.MetaDataImport, m_pdbxClass.Token.CLR); else return false; } @@ -75,7 +75,7 @@ public CorDebugAppDomain AppDomain public Pdbx.Class PdbxClass { [DebuggerHidden] - get {return m_pdbxClass;} + get { return m_pdbxClass; } } public bool HasSymbols @@ -89,27 +89,27 @@ public uint TypeDef_Index { uint tk = HasSymbols ? m_pdbxClass.Token.nanoCLR : m_tkSymbolless; - return nanoCLR_TypeSystem.ClassMemberIndexFromnanoCLRToken (tk, Assembly); + return nanoCLR_TypeSystem.ClassMemberIndexFromnanoCLRToken(tk, Assembly); } } #region ICorDebugClass Members - int ICorDebugClass. GetModule (out ICorDebugModule pModule) + int ICorDebugClass.GetModule(out ICorDebugModule pModule) { pModule = m_assembly; return COM_HResults.S_OK; } - int ICorDebugClass. GetToken (out uint pTypeDef) + int ICorDebugClass.GetToken(out uint pTypeDef) { pTypeDef = HasSymbols ? m_pdbxClass.Token.CLR : m_tkSymbolless; return COM_HResults.S_OK; } - int ICorDebugClass. GetStaticFieldValue (uint fieldDef, ICorDebugFrame pFrame, out ICorDebugValue ppValue) + int ICorDebugClass.GetStaticFieldValue(uint fieldDef, ICorDebugFrame pFrame, out ICorDebugValue ppValue) { //Cache, and invalidate when necessary??? uint fd = nanoCLR_TypeSystem.ClassMemberIndexFromCLRToken(fieldDef, Assembly); @@ -125,15 +125,14 @@ int ICorDebugClass. GetStaticFieldValue (uint fieldDef, ICorDebugFrame pFrame, o #region ICorDebugClass2 Members - int ICorDebugClass2.GetParameterizedType( CorElementType elementType, uint nTypeArgs, ICorDebugType []ppTypeArgs, out ICorDebugType ppType ) + int ICorDebugClass2.GetParameterizedType(CorElementType elementType, uint nTypeArgs, ICorDebugType[] ppTypeArgs, out ICorDebugType ppType) { - // CorDebugClass.GetParameterizedType is not implemented - ppType = null; + ppType = new CorDebugGenericType(elementType, null, Assembly); return COM_HResults.S_OK; } - int ICorDebugClass2. SetJMCStatus (int bIsJustMyCode) + int ICorDebugClass2.SetJMCStatus(int bIsJustMyCode) { bool fJMC = Boolean.IntToBool(bIsJustMyCode); @@ -145,12 +144,12 @@ int ICorDebugClass2. SetJMCStatus (int bIsJustMyCode) { if (Engine.Info_SetJMC(fJMC, ReflectionDefinition.Kind.REFLECTION_TYPE, TypeDef_Index)) { - if(!m_assembly.IsFrameworkAssembly) + if (!m_assembly.IsFrameworkAssembly) { //now update the debugger JMC state... foreach (Pdbx.Method m in m_pdbxClass.Methods) - { - m.IsJMC = fJMC; + { + m.IsJMC = fJMC; } } @@ -161,6 +160,6 @@ int ICorDebugClass2. SetJMCStatus (int bIsJustMyCode) return hres; } -#endregion + #endregion } } diff --git a/source/VisualStudio.Extension/CorDebug/CorDebugType.cs b/source/VisualStudio.Extension/CorDebug/CorDebugType.cs index 641ae992..58b82ce2 100644 --- a/source/VisualStudio.Extension/CorDebug/CorDebugType.cs +++ b/source/VisualStudio.Extension/CorDebug/CorDebugType.cs @@ -15,33 +15,33 @@ namespace nanoFramework.Tools.VisualStudio.Extension public class CorDebugTypeArray : ICorDebugType { CorDebugValueArray m_ValueArray; - - public CorDebugTypeArray( CorDebugValueArray valArray ) + + public CorDebugTypeArray(CorDebugValueArray valArray) { - m_ValueArray = valArray; + m_ValueArray = valArray; } - int ICorDebugType.EnumerateTypeParameters (out ICorDebugTypeEnum ppTyParEnum) + int ICorDebugType.EnumerateTypeParameters(out ICorDebugTypeEnum ppTyParEnum) { ppTyParEnum = null; return COM_HResults.E_NOTIMPL; } - int ICorDebugType.GetType (out CorElementType ty) + int ICorDebugType.GetType(out CorElementType ty) { // This is for arrays. ELEMENT_TYPE_SZARRAY - means single demensional array. ty = CorElementType.ELEMENT_TYPE_SZARRAY; return COM_HResults.S_OK; } - int ICorDebugType.GetRank (out uint pnRank) + int ICorDebugType.GetRank(out uint pnRank) { // ELEMENT_TYPE_SZARRAY - means single demensional array. pnRank = 1; return COM_HResults.S_OK; } - int ICorDebugType.GetClass (out ICorDebugClass ppClass) + int ICorDebugType.GetClass(out ICorDebugClass ppClass) { ppClass = CorDebugValue.ClassFromRuntimeValue(m_ValueArray.RuntimeValue, m_ValueArray.AppDomain); return COM_HResults.S_OK; @@ -52,19 +52,19 @@ int ICorDebugType.GetClass (out ICorDebugClass ppClass) * of element in the array. * It control viewing of arrays elements in the watch window of debugger. */ - int ICorDebugType.GetFirstTypeParameter (out ICorDebugType value) + int ICorDebugType.GetFirstTypeParameter(out ICorDebugType value) { value = new CorDebugGenericType(CorElementType.ELEMENT_TYPE_CLASS, m_ValueArray.RuntimeValue, m_ValueArray.AppDomain); return COM_HResults.S_OK; } - int ICorDebugType.GetStaticFieldValue (uint fieldDef, ICorDebugFrame pFrame, out ICorDebugValue ppValue) - { + int ICorDebugType.GetStaticFieldValue(uint fieldDef, ICorDebugFrame pFrame, out ICorDebugValue ppValue) + { ppValue = null; return COM_HResults.E_NOTIMPL; } - int ICorDebugType.GetBase (out ICorDebugType pBase) + int ICorDebugType.GetBase(out ICorDebugType pBase) { pBase = null; return COM_HResults.E_NOTIMPL; @@ -77,11 +77,55 @@ public class CorDebugGenericType : ICorDebugType public RuntimeValue m_rtv; public CorDebugAppDomain m_appDomain; + public CorDebugAssembly Assembly + { + [System.Diagnostics.DebuggerHidden] + get; + } + + public Engine Engine + { + [System.Diagnostics.DebuggerHidden] + get { return this.Process?.Engine; } + } + + public CorDebugProcess Process + { + [System.Diagnostics.DebuggerHidden] + get { return this.Assembly?.Process; } + } + + public CorDebugAppDomain AppDomain + { + [System.Diagnostics.DebuggerHidden] + get + { + if (m_appDomain != null) + { + return m_appDomain; + } + else + { + return this.Assembly?.AppDomain; + } + } + } + + // This is used to resolve values into types when we know the appdomain, but not the assembly. public CorDebugGenericType(CorElementType elemType, RuntimeValue rtv, CorDebugAppDomain appDomain) - { + { m_elemType = elemType; m_rtv = rtv; - m_appDomain = appDomain; + m_appDomain = appDomain; + } + + // This constructor is used exclusively for resolving potentially (but never really) generic classes into fully specified types. + // Generics are not supported (yet) but we still need to be able to convert classes into fully specified types. + public CorDebugGenericType(CorElementType elemType, RuntimeValue rtv, CorDebugAssembly assembly) + { + m_elemType = elemType; + m_rtv = rtv; + Assembly = assembly; } int ICorDebugType.EnumerateTypeParameters(out ICorDebugTypeEnum ppTyParEnum) @@ -106,7 +150,7 @@ int ICorDebugType.GetRank(out uint pnRank) int ICorDebugType.GetClass(out ICorDebugClass ppClass) { - ppClass = CorDebugValue.ClassFromRuntimeValue(m_rtv, m_appDomain); + ppClass = CorDebugValue.ClassFromRuntimeValue(m_rtv, AppDomain); return COM_HResults.S_OK; } @@ -119,8 +163,13 @@ int ICorDebugType.GetFirstTypeParameter(out ICorDebugType value) int ICorDebugType.GetStaticFieldValue(uint fieldDef, ICorDebugFrame pFrame, out ICorDebugValue ppValue) { - ppValue = null; - return COM_HResults.E_NOTIMPL; + uint fd = nanoCLR_TypeSystem.ClassMemberIndexFromCLRToken(fieldDef, this.Assembly); + + this.Process.SetCurrentAppDomain(this.AppDomain); + RuntimeValue rtv = this.Engine.GetStaticFieldValue(fd); + ppValue = CorDebugValue.CreateValue(rtv, this.AppDomain); + + return COM_HResults.S_OK; } int ICorDebugType.GetBase(out ICorDebugType pBase)