未验证 提交 f34e1ca3 编写于 作者: J Julien Couvreur 提交者: GitHub

Emit DebuggerStepThrough attribute on async Main stub (#34531)

上级 4ee95ab9
......@@ -5,7 +5,9 @@
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using Microsoft.CodeAnalysis.CSharp.Emit;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.PooledObjects;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.CSharp.Symbols
......@@ -345,6 +347,13 @@ internal sealed class AsyncForwardEntryPoint : SynthesizedEntryPointSymbol
ReturnType.SpecialType == SpecialType.System_Int32);
}
internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<SynthesizedAttributeData> attributes)
{
base.AddSynthesizedAttributes(moduleBuilder, ref attributes);
AddSynthesizedAttribute(ref attributes, this.DeclaringCompilation.SynthesizeDebuggerStepThroughAttribute());
}
public override string Name => MainName;
public override ImmutableArray<ParameterSymbol> Parameters => _parameters;
......
......@@ -4,6 +4,11 @@
using Xunit;
using System.Threading;
using Microsoft.CodeAnalysis.Test.Utilities;
using System.Reflection.PortableExecutable;
using System.Reflection.Metadata;
using System.Linq;
using Roslyn.Test.Utilities;
using System.Collections.Generic;
namespace Microsoft.CodeAnalysis.CSharp.UnitTests.CodeGen
{
......@@ -707,7 +712,21 @@ async static Task Main()
var entry = compilation.GetEntryPoint(CancellationToken.None);
Assert.NotNull(entry);
Assert.Equal("System.Threading.Tasks.Task A.Main()", entry.ToTestDisplayString());
var image = compilation.EmitToArray();
using var reader = new PEReader(image);
var metadataReader = reader.GetMetadataReader();
var main = metadataReader.MethodDefinitions.Where(mh => getMethodName(mh) == "<Main>").Single();
Assert.Equal(new[] { "MemberReference:Void System.Diagnostics.DebuggerStepThroughAttribute..ctor()" }, getMethodAttributes(main));
string getMethodName(MethodDefinitionHandle handle)
=> metadataReader.GetString(metadataReader.GetMethodDefinition(handle).Name);
IEnumerable<string> getMethodAttributes(MethodDefinitionHandle handle)
=> metadataReader.GetMethodDefinition(handle).GetCustomAttributes()
.Select(a => metadataReader.Dump(metadataReader.GetCustomAttribute(a).Constructor));
}
[Fact]
public void MainCanReturnTask_NoAsync()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册