Skip to content

Commit 01e5fa1

Browse files
authored
[cDAC] Fix issues found when running full SOS test suite (#115432)
* #114800 broke ISOSDacInterface::GetModuleData as it enforced only sending values defined in the cDAC. Adds all used flags to cDAC. * ISOSDacInterface::GetFrameName now works on all Frame names * ISOSDacInterface::GetFrameName properly returns the number of characters needed following quirks of DAC implementation * IXCLRDataModule::GetFlags now uses the correct enum value * ISOSDacInterface::GetAssemblyList follows quirks of DAC interface exactly
1 parent be4dd91 commit 01e5fa1

File tree

7 files changed

+98
-14
lines changed

7 files changed

+98
-14
lines changed

eng/pipelines/runtime-diagnostics.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extends:
4141
platforms:
4242
- windows_x64
4343
jobParameters:
44-
buildArgs: -s clr+libs+tools.cdac+host+packs -c $(_BuildConfig)
44+
buildArgs: -s clr+libs+tools.cdac+host+packs -c Debug -rc $(_BuildConfig) -lc $(_BuildConfig)
4545
nameSuffix: AllSubsets_CoreCLR
4646
isOfficialBuild: ${{ variables.isOfficialBuild }}
4747
timeoutInMinutes: 360

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/ILoader.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,26 @@ public ModuleHandle(TargetPointer address)
1919
[Flags]
2020
public enum ModuleFlags
2121
{
22-
Tenured = 0x00000001, // Set once we know for sure the Module will not be freed until the appdomain itself exits
23-
EditAndContinue = 0x00000008, // Edit and Continue is enabled for this module
24-
ReflectionEmit = 0x00000040, // Reflection.Emit was used to create this module
22+
Tenured = 0x1, // Set once we know for sure the Module will not be freed until the appdomain itself exits
23+
ClassFreed = 0x4,
24+
EditAndContinue = 0x8, // Edit and Continue is enabled for this module
25+
26+
ProfilerNotified = 0x10,
27+
EtwNotified = 0x20,
28+
29+
ReflectionEmit = 0x40, // Reflection.Emit was used to create this module
30+
ProfilerDisableOptimizations = 0x80,
31+
ProfilerDisableInlining = 0x100,
32+
33+
DebuggerUserOverridePriv = 0x400,
34+
DebuggerAllowJitOptsPriv = 0x800,
35+
DebuggerTrackJitInfoPriv = 0x1000,
36+
DebuggerEnCEnabledPriv = 0x2000,
37+
DebuggerPDBsCopied = 0x4000,
38+
DebuggerIgnorePDbs = 0x8000,
39+
40+
IJWFixedUp = 0x80000,
41+
BeingUnloaded = 0x100000,
2542
}
2643

2744
public record struct ModuleLookupTables(

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Loader_1.cs

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,26 @@ namespace Microsoft.Diagnostics.DataContractReader.Contracts;
1414

1515
private enum ModuleFlags_1 : uint
1616
{
17-
Tenured = 0x00000001, // Set once we know for sure the Module will not be freed until the appdomain itself exits
18-
EditAndContinue = 0x00000008, // Edit and Continue is enabled for this module
19-
ReflectionEmit = 0x00000040, // Reflection.Emit was used to create this module
17+
Tenured = 0x1, // Set once we know for sure the Module will not be freed until the appdomain itself exits
18+
ClassFreed = 0x4,
19+
EditAndContinue = 0x8, // Edit and Continue is enabled for this module
20+
21+
ProfilerNotified = 0x10,
22+
EtwNotified = 0x20,
23+
24+
ReflectionEmit = 0x40, // Reflection.Emit was used to create this module
25+
ProfilerDisableOptimizations = 0x80,
26+
ProfilerDisableInlining = 0x100,
27+
28+
DebuggerUserOverridePriv = 0x400,
29+
DebuggerAllowJitOptsPriv = 0x800,
30+
DebuggerTrackJitInfoPriv = 0x1000,
31+
DebuggerEnCEnabledPriv = 0x2000,
32+
DebuggerPDBsCopied = 0x4000,
33+
DebuggerIgnorePDbs = 0x8000,
34+
35+
IJWFixedUp = 0x80000,
36+
BeingUnloaded = 0x100000,
2037
}
2138

2239
private readonly Target _target;
@@ -196,10 +213,37 @@ private static ModuleFlags GetFlags(Data.Module module)
196213
ModuleFlags flags = default;
197214
if (runtimeFlags.HasFlag(ModuleFlags_1.Tenured))
198215
flags |= ModuleFlags.Tenured;
216+
if (runtimeFlags.HasFlag(ModuleFlags_1.ClassFreed))
217+
flags |= ModuleFlags.ClassFreed;
199218
if (runtimeFlags.HasFlag(ModuleFlags_1.EditAndContinue))
200219
flags |= ModuleFlags.EditAndContinue;
220+
if (runtimeFlags.HasFlag(ModuleFlags_1.ProfilerNotified))
221+
flags |= ModuleFlags.ProfilerNotified;
222+
if (runtimeFlags.HasFlag(ModuleFlags_1.EtwNotified))
223+
flags |= ModuleFlags.EtwNotified;
201224
if (runtimeFlags.HasFlag(ModuleFlags_1.ReflectionEmit))
202225
flags |= ModuleFlags.ReflectionEmit;
226+
if (runtimeFlags.HasFlag(ModuleFlags_1.ProfilerDisableOptimizations))
227+
flags |= ModuleFlags.ProfilerDisableOptimizations;
228+
if (runtimeFlags.HasFlag(ModuleFlags_1.ProfilerDisableInlining))
229+
flags |= ModuleFlags.ProfilerDisableInlining;
230+
if (runtimeFlags.HasFlag(ModuleFlags_1.DebuggerUserOverridePriv))
231+
flags |= ModuleFlags.DebuggerUserOverridePriv;
232+
if (runtimeFlags.HasFlag(ModuleFlags_1.DebuggerAllowJitOptsPriv))
233+
flags |= ModuleFlags.DebuggerAllowJitOptsPriv;
234+
if (runtimeFlags.HasFlag(ModuleFlags_1.DebuggerTrackJitInfoPriv))
235+
flags |= ModuleFlags.DebuggerTrackJitInfoPriv;
236+
if (runtimeFlags.HasFlag(ModuleFlags_1.DebuggerEnCEnabledPriv))
237+
flags |= ModuleFlags.DebuggerEnCEnabledPriv;
238+
if (runtimeFlags.HasFlag(ModuleFlags_1.DebuggerPDBsCopied))
239+
flags |= ModuleFlags.DebuggerPDBsCopied;
240+
if (runtimeFlags.HasFlag(ModuleFlags_1.DebuggerIgnorePDbs))
241+
flags |= ModuleFlags.DebuggerIgnorePDbs;
242+
if (runtimeFlags.HasFlag(ModuleFlags_1.IJWFixedUp))
243+
flags |= ModuleFlags.IJWFixedUp;
244+
if (runtimeFlags.HasFlag(ModuleFlags_1.BeingUnloaded))
245+
flags |= ModuleFlags.BeingUnloaded;
246+
203247
return flags;
204248
}
205249

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/FrameHandling/FrameIterator.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,23 @@ private enum FrameType
3333
FaultingExceptionFrame,
3434

3535
HijackFrame,
36+
37+
/* Other Frame Types not handled by the iterator */
38+
HelperMethodFrame,
39+
HelperMethodFrame_1OBJ,
40+
HelperMethodFrame_2OBJ,
41+
HelperMethodFrame_3OBJ,
42+
HelperMethodFrame_PROTECTOBJ,
43+
UnmanagedToManagedFrame,
44+
ComMethodFrame,
45+
ComPrestubMethodFrame,
46+
TailCallFrame,
47+
ProtectByRefsFrame,
48+
ProtectValueClassFrame,
49+
DebuggerClassInitMarkFrame,
50+
DebuggerExitFrame,
51+
DebuggerU2MCatchHandlerFrame,
52+
ExceptionFilterFrame,
3653
}
3754

