Skip to content

Commit 8f6454b

Browse files
authored
Improvements in CorDebugType and CorDebugClass (#300)
1 parent a7e486f commit 8f6454b

File tree

2 files changed

+82
-34
lines changed

2 files changed

+82
-34
lines changed

source/VisualStudio.Extension/CorDebug/CorDebugClass.cs

+17-18
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public CorDebugClass(CorDebugAssembly assembly, Pdbx.Class cls)
2121
m_assembly = assembly;
2222
m_pdbxClass = cls;
2323
}
24-
25-
public CorDebugClass (CorDebugAssembly assembly, uint tkSymbolless) : this(assembly, null)
24+
25+
public CorDebugClass(CorDebugAssembly assembly, uint tkSymbolless) : this(assembly, null)
2626
{
2727
m_tkSymbolless = tkSymbolless;
2828
}
@@ -45,10 +45,10 @@ public CorDebugAssembly Assembly
4545

4646
public bool IsEnum
4747
{
48-
get
48+
get
4949
{
50-
if(HasSymbols)
51-
return MetaData.Helper.ClassIsEnum(Assembly.MetaDataImport, m_pdbxClass.Token.CLR );
50+
if (HasSymbols)
51+
return MetaData.Helper.ClassIsEnum(Assembly.MetaDataImport, m_pdbxClass.Token.CLR);
5252
else
5353
return false;
5454
}
@@ -75,7 +75,7 @@ public CorDebugAppDomain AppDomain
7575
public Pdbx.Class PdbxClass
7676
{
7777
[DebuggerHidden]
78-
get {return m_pdbxClass;}
78+
get { return m_pdbxClass; }
7979
}
8080

8181
public bool HasSymbols
@@ -89,27 +89,27 @@ public uint TypeDef_Index
8989
{
9090
uint tk = HasSymbols ? m_pdbxClass.Token.nanoCLR : m_tkSymbolless;
9191

92-
return nanoCLR_TypeSystem.ClassMemberIndexFromnanoCLRToken (tk, Assembly);
92+
return nanoCLR_TypeSystem.ClassMemberIndexFromnanoCLRToken(tk, Assembly);
9393
}
9494
}
9595

9696
#region ICorDebugClass Members
9797

98-
int ICorDebugClass. GetModule (out ICorDebugModule pModule)
98+
int ICorDebugClass.GetModule(out ICorDebugModule pModule)
9999
{
100100
pModule = m_assembly;
101101

102102
return COM_HResults.S_OK;
103103
}
104104

105-
int ICorDebugClass. GetToken (out uint pTypeDef)
105+
int ICorDebugClass.GetToken(out uint pTypeDef)
106106
{
107107
pTypeDef = HasSymbols ? m_pdbxClass.Token.CLR : m_tkSymbolless;
108108

109109
return COM_HResults.S_OK;
110110
}
111111

