Skip to content

Commit

Permalink
Merge branch 'icsharpcode:master' into MoreCustomDebugInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
fowl2 authored Jan 5, 2023
2 parents 24a9294 + e286496 commit 93bf1a2
Show file tree
Hide file tree
Showing 148 changed files with 3,738 additions and 795 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-ilspy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
fetch-depth: 0

- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.1
uses: microsoft/setup-msbuild@v1.3

- name: Install dotnet-format
run: dotnet tool install -g dotnet-format --version "6.2.315104" --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json
Expand All @@ -37,7 +37,7 @@ jobs:
shell: pwsh
run: |
.\BuildTools\ghactions-install.ps1
Get-ChildItem Env: | Where-Object {$_.Name -Match "^ILSPY_"} | %{ echo "::set-output name=$($_.Name)::$($_.Value)" }
Get-ChildItem Env: | Where-Object {$_.Name -Match "^ILSPY_"} | %{ echo "$($_.Name)=$($_.Value)" } | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
- name: Restore the application
run: msbuild ILSpy.sln /t:Restore /p:Configuration=${{ matrix.configuration }} /p:Platform=$env:BuildPlatform
Expand All @@ -60,7 +60,7 @@ jobs:
path: 'test-results/${{ matrix.configuration }}.xml'

- name: Create Test Report
uses: test-summary/action@v1
uses: test-summary/action@v2
if: always()
with:
paths: "test-results/${{ matrix.configuration }}.xml"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
lock:
runs-on: ubuntu-latest
steps:
- uses: dessant/lock-threads@v3.0.0
- uses: dessant/lock-threads@v4.0.0
with:
github-token: ${{ github.token }}
issue-inactive-days: '90'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public void Report(DecompilationProgress value)
lock (syncObject)
{
completed++;
progress = new ProgressRecord(1, "Decompiling " + fileName, $"Completed {completed} of {value.TotalNumberOfFiles}: {value.Status}") {
PercentComplete = (int)(completed * 100.0 / value.TotalNumberOfFiles)
progress = new ProgressRecord(1, "Decompiling " + fileName, $"Completed {completed} of {value.TotalUnits}: {value.Status}") {
PercentComplete = (int)(completed * 100.0 / value.TotalUnits)
};
}
}
Expand Down
6 changes: 1 addition & 5 deletions ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
Expand Down Expand Up @@ -398,10 +398,6 @@ public async Task DynamicTests([ValueSource(nameof(noMonoOptions))] CompilerOpti
[Test]
public async Task MiniJSON([ValueSource(nameof(defaultOptions))] CompilerOptions options)
{
if (options.HasFlag(CompilerOptions.UseMcs2_6_4))
{
Assert.Ignore("Decompiler bug with mono!");
}
await RunCS(options: options);
}

Expand Down
17 changes: 12 additions & 5 deletions ICSharpCode.Decompiler.Tests/DisassemblerPrettyTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,22 @@ public async Task SecurityDeclarations()
await Run();
}

async Task Run([CallerMemberName] string testName = null)
[Test]
public async Task SortMembers()
{
await Run(ilExpectedFile: Path.Combine(TestCasePath, "SortMembers.expected.il"), asmOptions: AssemblerOptions.SortedOutput);
}