3855
private readonly Target target;

src/native/managed/cdac/mscordaccore_universal/Legacy/ClrDataModule.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,13 @@ int IXCLRDataModule.GetFlags(uint* flags)
183183
Contracts.ModuleHandle handle = contract.GetModuleHandle(_address);
184184

185185
ModuleFlags moduleFlags = contract.GetFlags(handle);
186-
if ((moduleFlags & ModuleFlags.EditAndContinue) != 0)
186+
if ((moduleFlags & ModuleFlags.ReflectionEmit) != 0)
187187
{
188188
*flags |= 0x1; // CLRDATA_MODULE_IS_DYNAMIC
189189
}
190190

191191
if (contract.GetAssembly(handle) == contract.GetRootAssembly())
192192
{
193-
194193
*flags |= 0x4; // CLRDATA_MODULE_FLAGS_ROOT_ASSEMBLY
195194
}
196195
}

src/native/managed/cdac/mscordaccore_universal/Legacy/ISOSDacInterface.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ internal unsafe partial interface ISOSDacInterface
202202

203203
// Assemblies
204204
[PreserveSig]
205-
int GetAssemblyList(ulong appDomain, int count, [In, Out, MarshalUsing(CountElementName = nameof(count))] ulong[] values, int* pNeeded);
205+
int GetAssemblyList(ulong appDomain, int count, [In, Out, MarshalUsing(CountElementName = nameof(count))] ulong[]? values, int* pNeeded);
206206
[PreserveSig]
207207
int GetAssemblyData(ulong baseDomainPtr, ulong assembly, /*struct DacpAssemblyData*/ void* data);
208208
[PreserveSig]

