-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Implement cDAC-backed DacDbi GetObjectForCCW and IsRcw + dump integration coverage
#126963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3d345df
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/3366f85c-8…
Copilot 80e52d1
Update DacDbiComWrappersDumpTests.cs
rcj1 7258f1a
copilot comments
rcj1 c82b05e
Rename method GetObjectFromCCW to GetObjectHandle
rcj1 acb652f
Update DacDbiImpl.cs
rcj1 f66279f
Fix two unresolved dump test review comments
Copilot 753b7dc
Merge remote-tracking branch 'rachel' into copilot/implement-dacdbi-g…
rcj1 54275e7
use trygetcontract
rcj1 2478f61
fix test
rcj1 a5f163c
Merge branch 'main' into copilot/implement-dacdbi-getobjectforccw-isrcw
rcj1 0f39605
code review
rcj1 e27006e
Update pointer reading method in ComWrappers_1.cs
rcj1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiCCWDumpTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using Microsoft.Diagnostics.DataContractReader.Contracts; | ||
| using Microsoft.Diagnostics.DataContractReader.Legacy; | ||
| using Microsoft.DotNet.XUnitExtensions; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.Diagnostics.DataContractReader.DumpTests; | ||
|
|
||
| /// <summary> | ||
| /// Dump-based integration tests for DacDbiImpl.GetObjectForCCW. | ||
| /// Uses the CCW debuggee (full dump). | ||
| /// </summary> | ||
| public class DacDbiCCWDumpTests : DumpTestBase | ||
| { | ||
| protected override string DebuggeeName => "CCW"; | ||
| protected override string DumpType => "full"; | ||
|
|
||
| private DacDbiImpl CreateDacDbi() => new DacDbiImpl(Target, legacyObj: null); | ||
|
|
||
| private (TargetPointer Ccw, TargetPointer InterfacePointer) FindBuiltInComCcwWithInterface() | ||
| { | ||
| IGC gc = Target.Contracts.GC; | ||
| IObject obj = Target.Contracts.Object; | ||
| IBuiltInCOM builtInCOM = Target.Contracts.BuiltInCOM; | ||
|
|
||
| foreach (HandleData handleData in gc.GetHandles([HandleType.Strong])) | ||
| { | ||
| TargetPointer objectAddress = Target.ReadPointer(handleData.Handle); | ||
| if (objectAddress == TargetPointer.Null) | ||
| continue; | ||
|
|
||
| if (!obj.GetBuiltInComData(objectAddress, out _, out TargetPointer ccw, out _) | ||
| || ccw == TargetPointer.Null) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| // Normalize to the start wrapper, matching what DacDbiImpl.GetObjectForCCW does | ||
| // before calling GetObjectHandle, so the expected handle in the test is consistent. | ||
| TargetPointer startCcw = builtInCOM.GetStartWrapper(ccw); | ||
|
|
||
| List<COMInterfacePointerData> interfaces = builtInCOM.GetCCWInterfaces(startCcw).ToList(); | ||
| if (interfaces.Count == 0) | ||
| continue; | ||
|
|
||
| return (startCcw, interfaces[0].InterfacePointerAddress); | ||
| } | ||
|
|
||
| throw new SkipTestException("No BuiltInCOM CCW interface pointer found in dump."); | ||
| } | ||
|
|
||
| [ConditionalTheory] | ||
| [MemberData(nameof(TestConfigurations))] | ||
| [SkipOnOS(IncludeOnly = "windows", Reason = "COM callable wrappers require Windows")] | ||
| public unsafe void GetObjectForCCW_ReturnsBuiltInComObjectHandle(TestConfiguration config) | ||
| { | ||
| InitializeDumpTest(config); | ||
| DacDbiImpl dbi = CreateDacDbi(); | ||
| IBuiltInCOM builtInCOM = Target.Contracts.BuiltInCOM; | ||
|
|
||
| (TargetPointer ccw, TargetPointer interfacePointer) = FindBuiltInComCcwWithInterface(); | ||
|
|
||
| ulong resultHandle; | ||
| int hr = dbi.GetObjectForCCW(interfacePointer.Value, &resultHandle); | ||
|
|
||
| Assert.Equal(System.HResults.S_OK, hr); | ||
| Assert.Equal(builtInCOM.GetObjectHandle(ccw).Value, resultHandle); | ||
| Assert.NotEqual(TargetPointer.Null, Target.ReadPointer(new TargetPointer(resultHandle))); | ||
|
rcj1 marked this conversation as resolved.
|
||
| } | ||
| } | ||
64 changes: 64 additions & 0 deletions
64
src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiComWrappersDumpTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Collections.Generic; | ||
| using Microsoft.Diagnostics.DataContractReader.Contracts; | ||
| using Microsoft.Diagnostics.DataContractReader.Legacy; | ||
| using Microsoft.DotNet.XUnitExtensions; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.Diagnostics.DataContractReader.DumpTests; | ||
|
|
||
| /// <summary> | ||
| /// Dump-based integration tests for DacDbiImpl.GetObjectForCCW via the ComWrappers path. | ||
| /// Uses the ComWrappers debuggee (full dump). | ||
| /// </summary> | ||
| public class DacDbiComWrappersDumpTests : DumpTestBase | ||
| { | ||
| protected override string DebuggeeName => "ComWrappers"; | ||
| protected override string DumpType => "full"; | ||
|
|
||
| private DacDbiImpl CreateDacDbi() => new DacDbiImpl(Target, legacyObj: null); | ||
|
|
||
| [ConditionalTheory] | ||
| [MemberData(nameof(TestConfigurations))] | ||
| [SkipOnVersion("net10.0", "ComWrappers cDAC support not available in .NET 10")] | ||
| public unsafe void GetObjectForCCW_ComWrappersIdentityPointer_ReturnsManagedObjectWrapperHandle(TestConfiguration config) | ||
| { | ||
| InitializeDumpTest(config); | ||
| DacDbiImpl dbi = CreateDacDbi(); | ||
| IGC gc = Target.Contracts.GC; | ||
| IComWrappers comWrappers = Target.Contracts.ComWrappers; | ||
|
|
||
| foreach (HandleData handleData in gc.GetHandles([HandleType.Strong])) | ||
| { | ||
| TargetPointer objectAddress = Target.ReadPointer(handleData.Handle); | ||
| if (objectAddress == TargetPointer.Null) | ||
| continue; | ||
|
|
||
| List<TargetPointer> mows = comWrappers.GetMOWs(objectAddress, out bool hasMowTable); | ||
| if (!hasMowTable || mows.Count == 0) | ||
| continue; | ||
|
|
||
| TargetPointer mow = mows[0]; | ||
| TargetPointer identity = comWrappers.GetIdentityForMOW(mow); | ||
| if (identity == TargetPointer.Null) | ||
| continue; | ||
|
|
||
| ulong expectedHandle = Target.ReadPointer(mow).Value; | ||
| ulong actualHandle; | ||
| int hr = dbi.GetObjectForCCW(identity.Value, &actualHandle); | ||
|
|
||
| Assert.Equal(System.HResults.S_OK, hr); | ||
| Assert.Equal(expectedHandle, actualHandle); | ||
|
rcj1 marked this conversation as resolved.
|
||
|
|
||
| // Verify the returned handle dereferences to a live object in the dump. | ||
| TargetPointer actualHandleTarget = new(actualHandle); | ||
| TargetPointer actualObjectAddress = Target.ReadPointer(actualHandleTarget); | ||
| Assert.NotEqual(TargetPointer.Null, actualObjectAddress); | ||
| return; | ||
| } | ||
|
|
||
| throw new SkipTestException("No ComWrappers MOW/CCW identity found in dump."); | ||
| } | ||
| } | ||
80 changes: 80 additions & 0 deletions
80
src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiRCWDumpTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Microsoft.Diagnostics.DataContractReader.Contracts; | ||
| using Microsoft.Diagnostics.DataContractReader.Legacy; | ||
| using Microsoft.DotNet.XUnitExtensions; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.Diagnostics.DataContractReader.DumpTests; | ||
|
|
||
| /// <summary> | ||
| /// Dump-based integration tests for DacDbiImpl.IsRcw. | ||
| /// Uses the RCW debuggee (full dump). | ||
| /// </summary> | ||
| public class DacDbiRCWDumpTests : DumpTestBase | ||
| { | ||
| protected override string DebuggeeName => "RCW"; | ||
| protected override string DumpType => "full"; | ||
|
|
||
| private DacDbiImpl CreateDacDbi() => new DacDbiImpl(Target, legacyObj: null); | ||
|
|
||
| [ConditionalTheory] | ||
| [MemberData(nameof(TestConfigurations))] | ||
| [SkipOnOS(IncludeOnly = "windows", Reason = "COM interop (RCW) is only supported on Windows")] | ||
| public unsafe void IsRcw_ReturnsTrueForBuiltInRcwObject(TestConfiguration config) | ||
| { | ||
| InitializeDumpTest(config); | ||
| DacDbiImpl dbi = CreateDacDbi(); | ||
| IGC gc = Target.Contracts.GC; | ||
| IObject obj = Target.Contracts.Object; | ||
|
|
||
| foreach (HandleData handleData in gc.GetHandles([HandleType.Strong])) | ||
| { | ||
| TargetPointer objectAddress = Target.ReadPointer(handleData.Handle); | ||
| if (objectAddress == TargetPointer.Null) | ||
| continue; | ||
|
|
||
| if (!obj.GetBuiltInComData(objectAddress, out TargetPointer rcw, out _, out _) || rcw == TargetPointer.Null) | ||
| continue; | ||
|
|
||
| Interop.BOOL result; | ||
| int hr = dbi.IsRcw(objectAddress.Value, &result); | ||
| Assert.Equal(System.HResults.S_OK, hr); | ||
| Assert.Equal(Interop.BOOL.TRUE, result); | ||
|
rcj1 marked this conversation as resolved.
|
||
| return; | ||
| } | ||
|
|
||
| throw new SkipTestException("No built-in RCW object found in dump."); | ||
| } | ||
|
|
||
| [ConditionalTheory] | ||
| [MemberData(nameof(TestConfigurations))] | ||
| [SkipOnOS(IncludeOnly = "windows", Reason = "COM interop (RCW) is only supported on Windows")] | ||
| public unsafe void IsRcw_ReturnsFalseForNonRcwObject(TestConfiguration config) | ||
| { | ||
| InitializeDumpTest(config); | ||
| DacDbiImpl dbi = CreateDacDbi(); | ||
| IGC gc = Target.Contracts.GC; | ||
| IObject obj = Target.Contracts.Object; | ||
|
|
||
| foreach (HandleData handleData in gc.GetHandles([HandleType.Strong])) | ||
| { | ||
| TargetPointer objectAddress = Target.ReadPointer(handleData.Handle); | ||
| if (objectAddress == TargetPointer.Null) | ||
| continue; | ||
|
|
||
| _ = obj.GetBuiltInComData(objectAddress, out TargetPointer rcw, out _, out _); | ||
| if (rcw != TargetPointer.Null) | ||
| continue; | ||
|
|
||
| Interop.BOOL result; | ||
| int hr = dbi.IsRcw(objectAddress.Value, &result); | ||
| Assert.Equal(System.HResults.S_OK, hr); | ||
| Assert.Equal(Interop.BOOL.FALSE, result); | ||
| return; | ||
| } | ||
|
|
||
| throw new SkipTestException("No non-RCW object found in dump."); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.