icsharpcode / ILSpy

.NET Decompiler with support for PDB generation, ReadyToRun, Metadata (&more) - cross-platform!
21.62k stars 3.36k forks source link

[ilspycmd] Broken PDB generated for `MoveNext` when using --genpdb #2823

Open spouliot opened 2 years ago

spouliot commented 2 years ago

Background

The iOS SDK does not use Source Link and also does not embed sources inside PDB (which would be quite useful for the generated code). I thought ILSpy could help :)

Steps to reproduce

  1. Use ilspycmd to create PDB with sources for Microsoft.iOS.dll

Both

ilspycmd -genpdb Microsoft.iOS.dll -usepdb Microsoft.iOS.pdb

and

ilspycmd -genpdb Microsoft.iOS.dll

were tried.

  1. Try to use the assembly / .pdb
  2. Error while building the application

Original files: Microsoft.iOS.zip

Error message shown

ILLink : error IL1005: System.Net.Http.NSUrlSessionHandler.<SendAsync>d__58: Error processing method 'System.Net.Http.NSUrlSessionHandler.<SendAsync>d__58.MoveNext()' in assembly 'Microsoft.iOS.dll' [/Users/.../DebugMyApp/DebugMyApp.Mobile/DebugMyApp.Mobile.csproj]
  Mono.Linker.LinkerFatalErrorException: ILLink: error IL1005: System.Net.Http.NSUrlSessionHandler.<SendAsync>d__58: Error processing method 'System.Net.Http.NSUrlSessionHandler.<SendAsync>d__58.MoveNext()' in assembly 'Microsoft.iOS.dll'
   ---> System.ArgumentNullException: Value cannot be null. (Parameter 'instruction')
     at Mono.Cecil.Cil.InstructionOffset..ctor(Instruction instruction)
     at Mono.Cecil.Cil.CodeReader.ReadAsyncMethodBody(AsyncMethodBodyDebugInformation async_method)
     at Mono.Cecil.Cil.CodeReader.ReadCustomDebugInformations(MethodDefinition method)
     at Mono.Cecil.Cil.CodeReader.ReadDebugInfo()
     at Mono.Cecil.Cil.CodeReader.ReadMethodBody()
     at Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)
     at Mono.Cecil.MetadataReader.ReadMethodBody(MethodDefinition method)
     at Mono.Cecil.MethodDefinition.<>c.<get_Body>b__41_0(MethodDefinition method, MetadataReader reader)
     at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TRet& variable, TItem item, Func`3 read)
     at Mono.Cecil.MethodDefinition.get_Body()
     at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method, DependencyInfo& reason, Scope& scope)
     at Mono.Linker.Steps.MarkStep.ProcessQueue()
     --- End of inner exception stack trace ---
     at Mono.Linker.Steps.MarkStep.ProcessQueue()
     at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()
     at Mono.Linker.Steps.MarkStep.Process()
     at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
     at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
     at Mono.Linker.Pipeline.Process(LinkContext context)
     at Mono.Linker.Driver.Run(ILogger customLogger)
  Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink

Versions

ilspycmd --version                                                                                                                         ilspycmd: 7.2.1.0
ICSharpCode.Decompiler: 7.2.1.6856

More details

I have hit a few PDB issues in the past so I wrote a tool to see what could be wrong in them (or Cecil).

The output I get is:

Microsoft.iOS

CoreFoundation.CFNetwork/d15 / System.Void CoreFoundation.CFNetwork/d15::MoveNext()

System.ArgumentNullException: Value cannot be null. (Parameter 'instruction')
   at Mono.Cecil.Cil.CodeReader.ReadAsyncMethodBody(AsyncMethodBodyDebugInformation async_method)
   at Mono.Cecil.Cil.CodeReader.ReadCustomDebugInformations(MethodDefinition method)
   at Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TRet& variable, TItem item, Func`3 read)
   at Program.<<Main>$>g__Process|0_0(TypeDefinition type) in /Users/poupou/git/dotnet-tools/cecil-pdb-check/Program.cs:line 29