src/native/managed/cdac/mscordaccore_universal/Legacy/SOSDacImpl.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ int ISOSDacInterface.GetApplicationBase(ulong appDomain, int count, char* appBas
132132
}
133133
int ISOSDacInterface.GetAssemblyData(ulong baseDomainPtr, ulong assembly, void* data)
134134
=> _legacyImpl is not null ? _legacyImpl.GetAssemblyData(baseDomainPtr, assembly, data) : HResults.E_NOTIMPL;
135-
int ISOSDacInterface.GetAssemblyList(ulong appDomain, int count, [In, MarshalUsing(CountElementName = "count"), Out] ulong[] values, int* pNeeded)
135+
int ISOSDacInterface.GetAssemblyList(ulong appDomain, int count, [In, MarshalUsing(CountElementName = "count"), Out] ulong[]? values, int* pNeeded)
136136
{
137137
if (appDomain == 0)
138138
{
@@ -173,7 +173,7 @@ int ISOSDacInterface.GetAssemblyList(ulong appDomain, int count, [In, MarshalUsi
173173
}
174174
else
175175
{
176-
for (int i = 0; i < modules.Count && n < count; i++)
176+
for (int i = 0; i < modules.Count; i++)
177177
{
178178
Contracts.ModuleHandle module = modules[i];
179179
if (loader.IsAssemblyLoaded(module))
@@ -197,7 +197,7 @@ int ISOSDacInterface.GetAssemblyList(ulong appDomain, int count, [In, MarshalUsi
197197
#if DEBUG
198198
if (_legacyImpl is not null)
199199
{
200-
ulong[] valuesLocal = new ulong[count];
200+
ulong[]? valuesLocal = values != null ? new ulong[count] : null;
201201
int neededLocal;
202202
int hrLocal = _legacyImpl.GetAssemblyList(appDomain, count, valuesLocal, &neededLocal);
203203
Debug.Assert(hrLocal == hr, $"cDAC: {hr:x}, DAC: {hrLocal:x}");
@@ -210,7 +210,7 @@ int ISOSDacInterface.GetAssemblyList(ulong appDomain, int count, [In, MarshalUsi
210210
// easiest for consumers and verification if the DAC and cDAC return the same order
211211
for (int i = 0; i < neededLocal; i++)
212212
{
213-
Debug.Assert(values[i] == valuesLocal[i], $"cDAC: {values[i]:x}, DAC: {valuesLocal[i]:x}");
213+
Debug.Assert(values[i] == valuesLocal![i], $"cDAC: {values[i]:x}, DAC: {valuesLocal[i]:x}");
214214
}
215215
}
216216
}
@@ -315,6 +315,13 @@ int ISOSDacInterface.GetFrameName(ulong vtable, uint count, char* frameName, uin
315315
else
316316
{
317317
OutputBufferHelpers.CopyStringToBuffer(frameName, count, pNeeded, name);
318+
319+
if (frameName is not null && pNeeded is not null)
320+
{
321+
// the DAC version of this API does not count the trailing null terminator
322+
// if a buffer is provided
323+
(*pNeeded)--;
324+
}
318325
}
319326
}
320327
catch (System.Exception ex)

0 commit comments

Comments
 (0)