112-
int ICorDebugClass. GetStaticFieldValue (uint fieldDef, ICorDebugFrame pFrame, out ICorDebugValue ppValue)
112+
int ICorDebugClass.GetStaticFieldValue(uint fieldDef, ICorDebugFrame pFrame, out ICorDebugValue ppValue)
113113
{
114114
//Cache, and invalidate when necessary???
115115
uint fd = nanoCLR_TypeSystem.ClassMemberIndexFromCLRToken(fieldDef, Assembly);
@@ -125,15 +125,14 @@ int ICorDebugClass. GetStaticFieldValue (uint fieldDef, ICorDebugFrame pFrame, o
125125

126126
#region ICorDebugClass2 Members
127127

128-
int ICorDebugClass2.GetParameterizedType( CorElementType elementType, uint nTypeArgs, ICorDebugType []ppTypeArgs, out ICorDebugType ppType )
128+
int ICorDebugClass2.GetParameterizedType(CorElementType elementType, uint nTypeArgs, ICorDebugType[] ppTypeArgs, out ICorDebugType ppType)
129129
{
130-
// CorDebugClass.GetParameterizedType is not implemented
131-
ppType = null;
130+
ppType = new CorDebugGenericType(elementType, null, Assembly);
132131

133132
return COM_HResults.S_OK;
134133
}
135134

136-
int ICorDebugClass2. SetJMCStatus (int bIsJustMyCode)
135+
int ICorDebugClass2.SetJMCStatus(int bIsJustMyCode)
137136
{
138137
bool fJMC = Boolean.IntToBool(bIsJustMyCode);
139138

@@ -145,12 +144,12 @@ int ICorDebugClass2. SetJMCStatus (int bIsJustMyCode)
145144
{
146145
if (Engine.Info_SetJMC(fJMC, ReflectionDefinition.Kind.REFLECTION_TYPE, TypeDef_Index))
147146
{
148-
if(!m_assembly.IsFrameworkAssembly)
147+
if (!m_assembly.IsFrameworkAssembly)
149148
{
150149
//now update the debugger JMC state...
151150
foreach (Pdbx.Method m in m_pdbxClass.Methods)
152-
{
153-
m.IsJMC = fJMC;
151+
{
152+
m.IsJMC = fJMC;
154153
}
155154
}
156155

@@ -161,6 +160,6 @@ int ICorDebugClass2. SetJMCStatus (int bIsJustMyCode)
161160
return hres;
162161
}
163162

164-
#endregion
163+
#endregion
165164
}
166165
}

source/VisualStudio.Extension/CorDebug/CorDebugType.cs

+65-16
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,33 @@ namespace nanoFramework.Tools.VisualStudio.Extension
1515
public class CorDebugTypeArray : ICorDebugType
1616
{
1717
CorDebugValueArray m_ValueArray;
18-
19-
public CorDebugTypeArray( CorDebugValueArray valArray )
18+
19+
public CorDebugTypeArray(CorDebugValueArray valArray)
2020
{
21-
m_ValueArray = valArray;
21+
m_ValueArray = valArray;
2222
}
2323

24-
int ICorDebugType.EnumerateTypeParameters (out ICorDebugTypeEnum ppTyParEnum)
24+
int ICorDebugType.EnumerateTypeParameters(out ICorDebugTypeEnum ppTyParEnum)
2525
{
2626
ppTyParEnum = null;
2727
return COM_HResults.E_NOTIMPL;
2828
}
2929

30-
int ICorDebugType.GetType (out CorElementType ty)
30+
int ICorDebugType.GetType(out CorElementType ty)
3131
{
3232
// This is for arrays. ELEMENT_TYPE_SZARRAY - means single demensional array.
3333
ty = CorElementType.ELEMENT_TYPE_SZARRAY;
3434
return COM_HResults.S_OK;
3535
}
3636

37-
int ICorDebugType.GetRank (out uint pnRank)
37+
int ICorDebugType.GetRank(out uint pnRank)
3838
{
3939
// ELEMENT_TYPE_SZARRAY - means single demensional array.
4040
pnRank = 1;
4141
return COM_HResults.S_OK;
4242
}
4343

44-
int ICorDebugType.GetClass (out ICorDebugClass ppClass)
44+
int ICorDebugType.GetClass(out ICorDebugClass ppClass)
4545
{
4646
ppClass = CorDebugValue.ClassFromRuntimeValue(m_ValueArray.RuntimeValue, m_ValueArray.AppDomain);
4747
return COM_HResults.S_OK;
@@ -52,19 +52,19 @@ int ICorDebugType.GetClass (out ICorDebugClass ppClass)
5252
* of element in the array.
5353
* It control viewing of arrays elements in the watch window of debugger.
5454
*/
55-
int ICorDebugType.GetFirstTypeParameter (out ICorDebugType value)
55+
int ICorDebugType.GetFirstTypeParameter(out ICorDebugType value)
5656
{
5757
value = new CorDebugGenericType(CorElementType.ELEMENT_TYPE_CLASS, m_ValueArray.RuntimeValue, m_ValueArray.AppDomain);
5858
return COM_HResults.S_OK;
5959
}
6060

61-
int ICorDebugType.GetStaticFieldValue (uint fieldDef, ICorDebugFrame pFrame, out ICorDebugValue ppValue)
62-
{
61+
int ICorDebugType.GetStaticFieldValue(uint fieldDef, ICorDebugFrame pFrame, out ICorDebugValue ppValue)
62+
{
6363
ppValue = null;
6464
return COM_HResults.E_NOTIMPL;
6565
}
6666

67-
int ICorDebugType.GetBase (out ICorDebugType pBase)
67+
int ICorDebugType.GetBase(out ICorDebugType pBase)
6868
{
6969
pBase = null;
7070
return COM_HResults.E_NOTIMPL;
@@ -77,11 +77,55 @@ public class CorDebugGenericType : ICorDebugType
7777
public RuntimeValue m_rtv;
7878
public CorDebugAppDomain m_appDomain;
7979

80+
public CorDebugAssembly Assembly
81+
{
82+
[System.Diagnostics.DebuggerHidden]
83+
get;
84+
}
85+
86+
public Engine Engine
87+
{
88+
[System.Diagnostics.DebuggerHidden]
89+
get { return this.Process?.Engine; }
90+
}
91+
92+
public CorDebugProcess Process
93+
{
94+
[System.Diagnostics.DebuggerHidden]
95+
get { return this.Assembly?.Process; }
96+
}
97+
98+
public CorDebugAppDomain AppDomain
99+
{
100+
[System.Diagnostics.DebuggerHidden]
101+
get
102+
{
103+
if (m_appDomain != null)
104+
{
105+
return m_appDomain;
106+
}
107+
else
108+
{
109+
return this.Assembly?.AppDomain;
110+
}
111+
}
112+
}
113+
114+
// This is used to resolve values into types when we know the appdomain, but not the assembly.
80115
public CorDebugGenericType(CorElementType elemType, RuntimeValue rtv, CorDebugAppDomain appDomain)
81-
{
116+
{
82117
m_elemType = elemType;
83118
m_rtv = rtv;
84-
m_appDomain = appDomain;
119+
m_appDomain = appDomain;
120+
}
121+
122+
// This constructor is used exclusively for resolving potentially (but never really) generic classes into fully specified types.
123+
// Generics are not supported (yet) but we still need to be able to convert classes into fully specified types.
124+
public CorDebugGenericType(CorElementType elemType, RuntimeValue rtv, CorDebugAssembly assembly)
125+
{
126+
m_elemType = elemType;
127+
m_rtv = rtv;
128+
Assembly = assembly;
85129
}
86130

87131
int ICorDebugType.EnumerateTypeParameters(out ICorDebugTypeEnum ppTyParEnum)
@@ -106,7 +150,7 @@ int ICorDebugType.GetRank(out uint pnRank)
106150

107151
int ICorDebugType.GetClass(out ICorDebugClass ppClass)
108152
{
109-
ppClass = CorDebugValue.ClassFromRuntimeValue(m_rtv, m_appDomain);
153+
ppClass = CorDebugValue.ClassFromRuntimeValue(m_rtv, AppDomain);
110154
return COM_HResults.S_OK;
111155
}
112156

@@ -119,8 +163,13 @@ int ICorDebugType.GetFirstTypeParameter(out ICorDebugType value)
119163

120164
int ICorDebugType.GetStaticFieldValue(uint fieldDef, ICorDebugFrame pFrame, out ICorDebugValue ppValue)
121165
{
122-
ppValue = null;
123-
return COM_HResults.E_NOTIMPL;
166+
uint fd = nanoCLR_TypeSystem.ClassMemberIndexFromCLRToken(fieldDef, this.Assembly);
167+
168+
this.Process.SetCurrentAppDomain(this.AppDomain);
169+
RuntimeValue rtv = this.Engine.GetStaticFieldValue(fd);
170+
ppValue = CorDebugValue.CreateValue(rtv, this.AppDomain);
171+
172+
return COM_HResults.S_OK;
124173
}
125174

126175
int ICorDebugType.GetBase(out ICorDebugType pBase)

0 commit comments

Comments
 (0)