async Task Run([CallerMemberName] string testName = null, string ilExpectedFile = null, AssemblerOptions asmOptions = AssemblerOptions.None)
{
var ilExpectedFile = Path.Combine(TestCasePath, testName + ".il");
var ilInputFile = Path.Combine(TestCasePath, testName + ".il");
ilExpectedFile ??= ilInputFile;
var ilResultFile = Path.Combine(TestCasePath, testName + ".result.il");

var executable = await Tester.AssembleIL(ilExpectedFile, AssemblerOptions.Library).ConfigureAwait(false);
var disassembled = await Tester.Disassemble(executable, ilResultFile, AssemblerOptions.UseOwnDisassembler).ConfigureAwait(false);
var executable = await Tester.AssembleIL(ilInputFile, AssemblerOptions.Library).ConfigureAwait(false);
var disassembled = await Tester.Disassemble(executable, ilResultFile, AssemblerOptions.UseOwnDisassembler | asmOptions).ConfigureAwait(false);

CodeAssert.FilesAreEqual(ilExpectedFile, ilResultFile);
CodeAssert.FilesAreEqual(ilExpectedFile, disassembled);
}
}
}
31 changes: 1 addition & 30 deletions ICSharpCode.Decompiler.Tests/Helpers/RemoveCompilerAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override void VisitAttribute(CSharp.Syntax.Attribute attribute)
if (section.Attributes.Count == 0)
section.Remove();
}
if (section.AttributeTarget == "module" && type.Identifier == "UnverifiableCode")
if (section.AttributeTarget == "module" && type.Identifier is "UnverifiableCode" or "RefSafetyRules")
{
attribute.Remove();
if (section.Attributes.Count == 0)
Expand All @@ -34,35 +34,6 @@ public void Run(AstNode rootNode, TransformContext context)
}
}

public class RemoveEmbeddedAttributes : DepthFirstAstVisitor, IAstTransform
{
HashSet<string> attributeNames = new HashSet<string>() {
"System.Runtime.CompilerServices.IsReadOnlyAttribute",
"System.Runtime.CompilerServices.IsByRefLikeAttribute",
"System.Runtime.CompilerServices.IsUnmanagedAttribute",
"System.Runtime.CompilerServices.NullableAttribute",
"System.Runtime.CompilerServices.NullableContextAttribute",
"System.Runtime.CompilerServices.NativeIntegerAttribute",
"Microsoft.CodeAnalysis.EmbeddedAttribute",
};

public override void VisitTypeDeclaration(TypeDeclaration typeDeclaration)
{
var typeDefinition = typeDeclaration.GetSymbol() as ITypeDefinition;
if (typeDefinition == null || !attributeNames.Contains(typeDefinition.FullName))
return;
if (typeDeclaration.Parent is NamespaceDeclaration ns && ns.Members.Count == 1)
ns.Remove();
else
typeDeclaration.Remove();
}

public void Run(AstNode rootNode, TransformContext context)
{
rootNode.AcceptVisitor(this);
}
}

public class RemoveNamespaceMy : DepthFirstAstVisitor, IAstTransform
{
public override void VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration)
Expand Down
12 changes: 9 additions & 3 deletions ICSharpCode.Decompiler.Tests/Helpers/Tester.VB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static async Task<CompilerResults> CompileVB(string sourceFileName, Compi
{
references = references.Concat(new[] { "-r:\"Microsoft.VisualBasic.dll\"" });
}
string otherOptions = $"-noconfig " +
string otherOptions = $"-nologo -noconfig " +
"-optioninfer+ -optionexplicit+ " +
$"-langversion:{languageVersion} " +
$"/optimize{(flags.HasFlag(CompilerOptions.Optimize) ? "+ " : "- ")}";
Expand Down Expand Up @@ -122,8 +122,14 @@ public static async Task<CompilerResults> CompileVB(string sourceFileName, Compi

var result = await command.ExecuteBufferedAsync().ConfigureAwait(false);

Console.WriteLine("output: " + result.StandardOutput);
Console.WriteLine("errors: " + result.StandardError);
if (!string.IsNullOrWhiteSpace(result.StandardOutput))
{
Console.WriteLine("output:" + Environment.NewLine + result.StandardOutput);
}
if (!string.IsNullOrWhiteSpace(result.StandardError))
{
Console.WriteLine("errors:" + Environment.NewLine + result.StandardError);
}
Assert.AreEqual(0, result.ExitCode, "vbc failed");

return results;
Expand Down
75 changes: 54 additions & 21 deletions ICSharpCode.Decompiler.Tests/Helpers/Tester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public enum AssemblerOptions
UseOwnDisassembler = 0x8,
/// Work around bug in .NET 5 ilasm (https://github.com/dotnet/runtime/issues/32400)
UseLegacyAssembler = 0x10,
/// UseSortByNameFilter, implies UseOwnDisassembler
SortedOutput = 0x20,
}

public static partial class Tester
Expand Down Expand Up @@ -176,21 +178,27 @@ public static async Task<string> AssembleIL(string sourceFileName, AssemblerOpti
}

var command = Cli.Wrap(ilasmPath)
.WithArguments($"/nologo {otherOptions}/output=\"{outputFile}\" \"{sourceFileName}\"")
.WithArguments($"/quiet {otherOptions}/output=\"{outputFile}\" \"{sourceFileName}\"")
.WithValidation(CommandResultValidation.None);

var result = await command.ExecuteBufferedAsync().ConfigureAwait(false);

Console.WriteLine("output: " + result.StandardOutput);
Console.WriteLine("errors: " + result.StandardError);
if (!string.IsNullOrWhiteSpace(result.StandardOutput))
{
Console.WriteLine("output:" + Environment.NewLine + result.StandardOutput);
}
if (!string.IsNullOrWhiteSpace(result.StandardError))
{
Console.WriteLine("errors:" + Environment.NewLine + result.StandardError);
}
Assert.AreEqual(0, result.ExitCode, "ilasm failed");

return outputFile;
}