System.Net.Http.NSUrlSessionHandler/NSUrlSessionDataTaskStream/d14 / System.Void System.Net.Http.NSUrlSessionHandler/NSUrlSessionDataTaskStream/d14::MoveNext()

System.ArgumentNullException: Value cannot be null. (Parameter 'instruction')
   at Mono.Cecil.Cil.CodeReader.ReadAsyncMethodBody(AsyncMethodBodyDebugInformation async_method)
   at Mono.Cecil.Cil.CodeReader.ReadCustomDebugInformations(MethodDefinition method)
   at Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TRet& variable, TItem item, Func`3 read)
   at Program.<<Main>$>g__Process|0_0(TypeDefinition type) in /Users/poupou/git/dotnet-tools/cecil-pdb-check/Program.cs:line 29

System.Net.Http.NSUrlSessionHandler/d57 / System.Void System.Net.Http.NSUrlSessionHandler/d57::MoveNext()

System.ArgumentNullException: Value cannot be null. (Parameter 'instruction')
   at Mono.Cecil.Cil.CodeReader.ReadAsyncMethodBody(AsyncMethodBodyDebugInformation async_method)
   at Mono.Cecil.Cil.CodeReader.ReadCustomDebugInformations(MethodDefinition method)
   at Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TRet& variable, TItem item, Func`3 read)
   at Program.<<Main>$>g__Process|0_0(TypeDefinition type) in /Users/poupou/git/dotnet-tools/cecil-pdb-check/Program.cs:line 29

System.Net.Http.NSUrlSessionHandler/d58 / System.Void System.Net.Http.NSUrlSessionHandler/d58::MoveNext()

System.ArgumentNullException: Value cannot be null. (Parameter 'instruction')
   at Mono.Cecil.Cil.CodeReader.ReadAsyncMethodBody(AsyncMethodBodyDebugInformation async_method)
   at Mono.Cecil.Cil.CodeReader.ReadCustomDebugInformations(MethodDefinition method)
   at Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TRet& variable, TItem item, Func`3 read)
   at Program.<<Main>$>g__Process|0_0(TypeDefinition type) in /Users/poupou/git/dotnet-tools/cecil-pdb-check/Program.cs:line 29

System.Net.Http.CFContentStream/d10 / System.Void System.Net.Http.CFContentStream/d10::MoveNext()

System.ArgumentNullException: Value cannot be null. (Parameter 'instruction')
   at Mono.Cecil.Cil.CodeReader.ReadAsyncMethodBody(AsyncMethodBodyDebugInformation async_method)
   at Mono.Cecil.Cil.CodeReader.ReadCustomDebugInformations(MethodDefinition method)
   at Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TRet& variable, TItem item, Func`3 read)
   at Program.<<Main>$>g__Process|0_0(TypeDefinition type) in /Users/poupou/git/dotnet-tools/cecil-pdb-check/Program.cs:line 29

System.Net.Http.CFNetworkHandler/d19 / System.Void System.Net.Http.CFNetworkHandler/d19::MoveNext()

System.ArgumentNullException: Value cannot be null. (Parameter 'instruction')
   at Mono.Cecil.Cil.CodeReader.ReadAsyncMethodBody(AsyncMethodBodyDebugInformation async_method)
   at Mono.Cecil.Cil.CodeReader.ReadCustomDebugInformations(MethodDefinition method)
   at Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TRet& variable, TItem item, Func`3 read)
   at Program.<<Main>$>g__Process|0_0(TypeDefinition type) in /Users/poupou/git/dotnet-tools/cecil-pdb-check/Program.cs:line 29

System.Net.Http.CFNetworkHandler/d20 / System.Void System.Net.Http.CFNetworkHandler/d20::MoveNext()

System.ArgumentNullException: Value cannot be null. (Parameter 'instruction')
   at Mono.Cecil.Cil.CodeReader.ReadAsyncMethodBody(AsyncMethodBodyDebugInformation async_method)
   at Mono.Cecil.Cil.CodeReader.ReadCustomDebugInformations(MethodDefinition method)
   at Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TRet& variable, TItem item, Func`3 read)
   at Program.<<Main>$>g__Process|0_0(TypeDefinition type) in /Users/poupou/git/dotnet-tools/cecil-pdb-check/Program.cs:line 29

