diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-08-25 20:45:24 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-25 20:45:24 -0400 |
commit | 0ad033908243528a26b48efcbc8727b1d882f236 (patch) | |
tree | 02909317cfd597acc14e932357fd8d2662fa3ea7 /src/SMAPI/Framework/ModLoading/Symbols/SymbolReader.cs | |
parent | b8dac41da8aa7ea8f42b89acd1e9a74829d70532 (diff) | |
parent | 11ecd578e960379db609cae5f9922df11ae79820 (diff) | |
download | SMAPI-0ad033908243528a26b48efcbc8727b1d882f236.tar.gz SMAPI-0ad033908243528a26b48efcbc8727b1d882f236.tar.bz2 SMAPI-0ad033908243528a26b48efcbc8727b1d882f236.zip |
Merge pull request #801 from spacechase0/fix-crash-rewritten-assemblies
Fix assembly rewriting causing VS to error/crash when debugging
Diffstat (limited to 'src/SMAPI/Framework/ModLoading/Symbols/SymbolReader.cs')
-rw-r--r-- | src/SMAPI/Framework/ModLoading/Symbols/SymbolReader.cs | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/ModLoading/Symbols/SymbolReader.cs b/src/SMAPI/Framework/ModLoading/Symbols/SymbolReader.cs new file mode 100644 index 00000000..2171895d --- /dev/null +++ b/src/SMAPI/Framework/ModLoading/Symbols/SymbolReader.cs @@ -0,0 +1,72 @@ +using System.IO; +using Mono.Cecil; +using Mono.Cecil.Cil; +using Mono.Cecil.Pdb; + +namespace StardewModdingAPI.Framework.ModLoading.Symbols +{ + /// <summary>Reads symbol data for an assembly.</summary> + internal class SymbolReader : ISymbolReader + { + /********* + ** Fields + *********/ + /// <summary>The module for which to read symbols.</summary> + private readonly ModuleDefinition Module; + + /// <summary>The symbol file stream.</summary> + private readonly Stream Stream; + + /// <summary>The underlying symbol reader.</summary> + private ISymbolReader Reader; + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + /// <param name="module">The module for which to read symbols.</param> + /// <param name="stream">The symbol file stream.</param> + public SymbolReader(ModuleDefinition module, Stream stream) + { + this.Module = module; + this.Stream = stream; + this.Reader = new NativePdbReaderProvider().GetSymbolReader(module, stream); + } + + /// <summary>Get the symbol writer provider for the assembly.</summary> + public ISymbolWriterProvider GetWriterProvider() + { + return new PortablePdbWriterProvider(); + } + + /// <summary>Process a debug header in the symbol file.</summary> + /// <param name="header">The debug header.</param> + public bool ProcessDebugHeader(ImageDebugHeader header) + { + try + { + return this.Reader.ProcessDebugHeader(header); + } + catch + { + this.Reader.Dispose(); + this.Reader = new PortablePdbReaderProvider().GetSymbolReader(this.Module, this.Stream); + return this.Reader.ProcessDebugHeader(header); + } + } + + /// <summary>Read the method debug information for a method in the assembly.</summary> + /// <param name="method">The method definition.</param> + public MethodDebugInformation Read(MethodDefinition method) + { + return this.Reader.Read(method); + } + + /// <inheritdoc /> + public void Dispose() + { + this.Reader.Dispose(); + } + } +} |