Skip to content
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

ResultProvider: Consume DkmClrModuleInstance.GetMetaDataImportHolder #76395

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions eng/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@
VS Debugger
-->
<PackageVersion Include="Microsoft.VisualStudio.Debugger.Contracts" Version="17.13.0-beta.24561.1" />
<PackageVersion Include="Microsoft.VisualStudio.Debugger.Engine-implementation" Version="17.13.1110101-preview" />
<PackageVersion Include="Microsoft.VisualStudio.Debugger.Metadata-implementation" Version="17.13.1110101-preview" />
<PackageVersion Include="Microsoft.VisualStudio.Debugger.Engine-implementation" Version="17.13.1121201-preview" />
<PackageVersion Include="Microsoft.VisualStudio.Debugger.Metadata-implementation" Version="17.13.1121201-preview" />

<!--
VS .NET Runtime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,18 @@ string IDkmClrFullNameProvider2.GetClrNameForLocalVariable(DkmInspectionContext

string IDkmClrFullNameProvider2.GetClrNameForField(DkmInspectionContext inspectionContext, DkmClrModuleInstance moduleInstance, int fieldToken)
{
var import = (IMetadataImport)moduleInstance.GetMetaDataImport();
using var importHolder = moduleInstance.GetMetaDataImportHolder();

// Just get some of information about properties. Get rest later only if needed.
int hr = import.GetFieldProps(fieldToken, out _, null, 0, out var nameLength, out _, out _, out _, out _, out _, out _);
int hr = importHolder.Value.GetFieldProps(fieldToken, out _, null, 0, out var nameLength, out _, out _, out _, out _, out _, out _);
const int S_OK = 0;
if (hr != S_OK)
{
throw new ArgumentException("Invalid field token.", nameof(fieldToken));
}

var sb = new StringBuilder(nameLength);
hr = import.GetFieldProps(fieldToken, out _, sb, sb.Capacity, out _, out _, out _, out _, out _, out _, out _);
hr = importHolder.Value.GetFieldProps(fieldToken, out _, sb, sb.Capacity, out _, out _, out _, out _, out _, out _, out _);
if (hr != S_OK)
{
throw new DkmException((DkmExceptionCode)hr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ internal int ResolveTypeNameFailures
get { return _resolveTypeNameFailures; }
}

public object GetMetaDataImport() => new MetadataImportMock(Assembly);
public DkmMetadataImportHolder GetMetaDataImportHolder() => new DkmMetadataImportHolder(new MetadataImportMock(Assembly));

private class MetadataImportMock : IMetadataImport
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using Microsoft.MetadataReader;

#nullable enable

namespace Microsoft.VisualStudio.Debugger.Clr
{
/// <summary>
/// Wrapper around a <see cref="Microsoft.MetadataReader.IMetadataImport"/> interface
/// reference that provides a easy way to release the reference to the underlying
/// COM object. Instances of this struct should always be disposed.
/// </summary>
public readonly struct DkmMetadataImportHolder : IDisposable
{
/// <summary>
/// The underlying IMetaDataImport interface reference
/// </summary>
public IMetadataImport Value { get; }

/// <summary>
/// Creates a new instance of <see cref="DkmMetadataImportHolder"/>.
/// </summary>
/// <param name="value">[In] Implementation of IMetadataImport to wrap</param>
public DkmMetadataImportHolder(IMetadataImport value)
{
this.Value = value ?? throw new ArgumentNullException(nameof(value));
}

void IDisposable.Dispose()
{
// Mock implementation does nothing
}
}
}