Compression.CompressionStream/CopyToAsyncStream/d8 / System.Void Compression.CompressionStream/CopyToAsyncStream/d8::MoveNext()

System.ArgumentNullException: Value cannot be null. (Parameter 'instruction')
   at Mono.Cecil.Cil.CodeReader.ReadAsyncMethodBody(AsyncMethodBodyDebugInformation async_method)
   at Mono.Cecil.Cil.CodeReader.ReadCustomDebugInformations(MethodDefinition method)
   at Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TRet& variable, TItem item, Func`3 read)
   at Program.<<Main>$>g__Process|0_0(TypeDefinition type) in /Users/poupou/git/dotnet-tools/cecil-pdb-check/Program.cs:line 29

Compression.CompressionStream/CopyToAsyncStream/d9 / System.Void Compression.CompressionStream/CopyToAsyncStream/d9::MoveNext()

System.ArgumentNullException: Value cannot be null. (Parameter 'instruction')
   at Mono.Cecil.Cil.CodeReader.ReadAsyncMethodBody(AsyncMethodBodyDebugInformation async_method)
   at Mono.Cecil.Cil.CodeReader.ReadCustomDebugInformations(MethodDefinition method)
   at Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TRet& variable, TItem item, Func`3 read)
   at Program.<<Main>$>g__Process|0_0(TypeDefinition type) in /Users/poupou/git/dotnet-tools/cecil-pdb-check/Program.cs:line 29

Compression.CompressionStream/d41 / System.Void Compression.CompressionStream/d41::MoveNext()

System.ArgumentNullException: Value cannot be null. (Parameter 'instruction')
   at Mono.Cecil.Cil.CodeReader.ReadAsyncMethodBody(AsyncMethodBodyDebugInformation async_method)
   at Mono.Cecil.Cil.CodeReader.ReadCustomDebugInformations(MethodDefinition method)
   at Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TRet& variable, TItem item, Func`3 read)
   at Program.<<Main>$>g__Process|0_0(TypeDefinition type) in /Users/poupou/git/dotnet-tools/cecil-pdb-check/Program.cs:line 29

Compression.CompressionStream/d73 / System.Void Compression.CompressionStream/d73::MoveNext()

System.ArgumentNullException: Value cannot be null. (Parameter 'instruction')
   at Mono.Cecil.Cil.CodeReader.ReadAsyncMethodBody(AsyncMethodBodyDebugInformation async_method)
   at Mono.Cecil.Cil.CodeReader.ReadCustomDebugInformations(MethodDefinition method)
   at Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TRet& variable, TItem item, Func`3 read)
   at Program.<<Main>$>g__Process|0_0(TypeDefinition type) in /Users/poupou/git/dotnet-tools/cecil-pdb-check/Program.cs:line 29

Compression.CompressionStream/d74 / System.Void Compression.CompressionStream/d74::MoveNext()

