Skip to content

Commit 2c8a1de

Browse files
committed
CorDebug: reading of string, float, double and bool constants from metadata.
(cherry picked from commit 97c1a6a)
1 parent ce4d48e commit 2c8a1de

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

CorApi2/Metadata/MetadataFieldInfo.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ out pcchValue
6464
FieldAttributes staticLiteralField = FieldAttributes.Static | FieldAttributes.HasDefault | FieldAttributes.Literal;
6565
if ((m_fieldAttributes & staticLiteralField) == staticLiteralField)
6666
{
67-
m_value = ParseDefaultValue(declaringType,ppvSigBlob,ppvRawValue);
67+
m_value = ParseDefaultValue(declaringType,ppvSigBlob,ppvRawValue, pcchValue);
6868
}
6969
// [Xamarin] Expression evaluator.
7070
MetadataHelperFunctionsExtensions.GetCustomAttribute (m_importer, m_fieldToken, typeof (DebuggerBrowsableAttribute));
7171
}
7272

73-
private static object ParseDefaultValue(MetadataType declaringType, IntPtr ppvSigBlob, IntPtr ppvRawValue)
73+
private static object ParseDefaultValue(MetadataType declaringType, IntPtr ppvSigBlob, IntPtr ppvRawValue, int rawValueSize)
7474
{
7575
IntPtr ppvSigTemp = ppvSigBlob;
7676
CorCallingConvention callingConv = MetadataHelperFunctions.CorSigUncompressCallingConv(ref ppvSigTemp);
@@ -94,7 +94,7 @@ private static object ParseDefaultValue(MetadataType declaringType, IntPtr ppvSi
9494
}
9595
}
9696
}
97-
97+
9898
switch (elementType)
9999
{
100100
case CorElementType.ELEMENT_TYPE_CHAR:
@@ -117,10 +117,21 @@ private static object ParseDefaultValue(MetadataType declaringType, IntPtr ppvSi
117117
return (ulong)Marshal.ReadInt64(ppvRawValue);
118118
case CorElementType.ELEMENT_TYPE_I:
119119
return Marshal.ReadIntPtr(ppvRawValue);
120-
case CorElementType.ELEMENT_TYPE_U:
120+
case CorElementType.ELEMENT_TYPE_STRING:
121+
return Marshal.PtrToStringAuto (ppvRawValue, rawValueSize);
121122
case CorElementType.ELEMENT_TYPE_R4:
123+
unsafe {
124+
return *(float*) ppvRawValue.ToPointer ();
125+
}
122126
case CorElementType.ELEMENT_TYPE_R8:
123-
// Technically U and the floating-point ones are options in the CLI, but not in the CLS or C#, so these are NYI
127+
unsafe {
128+
return *(double*) ppvRawValue.ToPointer ();
129+
}
130+
case CorElementType.ELEMENT_TYPE_BOOLEAN:
131+
unsafe {
132+
return *(bool*) ppvRawValue.ToPointer ();
133+
}
134+
124135
default:
125136
return null;
126137
}

0 commit comments

Comments
 (0)