Skip to content

Commit

Permalink
Add method representation only if available
Browse files Browse the repository at this point in the history
Removed usage of System.Collections.Immutable and System.Runtime.CompilerServices.Unsafe where possible
  • Loading branch information
Aragas committed Dec 23, 2023
1 parent d843c1c commit d3ba74c
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="NuGetizer" Version="1.2.1" Pack="false" />
<PackageReference Include="System.Collections.Immutable" Version="1.2.0" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ namespace BUTR.CrashReport.Bannerlord
using global::System.Collections.Generic;
using global::System.IO;
using global::System.IO.Compression;
using global::System.Linq;

internal static class CrashReportArchiveRenderer
{
Expand Down
168 changes: 95 additions & 73 deletions src/BUTR.CrashReport.Bannerlord.Source/CrashReportCreator.cs

Large diffs are not rendered by default.

64 changes: 41 additions & 23 deletions src/BUTR.CrashReport.Bannerlord.Source/CrashReportHtmlRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ namespace BUTR.CrashReport.Bannerlord
{
using global::BUTR.CrashReport.Extensions;
using global::BUTR.CrashReport.Models;
using global::BUTR.CrashReport.Utils;

using global::System;
using global::System.Collections.Generic;
using global::System.Collections.Immutable;
using global::System.IO;
using global::System.Linq;
using global::System.Text;
Expand Down Expand Up @@ -519,15 +517,23 @@ private static string GetEnhancedStacktraceHtml(CrashReportModel crashReport)
.Append("Method: ").Append(stacktrace.ExecutingMethod.MethodFullDescription.EscapeGenerics()).Append("<br/>")
.Append("Method From Stackframe Issue: ").Append(stacktrace.MethodFromStackframeIssue).Append("<br/>")
.Append("Approximate IL Offset: ").Append(stacktrace.ILOffset is not null ? $"{stacktrace.ILOffset:X4}" : "UNKNOWN").Append("<br/>")
.Append("Native Offset: ").Append(stacktrace.NativeOffset is not null ? $"{stacktrace.NativeOffset:X4}" : "UNKNOWN")
.AppendIf(stacktrace.ExecutingMethod.ILInstructions.Count > 0, $"<div><a href='javascript:;' class='headers' onclick='showHideById(this, \"{id1}\")'>+ IL:</a><div id='{id1}' class='headers-container'><pre>")
.AppendJoinIf(stacktrace.ExecutingMethod.ILInstructions.Count > 0, Environment.NewLine, stacktrace.ExecutingMethod.ILInstructions.Select(x => x.EscapeGenerics()).ToArray()).Append("</pre></div></div>")
.AppendIf(stacktrace.ExecutingMethod.CSharpILMixedInstructions.Count > 0, $"<div><a href='javascript:;' class='headers' onclick='showHideById(this, \"{id2}\")'>+ IL with C#:</a><div id='{id2}' class='headers-container'><pre>")
.AppendJoinIf(stacktrace.ExecutingMethod.CSharpILMixedInstructions.Count > 0, Environment.NewLine, stacktrace.ExecutingMethod.CSharpILMixedInstructions.Select(x => x.EscapeGenerics()).ToArray()).Append("</pre></div></div>")
.AppendIf(stacktrace.ExecutingMethod.CSharpInstructions.Count > 0, $"<div><a href='javascript:;' class='headers' onclick='showHideById(this, \"{id3}\")'>+ C#:</a><div id='{id3}' class='headers-container'><pre>")
.AppendJoinIf(stacktrace.ExecutingMethod.CSharpInstructions.Count > 0, Environment.NewLine, stacktrace.ExecutingMethod.CSharpInstructions.Select(x => x.EscapeGenerics()).ToArray()).Append("</pre></div></div>")
.AppendIf(stacktrace.ExecutingMethod.NativeInstructions.Count > 0, $"<div><a href='javascript:;' class='headers' onclick='showHideById(this, \"{id4}\")'>+ Native:</a><div id='{id4}' class='headers-container'><pre>")
.AppendJoinIf(stacktrace.ExecutingMethod.NativeInstructions.Count > 0, Environment.NewLine, stacktrace.ExecutingMethod.NativeInstructions.Select(x => x.EscapeGenerics()).ToArray()).Append("</pre></div></div>")
.Append("Native Offset: ").Append(stacktrace.NativeOffset is not null ? $"{stacktrace.NativeOffset:X4}" : "UNKNOWN").Append("<br/>")
.AppendIf(stacktrace.ExecutingMethod.ILInstructions.Count > 0, sp => sp
.Append($"<div><a href='javascript:;' class='headers' onclick='showHideById(this, \"{id1}\")'>+ IL:</a><div id='{id1}' class='headers-container'><pre>")
.AppendJoin(Environment.NewLine, stacktrace.ExecutingMethod.ILInstructions.Select(x => x.EscapeGenerics()))
.Append("</pre></div></div>"))
.AppendIf(stacktrace.ExecutingMethod.CSharpILMixedInstructions.Count > 0, sp => sp
.Append($"<div><a href='javascript:;' class='headers' onclick='showHideById(this, \"{id2}\")'>+ IL with C#:</a><div id='{id2}' class='headers-container'><pre>")
.AppendJoin(Environment.NewLine, stacktrace.ExecutingMethod.CSharpILMixedInstructions.Select(x => x.EscapeGenerics()))
.Append("</pre></div></div>"))
.AppendIf(stacktrace.ExecutingMethod.CSharpInstructions.Count > 0, sp => sp
.Append($"<div><a href='javascript:;' class='headers' onclick='showHideById(this, \"{id3}\")'>+ C#:</a><div id='{id3}' class='headers-container'><pre>")
.AppendJoin(Environment.NewLine, stacktrace.ExecutingMethod.CSharpInstructions.Select(x => x.EscapeGenerics()))
.Append("</pre></div></div>"))
.AppendIf(stacktrace.ExecutingMethod.NativeInstructions.Count > 0, sp => sp
.Append($"<div><a href='javascript:;' class='headers' onclick='showHideById(this, \"{id4}\")'>+ Native:</a><div id='{id4}' class='headers-container'><pre>")
.AppendJoin(Environment.NewLine, stacktrace.ExecutingMethod.NativeInstructions.Select(x => x.EscapeGenerics()))
.Append("</pre></div></div>"))
.Append("</li>")
.Append("</ul>");

Expand All @@ -545,12 +551,18 @@ private static string GetEnhancedStacktraceHtml(CrashReportModel crashReport)
.AppendIf(moduleId == "UNKNOWN", sb => sb.Append("Module Id: ").Append(moduleId).Append("<br/>"))
.AppendIf(moduleId != "UNKNOWN", sb => sb.Append("Module Id: ").Append("<b><a href='javascript:;' onclick='scrollToElement(\"").Append(moduleId).Append("\")'>").Append(moduleId).Append("</a></b>").Append("<br/>"))
.Append("Method: ").Append(method.MethodFullDescription.EscapeGenerics()).Append("<br/>")
.AppendIf(method.ILInstructions.Count > 0, $"<div><a href='javascript:;' class='headers' onclick='showHideById(this, \"{id01}\")'>+ IL:</a><div id='{id01}' class='headers-container'><pre>")
.AppendJoinIf(method.ILInstructions.Count > 0, Environment.NewLine, method.ILInstructions.Select(x => x.EscapeGenerics()).ToArray()).Append("</pre></div></div>")
.AppendIf(method.CSharpILMixedInstructions.Count > 0, $"<div><a href='javascript:;' class='headers' onclick='showHideById(this, \"{id02}\")'>+ IL with C#:</a><div id='{id02}' class='headers-container'><pre>")
.AppendJoinIf(method.CSharpILMixedInstructions.Count > 0, Environment.NewLine, method.CSharpILMixedInstructions.Select(x => x.EscapeGenerics()).ToArray()).Append("</pre></div></div>")
.AppendIf(method.CSharpInstructions.Count > 0, $"<div><a href='javascript:;' class='headers' onclick='showHideById(this, \"{id03}\")'>+ C#:</a><div id='{id03}' class='headers-container'><pre>")
.AppendJoinIf(method.CSharpInstructions.Count > 0, Environment.NewLine, method.CSharpInstructions.Select(x => x.EscapeGenerics()).ToArray()).Append("</pre></div></div>")
.AppendIf(method.ILInstructions.Count > 0, sp => sp
.Append($"<div><a href='javascript:;' class='headers' onclick='showHideById(this, \"{id01}\")'>+ IL:</a><div id='{id01}' class='headers-container'><pre>")
.AppendJoin(Environment.NewLine, method.ILInstructions.Select(x => x.EscapeGenerics()))
.Append("</pre></div></div>"))
.AppendIf(method.CSharpILMixedInstructions.Count > 0, sp => sp
.Append($"<div><a href='javascript:;' class='headers' onclick='showHideById(this, \"{id02}\")'>+ IL with C#:</a><div id='{id02}' class='headers-container'><pre>")
.AppendJoin(Environment.NewLine, method.CSharpILMixedInstructions.Select(x => x.EscapeGenerics()))
.Append("</pre></div></div>"))
.AppendIf(method.CSharpInstructions.Count > 0, sp => sp
.Append($"<div><a href='javascript:;' class='headers' onclick='showHideById(this, \"{id03}\")'>+ C#:</a><div id='{id03}' class='headers-container'><pre>")
.AppendJoin(Environment.NewLine, method.CSharpInstructions.Select(x => x.EscapeGenerics()))
.Append("</pre></div></div>"))
.Append("</li>");
}
sb.Append("</ul>");
Expand All @@ -567,12 +579,18 @@ private static string GetEnhancedStacktraceHtml(CrashReportModel crashReport)
.AppendIf(moduleId2 == "UNKNOWN", sb => sb.Append("Module Id: ").Append(moduleId2).Append("<br/>"))
.AppendIf(moduleId2 != "UNKNOWN", sb => sb.Append("Module Id: ").Append("<b><a href='javascript:;' onclick='scrollToElement(\"").Append(moduleId2).Append("\")'>").Append(moduleId2).Append("</a></b>").Append("<br/>"))
.Append("Method: ").Append(stacktrace.OriginalMethod.MethodFullDescription.EscapeGenerics()).Append("<br/>")
.AppendIf(stacktrace.OriginalMethod.ILInstructions.Count > 0, $"<div><a href='javascript:;' class='headers' onclick='showHideById(this, \"{id01}\")'>+ IL:</a><div id='{id01}' class='headers-container'><pre>")
.AppendJoinIf(stacktrace.OriginalMethod.ILInstructions.Count > 0, Environment.NewLine, stacktrace.OriginalMethod.ILInstructions.Select(x => x.EscapeGenerics()).ToArray()).Append("</pre></div></div>")
.AppendIf(stacktrace.OriginalMethod.CSharpILMixedInstructions.Count > 0, $"<div><a href='javascript:;' class='headers' onclick='showHideById(this, \"{id02}\")'>+ IL with C#:</a><div id='{id02}' class='headers-container'><pre>")
.AppendJoinIf(stacktrace.OriginalMethod.CSharpILMixedInstructions.Count > 0, Environment.NewLine, stacktrace.OriginalMethod.CSharpILMixedInstructions.Select(x => x.EscapeGenerics()).ToArray()).Append("</pre></div></div>")
.AppendIf(stacktrace.OriginalMethod.CSharpInstructions.Count > 0, $"<div><a href='javascript:;' class='headers' onclick='showHideById(this, \"{id03}\")'>+ C#:</a><div id='{id03}' class='headers-container'><pre>")
.AppendJoinIf(stacktrace.OriginalMethod.CSharpInstructions.Count > 0, Environment.NewLine, stacktrace.OriginalMethod.CSharpInstructions.Select(x => x.EscapeGenerics()).ToArray()).Append("</pre></div></div>")
.AppendIf(stacktrace.OriginalMethod.ILInstructions.Count > 0, sb => sb
.Append($"<div><a href='javascript:;' class='headers' onclick='showHideById(this, \"{id01}\")'>+ IL:</a><div id='{id01}' class='headers-container'><pre>")
.AppendJoin(Environment.NewLine, stacktrace.OriginalMethod.ILInstructions.Select(x => x.EscapeGenerics()))
.Append("</pre></div></div>"))
.AppendIf(stacktrace.OriginalMethod.CSharpILMixedInstructions.Count > 0, sb => sb
.Append($"<div><a href='javascript:;' class='headers' onclick='showHideById(this, \"{id02}\")'>+ IL with C#:</a><div id='{id02}' class='headers-container'><pre>")
.AppendJoin(Environment.NewLine, stacktrace.OriginalMethod.CSharpILMixedInstructions.Select(x => x.EscapeGenerics()))
.Append("</pre></div></div>"))
.AppendIf(stacktrace.OriginalMethod.CSharpInstructions.Count > 0, sb => sb
.Append($"<div><a href='javascript:;' class='headers' onclick='showHideById(this, \"{id03}\")'>+ C#:</a><div id='{id03}' class='headers-container'><pre>")
.AppendJoin(Environment.NewLine, stacktrace.OriginalMethod.CSharpInstructions.Select(x => x.EscapeGenerics()))
.Append("</pre></div></div>"))
.Append("</li>")
.Append("</ul>");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ namespace BUTR.CrashReport.Bannerlord

using global::System.Collections.Generic;
using global::System.Linq;
using global::System.Reflection;

internal static class CrashReportShared
{
Expand Down
59 changes: 0 additions & 59 deletions src/BUTR.CrashReport.Bannerlord.Source/ImmutableArrayExtensions.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ internal static class StringBuilderExtensions
{
public static string EscapeGenerics(this string str) => str.Replace("<", "&lt;").Replace(">", "&gt;");

public static StringBuilder AppendIf(this StringBuilder builder, Func<StringBuilder, StringBuilder> lambda) => lambda(builder);

public static StringBuilder AppendJoin(this StringBuilder builder, string separator, IEnumerable<string> lines) => AppendJoinIf(builder, true, separator, lines.ToArray());
public static StringBuilder AppendJoin(this StringBuilder builder, char separator, IEnumerable<string> lines) => AppendJoinIf(builder, true, separator, lines.ToArray());
public static StringBuilder AppendJoinIf(this StringBuilder builder, bool condition, string separator, IReadOnlyList<string> lines)
Expand Down

0 comments on commit d3ba74c

Please sign in to comment.