System.ArgumentNullException: Value cannot be null. (Parameter 'instruction')
   at Mono.Cecil.Cil.CodeReader.ReadAsyncMethodBody(AsyncMethodBodyDebugInformation async_method)
   at Mono.Cecil.Cil.CodeReader.ReadCustomDebugInformations(MethodDefinition method)
   at Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TRet& variable, TItem item, Func`3 read)
   at Program.<<Main>$>g__Process|0_0(TypeDefinition type) in /Users/poupou/git/dotnet-tools/cecil-pdb-check/Program.cs:line 29
spouliot commented 2 years ago

Trying to decompile one of the methods shows

    private void MoveNext()
    {
        //IL_004d: Unknown result type (might be due to invalid IL or missing references)
        //IL_0052: Unknown result type (might be due to invalid IL or missing references)
        //IL_0056: Unknown result type (might be due to invalid IL or missing references)
        //IL_005b: Unknown result type (might be due to invalid IL or missing references)
        //IL_0070: Unknown result type (might be due to invalid IL or missing references)
        //IL_0072: Unknown result type (might be due to invalid IL or missing references)
        //IL_008b: Unknown result type (might be due to invalid IL or missing references)
        //IL_0090: Unknown result type (might be due to invalid IL or missing references)
        //IL_0098: Unknown result type (might be due to invalid IL or missing references)
        //IL_00e4: Unknown result type (might be due to invalid IL or missing references)
        //IL_017c: Unknown result type (might be due to invalid IL or missing references)
        //IL_0186: Expected O, but got Unknown
        //IL_0181: Unknown result type (might be due to invalid IL or missing references)
        //IL_019d: Unknown result type (might be due to invalid IL or missing references)
        //IL_01a2: Unknown result type (might be due to invalid IL or missing references)
        //IL_01a6: Unknown result type (might be due to invalid IL or missing references)
        //IL_01ab: Unknown result type (might be due to invalid IL or missing references)
        //IL_01c0: Unknown result type (might be due to invalid IL or missing references)
        //IL_01c2: Unknown result type (might be due to invalid IL or missing references)
        //IL_01d8: Unknown result type (might be due to invalid IL or missing references)
        //IL_01dd: Unknown result type (might be due to invalid IL or missing references)
        //IL_01e5: Unknown result type (might be due to invalid IL or missing references)
        int num = <>1__state;
...

The first block is:

            IL_004d: callvirt instance valuetype [System.Runtime]System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1<!0> class [System.Runtime]System.Threading.Tasks.Task`1<class Foundation.NSUrlRequest>::ConfigureAwait(bool) /* 0A000BCE */
            IL_0052: stloc.s 5
            IL_0054: ldloca.s 5
            IL_0056: call instance valuetype [System.Runtime]System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1/ConfiguredTaskAwaiter<!0> valuetype [System.Runtime]System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1<class Foundation.NSUrlRequest>::GetAwaiter() /* 0A000BCF */

so maybe it just needs to find System.Runtime...

spouliot commented 2 years ago

Nope, that did not help :|

siegfriedpammer commented 2 years ago

I tried your tool, but it does not give me the same output on Windows. No errors are reported using it on Microsoft.iOS.dll with a PDB generated by ILSpy. However, I found a difference between ILSpy and other PDB tools. I will push a fix soon, but I am not sure, if it will fix all your problems, because I cannot reproduce the Cecil crashes using your tool.

spouliot commented 2 years ago

I'm on a Mac computer. Is there Windows (or Mac) specific code paths for PDB ?

Anyway I'll be trying your fix once pushed, thanks for looking :)

spouliot commented 2 years ago

It works for me when using the Avalonia version of ILSpy (version 7.2.0.0.rc) on the Mac.

So I could be an issue (only) with ilspycmd. Or there's something broken in master (that I used to build ilspycmd) versus the latest release of ILSpy/Avalonia

Did you try using the command tool ?

siegfriedpammer commented 2 years ago

I tried ILSpy master and the released version of ilspycmd, that is 7.2.1.6856 (via dotnet tool install). It's interesting that it's the same version that ILSpyAvalonia is using currently: https://github.com/icsharpcode/AvaloniaILSpy/blob/master/ILSpy.Core/ILSpy.Core.csproj#L32

siegfriedpammer commented 2 years ago