public static async Task<string> Disassemble(string sourceFileName, string outputFile, AssemblerOptions asmOptions)
{
if (asmOptions.HasFlag(AssemblerOptions.UseOwnDisassembler))
if (asmOptions.HasFlag(AssemblerOptions.UseOwnDisassembler) || asmOptions.HasFlag(AssemblerOptions.SortedOutput))
{
using (var peFileStream = new FileStream(sourceFileName, FileMode.Open, FileAccess.Read))
using (var peFile = new PEFile(sourceFileName, peFileStream))
Expand All @@ -199,7 +207,11 @@ public static async Task<string> Disassemble(string sourceFileName, string outpu
var metadata = peFile.Metadata;
var output = new PlainTextOutput(writer);
ReflectionDisassembler rd = new ReflectionDisassembler(output, CancellationToken.None);
rd.AssemblyResolver = new UniversalAssemblyResolver(sourceFileName, true, null);
if (asmOptions.HasFlag(AssemblerOptions.SortedOutput))
{
rd.EntityProcessor = new SortByNameProcessor();
}
rd.AssemblyResolver = new UniversalAssemblyResolver(sourceFileName, throwOnError: true, null);
rd.DetectControlStructure = false;
rd.WriteAssemblyReferences(metadata);
if (metadata.IsAssembly)
Expand All @@ -224,8 +236,14 @@ public static async Task<string> Disassemble(string sourceFileName, string outpu

var result = await command.ExecuteBufferedAsync().ConfigureAwait(false);

Console.WriteLine("output: " + result.StandardOutput);
Console.WriteLine("errors: " + result.StandardError);
if (!string.IsNullOrWhiteSpace(result.StandardOutput))
{
Console.WriteLine("output:" + Environment.NewLine + result.StandardOutput);
}
if (!string.IsNullOrWhiteSpace(result.StandardError))
{
Console.WriteLine("errors:" + Environment.NewLine + result.StandardError);
}
Assert.AreEqual(0, result.ExitCode, "ildasm failed");

// Unlike the .imagebase directive (which is a fixed value when compiling with /deterministic),
Expand Down Expand Up @@ -353,10 +371,7 @@ public static List<string> GetPreprocessorSymbols(CompilerOptions flags)
{
preprocessorSymbols.Add("ROSLYN4");
preprocessorSymbols.Add("CS100");
if (flags.HasFlag(CompilerOptions.Preview))
{
preprocessorSymbols.Add("CS110");
}
preprocessorSymbols.Add("CS110");
}
}
else if ((flags & CompilerOptions.UseMcsMask) != 0)
Expand Down Expand Up @@ -430,7 +445,7 @@ public static async Task<CompilerResults> CompileCSharp(string sourceFileName, C
{
references = references.Concat(new[] { "-r:\"System.Runtime.CompilerServices.Unsafe.dll\"" });
}
string otherOptions = $"-noconfig " +
string otherOptions = $"-nologo -noconfig " +
$"-langversion:{languageVersion} " +
$"-unsafe -o{(flags.HasFlag(CompilerOptions.Optimize) ? "+ " : "- ")}";

Expand Down Expand Up @@ -482,12 +497,18 @@ public static async Task<CompilerResults> CompileCSharp(string sourceFileName, C
var command = Cli.Wrap(cscPath)
.WithArguments($"{otherOptions} -lib:{libPath} {string.Join(" ", references)} -out:\"{Path.GetFullPath(results.PathToAssembly)}\" {string.Join(" ", sourceFileNames.Select(fn => '"' + Path.GetFullPath(fn) + '"'))}")
.WithValidation(CommandResultValidation.None);
Console.WriteLine($"\"{command.TargetFilePath}\" {command.Arguments}");
//Console.WriteLine($"\"{command.TargetFilePath}\" {command.Arguments}");

var result = await command.ExecuteBufferedAsync().ConfigureAwait(false);
if (!string.IsNullOrWhiteSpace(result.StandardOutput))
{
Console.WriteLine("output:" + Environment.NewLine + result.StandardOutput);
}
if (!string.IsNullOrWhiteSpace(result.StandardError))
{
Console.WriteLine("errors:" + Environment.NewLine + result.StandardError);
}

Console.WriteLine("output: " + result.StandardOutput);
Console.WriteLine("errors: " + result.StandardError);
Assert.AreEqual(0, result.ExitCode, "csc failed");

return results;
Expand Down Expand Up @@ -538,12 +559,18 @@ public static async Task<CompilerResults> CompileCSharp(string sourceFileName, C
var command = Cli.Wrap(mcsPath)
.WithArguments($"{otherOptions}-out:\"{Path.GetFullPath(results.PathToAssembly)}\" {string.Join(" ", sourceFileNames.Select(fn => '"' + Path.GetFullPath(fn) + '"'))}")
.WithValidation(CommandResultValidation.None);
Console.WriteLine($"\"{command.TargetFilePath}\" {command.Arguments}");
//Console.WriteLine($"\"{command.TargetFilePath}\" {command.Arguments}");

var result = await command.ExecuteBufferedAsync().ConfigureAwait(false);

Console.WriteLine("output: " + result.StandardOutput);
Console.WriteLine("errors: " + result.StandardError);
if (!string.IsNullOrWhiteSpace(result.StandardOutput))
{
Console.WriteLine("output:" + Environment.NewLine + result.StandardOutput);
}
if (!string.IsNullOrWhiteSpace(result.StandardError))
{
Console.WriteLine("errors:" + Environment.NewLine + result.StandardError);
}
Assert.AreEqual(0, result.ExitCode, "mcs failed");

return results;
Expand All @@ -558,7 +585,7 @@ internal static DecompilerSettings GetSettings(CompilerOptions cscOptions)
CompilerOptions.UseRoslyn1_3_2 => CSharp.LanguageVersion.CSharp6,
CompilerOptions.UseRoslyn2_10_0 => CSharp.LanguageVersion.CSharp7_3,
CompilerOptions.UseRoslyn3_11_0 => CSharp.LanguageVersion.CSharp9_0,
_ => cscOptions.HasFlag(CompilerOptions.Preview) ? CSharp.LanguageVersion.Latest : CSharp.LanguageVersion.CSharp10_0,
_ => cscOptions.HasFlag(CompilerOptions.Preview) ? CSharp.LanguageVersion.Latest : CSharp.LanguageVersion.CSharp11_0,
};
DecompilerSettings settings = new(langVersion) {
// Never use file-scoped namespaces
Expand Down Expand Up @@ -815,8 +842,14 @@ public static async Task SignAssembly(string assemblyPath, string keyFilePath)
var result = await command.ExecuteBufferedAsync().ConfigureAwait(false);
Assert.AreEqual(0, result.ExitCode, "sn failed");

Console.WriteLine("output: " + result.StandardOutput);
Console.WriteLine("errors: " + result.StandardError);
if (!string.IsNullOrWhiteSpace(result.StandardOutput))
{
Console.WriteLine("output:" + Environment.NewLine + result.StandardOutput);
}
if (!string.IsNullOrWhiteSpace(result.StandardError))
{
Console.WriteLine("errors:" + Environment.NewLine + result.StandardError);
}
}

public static async Task<string> FindMSBuild()
Expand Down
13 changes: 10 additions & 3 deletions ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<AllowUnsafeBlocks>True</AllowUnsafeBlocks>

<NoWarn>1701;1702;1705,67,169,1058,728,1720,649,168,251,660,661,675;1998;162</NoWarn>
<NoWarn>1701;1702;1705,67,169,1058,728,1720,649,168,251,660,661,675;1998;162;8632</NoWarn>

<GenerateAssemblyVersionAttribute>False</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>False</GenerateAssemblyFileVersionAttribute>
Expand Down Expand Up @@ -45,7 +45,7 @@
<ItemGroup>
<PackageReference Include="DiffLib" Version="$(DiffLibVersion)" />
<PackageReference Include="CliWrap" Version="3.4.4" />
<PackageReference Include="NuGet.Protocol" Version="6.2.1" />
<PackageReference Include="NuGet.Protocol" Version="6.2.2" />
<PackageReference Include="System.Collections.Immutable" Version="$(SystemCollectionsImmutableVersion)" />
<PackageReference Include="System.Reflection.Metadata" Version="$(SystemReflectionMetadataVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="$(RoslynVersion)" />
Expand All @@ -57,7 +57,7 @@
<!-- used for xml test result files -->
<PackageReference Include="JunitXml.TestLogger" Version="$(JUnitXmlTestLoggerVersion)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkVersion)" />
<PackageReference Include="System.Memory" Version="4.5.4" />
<PackageReference Include="System.Memory" Version="4.5.5" />
<PackageReference Include="Mono.Cecil" Version="$(MonoCecilVersion)" />
<PackageReference Include="Microsoft.NETCore.ILAsm" Version="$(ILAsmVersion)" />
<PackageReference Include="Microsoft.NETCore.ILDAsm" Version="$(ILDAsmVersion)" />
Expand All @@ -73,6 +73,8 @@
<None Include="TestCases\Correctness\StackTests.il" />
<None Include="TestCases\Correctness\StackTypes.il" />
<None Include="TestCases\Correctness\Uninit.vb" />
<None Include="TestCases\Disassembler\Pretty\SortMembers.expected.il" />
<None Include="TestCases\Disassembler\Pretty\SortMembers.il" />
<None Include="TestCases\ILPretty\GuessAccessors.cs" />
<None Include="TestCases\ILPretty\GuessAccessors.il" />
<None Include="TestCases\ILPretty\Issue2260SwitchString.il" />
Expand Down Expand Up @@ -110,6 +112,10 @@
<Compile Include="Output\InsertParenthesesVisitorTests.cs" />
<Compile Include="ProjectDecompiler\TargetFrameworkTests.cs" />
<Compile Include="TestAssemblyResolver.cs" />
<None Include="TestCases\VBPretty\VBAutomaticEvents.vb" />
<Compile Include="TestCases\VBPretty\VBAutomaticEvents.cs" />
<Compile Include="TestCases\VBPretty\VBNonGenericForEach.cs" />
<None Include="TestCases\VBPretty\VBNonGenericForEach.vb" />
<Compile Include="TypeSystem\ReflectionHelperTests.cs" />
<None Include="TestCases\Pretty\MetadataAttributes.cs" />
<None Include="TestCases\Correctness\ComInterop.cs" />
Expand Down Expand Up @@ -312,6 +318,7 @@
</ItemGroup>

<ItemGroup>
<Content Include="TestCases\PdbGen\ProgressReporting.xml" />
<Content Include="TestCases\PdbGen\ForLoopTests.xml" />
<Content Include="TestCases\PdbGen\CustomPdbId.xml" />
<Content Include="TestCases\PdbGen\HelloWorld.xml" />
Expand Down
Loading

0 comments on commit 93bf1a2

Please sign in to comment.