Skip to content

Commit

Permalink
PDBWriter: replace Assert with LogError (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierpinho authored Dec 16, 2024
1 parent 37772a6 commit 77091f6
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions DotNetAstGen/PDBWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,25 @@
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection.Metadata;
using System.Reflection.Metadata.Ecma335;
using System.Reflection.PortableExecutable;
using System.Runtime;
using System.Security.Cryptography;
using System.Text;
using System.Threading;

using ICSharpCode.Decompiler.CSharp;
using ICSharpCode.Decompiler.CSharp.OutputVisitor;
using ICSharpCode.Decompiler.CSharp.ProjectDecompiler;
using ICSharpCode.Decompiler.CSharp.Syntax;
using ICSharpCode.Decompiler.CSharp.Transforms;
using ICSharpCode.Decompiler.IL;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.Decompiler.Util;
using ICSharpCode.Decompiler;

using ICSharpCode.Decompiler.DebugInfo;
using ICSharpCode.Decompiler.Disassembler;
using ICSharpCode.Decompiler.Solution;
using ICSharpCode.ILSpyX.PdbProvider;
using Microsoft.Extensions.Logging;

namespace DotNetAstGen
{
Expand Down Expand Up @@ -279,6 +268,8 @@ public ImportScopeInfo(ImportScopeInfo parent)

public class PDBWriter
{
private static readonly ILogger? Logger = Program.LoggerFactory?.CreateLogger("PDBWriter");

internal static readonly HashSet<string> attributeNames = new HashSet<string>() {
"System.Runtime.CompilerServices.IsReadOnlyAttribute",
"System.Runtime.CompilerServices.IsByRefLikeAttribute",
Expand Down Expand Up @@ -402,7 +393,7 @@ string BuildFileNameFromTypeName(TypeDefinitionHandle handle)
var method = function.MoveNextMethod ?? function.Method;
var methodHandle = (MethodDefinitionHandle)method!.MetadataToken;
sequencePoints.TryGetValue(function, out var points);
ProcessMethod(methodHandle, document, points, syntaxTree);
ProcessMethod(methodHandle, document, points, file.FileName);
if (function.MoveNextMethod != null)
{
stateMachineMethods.Add((
Expand Down Expand Up @@ -495,14 +486,13 @@ string BuildFileNameFromTypeName(TypeDefinitionHandle handle)
blobBuilder.WriteContentTo(targetStream);

void ProcessMethod(MethodDefinitionHandle method, DocumentHandle document,
List<ICSharpCode.Decompiler.DebugInfo.SequencePoint>? sequencePoints, SyntaxTree syntaxTree)
List<ICSharpCode.Decompiler.DebugInfo.SequencePoint>? sequencePoints, string sourceFile)
{
var methodDef = reader.GetMethodDefinition(method);
int localSignatureRowId;
MethodBodyBlock methodBody;
if (methodDef.RelativeVirtualAddress != 0)
{
methodBody = file.Reader.GetMethodBody(methodDef.RelativeVirtualAddress);
var methodBody = file.Reader.GetMethodBody(methodDef.RelativeVirtualAddress);
localSignatureRowId = methodBody.LocalSignature.IsNil ? 0 : MetadataTokens.GetRowNumber(methodBody.LocalSignature);
}
else
Expand All @@ -522,7 +512,7 @@ void ProcessMethod(MethodDefinitionHandle method, DocumentHandle document,
}
else
{
Debug.Assert(false, "Duplicate sequence point definition detected: " + MetadataTokens.GetToken(method).ToString("X8"));
Logger.LogError($"Duplicate sequence point definition detected: ${MetadataTokens.GetToken(method):X8} when processing ${sourceFile}");

Check warning on line 515 in DotNetAstGen/PDBWriter.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'logger' in 'void LoggerExtensions.LogError(ILogger logger, string? message, params object?[] args)'.

Check warning on line 515 in DotNetAstGen/PDBWriter.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'logger' in 'void LoggerExtensions.LogError(ILogger logger, string? message, params object?[] args)'.

Check warning on line 515 in DotNetAstGen/PDBWriter.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'logger' in 'void LoggerExtensions.LogError(ILogger logger, string? message, params object?[] args)'.
}
}
}
Expand Down Expand Up @@ -639,4 +629,4 @@ static string SyntaxTreeToString(SyntaxTree syntaxTree, DecompilerSettings setti
return w.ToString();
}
}
}
}

0 comments on commit 77091f6

Please sign in to comment.