I have pushed two commits that fix some of the issues I saw. Can you please try again? Thanks!

spouliot commented 2 years ago

In my original report I used the prebuilt tools (ilspycmd and ILSpy/Avalonia).

This time I

cp /usr/local/share/dotnet//packs/Microsoft.iOS.Runtime.iossimulator-x86/16.0.523/runtimes/iossimulator-x86/lib/net6.0/* tmp/
cd ILSpy
git clean -xfd
cd ICSharpCode.ILSpyCmd
dotnet run -- -genpdb /Users/poupou/git/external/uno/uno.vscode/tmp/Microsoft.iOS.dll -usepdb /Users/poupou/git/external/uno/uno.vscode/tmp/Microsoft.iOS.pdb

This is hitting Debug.Assert conditions

/Users/poupou/.nuget/packages/microsoft.build.tasks.git/1.1.1/build/Microsoft.Build.Tasks.Git.targets(25,5): warning : Could not find file '/Users/poupou/git/external/ILSpy/ILSpy-tests/.git'. The source code won't be available via Source Link. [/Users/poupou/git/external/ILSpy/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj]
/Users/poupou/.nuget/packages/microsoft.build.tasks.git/1.1.1/build/Microsoft.Build.Tasks.Git.targets(25,5): warning : Could not find file '/Users/poupou/git/external/ILSpy/ILSpy-tests/.git'. The source code won't be available via Source Link. [/Users/poupou/git/external/ILSpy/ICSharpCode.ILSpyX/ICSharpCode.ILSpyX.csproj]

Process terminated. Assertion failed.
Duplicate sequence point definition detected: 060186C5
   at ICSharpCode.Decompiler.DebugInfo.PortablePdbWriter.<>c__DisplayClass2_0.<WritePdb>g__ProcessMethod|6(MethodDefinitionHandle method, DocumentHandle document, List`1 sequencePoints, SyntaxTree syntaxTree) in /Users/poupou/git/external/ILSpy/ICSharpCode.Decompiler/DebugInfo/PortablePdbWriter.cs:line 261
   at ICSharpCode.Decompiler.DebugInfo.PortablePdbWriter.WritePdb(PEFile file, CSharpDecompiler decompiler, DecompilerSettings settings, Stream targetStream, Boolean noLogo, Nullable`1 pdbId, IProgress`1 progress) in /Users/poupou/git/external/ILSpy/ICSharpCode.Decompiler/DebugInfo/PortablePdbWriter.cs:line 141
   at ICSharpCode.ILSpyCmd.ILSpyCmdProgram.GeneratePdbForAssembly(String assemblyFileName, String pdbFileName, CommandLineApplication app) in /Users/poupou/git/external/ILSpy/ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs:line 322
   at ICSharpCode.ILSpyCmd.ILSpyCmdProgram.<OnExecute>g__PerformPerFileAction|48_0(String fileName, <>c__DisplayClass48_0& ) in /Users/poupou/git/external/ILSpy/ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs:line 198
   at ICSharpCode.ILSpyCmd.ILSpyCmdProgram.OnExecute(CommandLineApplication app) in /Users/poupou/git/external/ILSpy/ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs:line 144
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.Invoke(MethodInfo method, Object instance, Object[] arguments)
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.OnExecute(ConventionContext context, CancellationToken cancellationToken)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.OnExecute(ConventionContext context, CancellationToken cancellationToken)
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.<>c__DisplayClass0_0.<<Apply>b__0>d.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.<>c__DisplayClass0_0.<Apply>b__0(CancellationToken ct)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync[TApp](CommandLineContext context, CancellationToken cancellationToken)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync[TApp](CommandLineContext context, CancellationToken cancellationToken)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute[TApp](CommandLineContext context)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute[TApp](IConsole console, String[] args)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute[TApp](String[] args)
   at ICSharpCode.ILSpyCmd.ILSpyCmdProgram.Main(String[] args) in /Users/poupou/git/external/ILSpy/ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs:line 51

If I try the same in a release build (dotnet publish -c Release) it gets farther (takes more time and modifies the .pdb file) but it still fails.

./ilspycmd -genpdb /Users/poupou/git/external/uno/uno.vscode/tmp/Microsoft.iOS.dll -usepdb /Users/poupou/git/external/uno/uno.vscode/tmp/Microsoft.iOS.pdb
ICSharpCode.Decompiler.Metadata.PEFileNotSupportedException: PE file does not contain any managed metadata.
   at ICSharpCode.Decompiler.Metadata.PEFile..ctor(String fileName, PEReader reader, MetadataReaderOptions metadataOptions) in /Users/poupou/git/external/ILSpy/ICSharpCode.Decompiler/Metadata/PEFile.cs:line 70
   at ICSharpCode.Decompiler.Metadata.PEFile..ctor(String fileName, Stream stream, PEStreamOptions streamOptions, MetadataReaderOptions metadataOptions) in /Users/poupou/git/external/ILSpy/ICSharpCode.Decompiler/Metadata/PEFile.cs:line 61
   at ICSharpCode.ILSpyCmd.ILSpyCmdProgram.GeneratePdbForAssembly(String assemblyFileName, String pdbFileName, CommandLineApplication app) in /Users/poupou/git/external/ILSpy/ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs:line 308
   at ICSharpCode.ILSpyCmd.ILSpyCmdProgram.<OnExecute>g__PerformPerFileAction|48_0(String fileName, <>c__DisplayClass48_0& ) in /Users/poupou/git/external/ILSpy/ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs:line 198
   at ICSharpCode.ILSpyCmd.ILSpyCmdProgram.OnExecute(CommandLineApplication app) in /Users/poupou/git/external/ILSpy/ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs:line 144

If I do not specify -usepdb then there's no error - but I thought I needed that to get the original information, like variable names right ?

The build works but the decompiled sources are not visible in the debugger and the .pdb is only 13MB. The working (with sources) version (from ILSpy/Avalonia) was 20MB.

Maybe I missing a step somewhere ?

siegfriedpammer commented 2 years ago

Ok, so there is multiple issues:

1) The assertion regarding Duplicate sequence point definition is due ILSpy's inability to recognize some async state-machines. Unfortunately, ilspycmd has no way to "ignore" the assertion, unlike "ILSpy for Windows ". Compiling in release mode will fix that. 2) If you look at the command line help of ilspycmd, you will see that -usepdb does not accept an argument. The PDB file is treated as normal DLL by ilspycmd and when it tries to load it, it fails with "PE file does not contain any managed metadata", because the PDB file is not a full PE image. -usepdb will cause ilspycmd to automatically resolve and load the PDB file next to the DLL.

Regarding the differences in file size... I will have to investigate further, but you can always look at the PDB file in ILSpy and check if the Document table contains any rows... From what I can see, it seems that the PDB generated by ILSpy is fine:

image

spouliot commented 2 years ago

That makes sense. Thanks for the help!

Sadly ILSpy/Avalonia does not show the metadata tables :( but I can check that with some code...

or UPS will finally deliver me my volterra devkit and I'll have a window box again (after more than 15 years)

spouliot commented 2 years ago

So after doing a (more proper) ./ilspycmd -genpdb tmp/Microsoft.iOS.dll -usepdb

I have no error (as expected) but don't get any document (0x30) from the assembly... binaries attached

Screenshot 2022-11-02 at 10 44 41 AM

Microsoft.iOS.zip

siegfriedpammer commented 2 years ago

Don't know which tool you used in that screenshot, but it's somehow broken. This is what ILSpy shows for the files you provided:

image

spouliot commented 2 years ago

I see them on Windows too. I noticed the workload number changed so I might have copied the pdb to the older location... I'll restart this from scratch and compare the results (myself) on Windows.