Skip to content

Commit

Permalink
Added Parser for legacy reports
Browse files Browse the repository at this point in the history
Removed some Properties since they are redundant
  • Loading branch information
Aragas committed Oct 2, 2023
1 parent e6d7b2a commit 35b113a
Show file tree
Hide file tree
Showing 9 changed files with 542 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<IsPackable>true</IsPackable>
</PropertyGroup>

<PropertyGroup>
<ILRepackTargetConfigurations>Debug;Release</ILRepackTargetConfigurations>
<ILRepackAllowDuplicateResources>false</ILRepackAllowDuplicateResources>
<ILRepackMergeDebugSymbols>true</ILRepackMergeDebugSymbols>
<ILRepackPerformInternalize>true</ILRepackPerformInternalize>
<ILRepackCopyAttributes>false</ILRepackCopyAttributes>
<ILRepackBuildToolingPath>$(PkgBUTR_ILRepack)\tools\net461\ILRepack.exe</ILRepackBuildToolingPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ILRepack" Version="2.0.18" PrivateAssets="all" IncludeAssets="none" />
<PackageReference Include="BUTR.ILRepack" Version="2.1.9-beta7" GeneratePathProperty="true" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<PackageReference Include="ILRepack.FullAuto" Version="1.2.0" PrivateAssets="all" />
</ItemGroup>

<PropertyGroup>
<PackageId>BUTR.CrashReport.Bannerlord.Parser</PackageId>
<Title>BUTR.CrashReport.Bannerlord.Parser</Title>
<Description>Contains the models for parsing the crash report</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageIconUrl>https://raw.githubusercontent.com/BUTR/BUTR.CrashReport/master/assets/Icon128x128.png</PackageIconUrl>
<PackageTags>butr crash report bannerlord</PackageTags>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.11.53" />
<PackageReference Include="Polyfill" Version="1.28.0" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<PackageReference Include="System.Collections.Immutable" Version="7.0.0" />
<PackageReference Include="System.Memory" Version="4.5.5" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BUTR.CrashReport\BUTR.CrashReport.csproj" />
</ItemGroup>

<Target Name="ExcludeAssembliesFromILRepack" BeforeTargets="ILRepackPrepare">
<PropertyGroup>
<ILRepackExcludeAssemblies>$(ILRepackExcludeAssemblies);$(ProjectDir)$(OutputPath)BUTR.CrashReport.dll;</ILRepackExcludeAssemblies>
</PropertyGroup>
</Target>


</Project>
434 changes: 434 additions & 0 deletions src/BUTR.CrashReport.Bannerlord.Parser/CrashReportParser.cs

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions src/BUTR.CrashReport.Bannerlord.Source/CrashReportCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private static ImmutableArray<InvolvedModuleModel> GetInvolvedModuleList(CrashRe
builder.Add(new()
{
Id = module.Id,
Stacktrace = string.Join(Environment.NewLine, stacktrace.Select(x => x.Method.FullDescription())),
EnhancedStacktraceFrameName = stacktrace.Last().StackFrameDescription,
AdditionalMetadata = ImmutableArray<MetadataModel>.Empty,
});
}
Expand Down Expand Up @@ -249,9 +249,8 @@ private static ImmutableArray<ModuleModel> GetModuleList(CrashReportInfo crashRe
DependencyMetadatas = module.DependenciesAllDistinct().Select(x => new ModuleDependencyMetadataModel
{
ModuleId = x.Id,
Type = (ModuleDependencyMetadataModelType) x.LoadType,
Type = x.IsIncompatible ? ModuleDependencyMetadataModelType.Incompatible : (ModuleDependencyMetadataModelType) x.LoadType,
IsOptional = x.IsOptional,
IsIncompatible = x.IsIncompatible,
Version = !x.Version.Equals(ApplicationVersion.Empty) ? x.Version.ToString() : null,
VersionRange = !x.VersionRange.Equals(ApplicationVersionRange.Empty) ? x.VersionRange.ToString() : null,
AdditionalMetadata = ImmutableArray<MetadataModel>.Empty,
Expand All @@ -265,7 +264,14 @@ private static ImmutableArray<ModuleModel> GetModuleList(CrashReportInfo crashRe
.Concat(x.Tags.SelectMany(y => y.Value.Select(z => new MetadataModel { Key = y.Key, Value = z })))
.ToImmutableArray(),
}).ToImmutableArray(),
AdditionalMetadata = ImmutableArray.Create<MetadataModel>(new MetadataModel { Key = "METADATA:MANAGED_BY_VORTEX", Value = isManagedByVortex.ToString()}),
AdditionalMetadata = ImmutableArray.Create<MetadataModel>(new MetadataModel { Key = "METADATA:MANAGED_BY_VORTEX", Value = isManagedByVortex.ToString()}).AddRange(crashReport.AvailableAssemblies.Select(x =>
{
if (ModuleInfoHelper.IsModuleAssembly(module, x.Value))
{
return new MetadataModel { Key = "METADATA:AdditionalAssembly", Value = $"{Path.GetFileName(x.Value.CodeBase)} ({x.Key.ToString()})", };
}
return null;
}).OfType<MetadataModel>()),
});
}

Expand Down Expand Up @@ -314,11 +320,9 @@ static string CalculateMD5(string filename)
FullName = assembly.ToString(),
Version = assemblyName.Version.ToString(),
Architecture = assemblyName.ProcessorArchitecture.ToString(),
Hash = assembly.IsDynamic || string.IsNullOrWhiteSpace(assembly.Location) || !File.Exists(assembly.Location) ? "" : CalculateMD5(assembly.Location),
Hash = assembly.IsDynamic || string.IsNullOrWhiteSpace(assembly.Location) || !File.Exists(assembly.Location) ? string.Empty : CalculateMD5(assembly.Location),
Path = assembly.IsDynamic ? "DYNAMIC" : string.IsNullOrWhiteSpace(assembly.Location) ? "EMPTY" : !File.Exists(assembly.Location) ? "MISSING" : assembly.Location,
Type = type,
ModuleId = module?.Id,
SubModuleId = null,
AdditionalMetadata = ImmutableArray<MetadataModel>.Empty,
});
}
Expand Down
76 changes: 39 additions & 37 deletions src/BUTR.CrashReport.Bannerlord.Source/CrashReportHtmlRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ namespace BUTR.CrashReport.Bannerlord

internal static class CrashReportHtmlRenderer
{
public static readonly string MiniDumpTag = "<!-- MINI DUMP -->";
public static readonly string MiniDumpButtonTag = "<!-- MINI DUMP BUTTON -->";
public static readonly string SaveFileTag = "<!-- SAVE FILE -->";
public static readonly string SaveFileButtonTag = "<!-- SAVE FILE BUTTON -->";
public static readonly string ScreenshotTag = "<!-- SCREENSHOT -->";
public static readonly string ScreenshotButtonTag = "<!-- SCREENSHOT BUTTON -->";
public static readonly string DecompressScriptTag = "<!-- DECOMPRESS SCRIPT -->";
public static readonly string JsonModelDataTag = "<!-- JSON MODEL -->";
private static readonly string MiniDumpTag = "<!-- MINI DUMP -->";
private static readonly string MiniDumpButtonTag = "<!-- MINI DUMP BUTTON -->";
private static readonly string SaveFileTag = "<!-- SAVE FILE -->";
private static readonly string SaveFileButtonTag = "<!-- SAVE FILE BUTTON -->";
private static readonly string ScreenshotTag = "<!-- SCREENSHOT -->";
private static readonly string ScreenshotButtonTag = "<!-- SCREENSHOT BUTTON -->";
private static readonly string DecompressScriptTag = "<!-- DECOMPRESS SCRIPT -->";
private static readonly string JsonModelDataTag = "<!-- JSON MODEL -->";

#pragma warning disable format // @formatter:off
private static readonly string Scripts = """
Expand Down Expand Up @@ -492,35 +492,39 @@ private static string GetInvolvedModuleListHtml(CrashReportModel crashReport)
{
var sb = new StringBuilder();
sb.Append("<ul>");
foreach (var stacktrace in crashReport.EnhancedStacktrace)
foreach (var grouping in crashReport.EnhancedStacktrace.GroupBy(x => x.OriginalMethod.Module))
{
var moduleId = stacktrace.OriginalMethod.Module;
var moduleId = grouping.Key;
if (moduleId == "UNKNOWN") continue;

sb.Append("<li>")
.Append($"<a href='javascript:;' onclick='document.getElementById(\"{moduleId}\").scrollIntoView(false)'>").Append(moduleId).Append("</a>").Append("<br/>")
.Append("Method: ").Append(stacktrace.OriginalMethod.MethodFullName).Append("<br/>")
.Append("Frame: ").Append(stacktrace.FrameDescription).Append("<br/>")
.Append("Method From Stackframe Issue: ").Append(stacktrace.MethodFromStackframeIssue).Append("<br/>")
.Append("</li>");
.Append($"<a href='javascript:;' onclick='document.getElementById(\"{moduleId}\").scrollIntoView(false)'>").Append(moduleId).Append("</a>").Append("<br/>");

if (stacktrace.PatchMethods.Count > 0)
foreach (var stacktrace in grouping)
{
sb.Append("Patches:").Append("<br/>")
.Append("<ul>");
foreach (var method in stacktrace.PatchMethods)
sb.Append("Method: ").Append(stacktrace.OriginalMethod.MethodFullName).Append("<br/>")
.Append("Frame: ").Append(stacktrace.FrameDescription).Append("<br/>");

if (stacktrace.PatchMethods.Count > 0)
{
// Ignore blank transpilers used to force the jitter to skip inlining
if (method.Method == "BlankTranspiler") continue;
sb.Append("<li>")
.Append($"Module: ").Append(method.Module ?? "UNKNOWN").Append("<br/>")
.Append($"Method: ").Append(method.MethodFullName).Append("<br/>")
.Append("</li>");
sb.Append("Patches:").Append("<br/>")
.Append("<ul>");
foreach (var method in stacktrace.PatchMethods)
{
// Ignore blank transpilers used to force the jitter to skip inlining
if (method.Method == "BlankTranspiler") continue;
sb.Append("<li>")
.Append($"Module: ").Append(method.Module ?? "UNKNOWN").Append("<br/>")
.Append($"Method: ").Append(method.MethodFullName).Append("<br/>")
.Append("</li>");
}
sb.Append("</ul>");
}
sb.Append("</ul>");
}

sb.Append("</br>");
sb.Append("</br>");

sb.Append("</li>");
}

sb.Append("</li>");
}
Expand All @@ -545,7 +549,7 @@ void AppendDependencies(ModuleModel module)
{
var hasVersion = !string.IsNullOrEmpty(dependentModule.Version);
var hasVersionRange = !string.IsNullOrEmpty(dependentModule.VersionRange);
if (dependentModule.IsIncompatible)
if (dependentModule.Type == ModuleDependencyMetadataModelType.Incompatible)
{
deps[dependentModule.ModuleId] = tmp.Clear()
.Append("Incompatible ")
Expand Down Expand Up @@ -629,12 +633,12 @@ void AppendSubModules(ModuleModel module)
void AppendAdditionalAssemblies(ModuleModel module)
{
additionalAssembliesBuilder.Clear();
foreach (var externalLoadedAssembly in crashReport.Assemblies)
foreach (var kv in module.AdditionalMetadata.Where(x => x.Key.Equals("METADATA:AdditionalAssembly")))
{
if (externalLoadedAssembly.ModuleId == module.Id)
{
additionalAssembliesBuilder.Append("<li>").Append(Path.GetFileName(externalLoadedAssembly.Path)).Append(" (").Append(externalLoadedAssembly.FullName).Append(")").Append("</li>");
}
var splt = kv.Value.Split(" (");
var fullName = splt[1].TrimEnd(')');
var assembly = crashReport.Assemblies.FirstOrDefault(x => fullName.StartsWith(x.FullName));
additionalAssembliesBuilder.Append("<li>").Append(assembly.Name).Append(" (").Append(assembly.FullName).Append(")").Append("</li>");
}
}

Expand Down Expand Up @@ -697,8 +701,6 @@ private static string GetAssemblyListHtml(CrashReportModel crashReport)

void AppendAssembly(AssemblyModel assembly)
{
var isModule = assembly.ModuleId is not null;

var @class = string.Join(" ", assembly.Type.GetFlags().Select(x => x switch
{
AssemblyModelType.Dynamic => "dynamic_assembly",
Expand Down Expand Up @@ -798,7 +800,7 @@ private static string GetLogFilesListHtml(IEnumerable<LogSource> files)
{
var toAppend = (longestType - logEntry.Type.Length) + 1;
var style = logEntry.Level == "ERR" ? "color:red" : logEntry.Level == "WRN" ? "color:orange" : "";
sb.Append(logEntry.Date.ToString("u")).Append(" [").Append(logEntry.Type).Append(']').Append(' ', toAppend).Append('[').Append("<span style ='").Append(style).Append("'>").Append(logEntry.Level).Append("</span>").Append("]: ").Append(logEntry.Message);
sb.Append(logEntry.Date.ToString("u")).Append(" [").Append(logEntry.Type).Append(']').Append(' ', toAppend).Append('[').Append("<span style ='").Append(style).Append("'>").Append(logEntry.Level).Append("</span>").Append("]: ").Append(logEntry.Message).AppendLine();
}
sb.Append("</pre>").Append("</ul></li>");
}
Expand Down
7 changes: 7 additions & 0 deletions src/BUTR.CrashReport.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{56E6B143
..\build\common.props = ..\build\common.props
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BUTR.CrashReport.Bannerlord.Parser", "BUTR.CrashReport.Bannerlord.Parser\BUTR.CrashReport.Bannerlord.Parser.csproj", "{51A4BB52-A8E0-4BC3-8476-23E272413954}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -33,6 +35,10 @@ Global
{80698068-7B95-487A-9DD8-E02DE27127AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{80698068-7B95-487A-9DD8-E02DE27127AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{80698068-7B95-487A-9DD8-E02DE27127AC}.Release|Any CPU.Build.0 = Release|Any CPU
{51A4BB52-A8E0-4BC3-8476-23E272413954}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{51A4BB52-A8E0-4BC3-8476-23E272413954}.Debug|Any CPU.Build.0 = Debug|Any CPU
{51A4BB52-A8E0-4BC3-8476-23E272413954}.Release|Any CPU.ActiveCfg = Release|Any CPU
{51A4BB52-A8E0-4BC3-8476-23E272413954}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -43,5 +49,6 @@ Global
GlobalSection(NestedProjects) = preSolution
{B1100D38-D4C9-4B83-96BC-2252449A89E5} = {8013DEFB-F940-4891-9F74-BFE1A8106506}
{80698068-7B95-487A-9DD8-E02DE27127AC} = {8013DEFB-F940-4891-9F74-BFE1A8106506}
{51A4BB52-A8E0-4BC3-8476-23E272413954} = {8013DEFB-F940-4891-9F74-BFE1A8106506}
EndGlobalSection
EndGlobal
2 changes: 0 additions & 2 deletions src/BUTR.CrashReport/Models/AssemblyModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ public record AssemblyModel
public required string Hash { get; set; }
public required string Path { get; set; }
public required AssemblyModelType Type { get; set; }
public required string? ModuleId { get; set; }
public required string? SubModuleId { get; set; }
public required IReadOnlyList<MetadataModel> AdditionalMetadata { get; set; } = new List<MetadataModel>();
}
2 changes: 1 addition & 1 deletion src/BUTR.CrashReport/Models/InvolvedModuleModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace BUTR.CrashReport.Models;
public record InvolvedModuleModel
{
public required string Id { get; set; }
public required string Stacktrace { get; set; }
public required string EnhancedStacktraceFrameName { get; set; }
public required IReadOnlyList<MetadataModel> AdditionalMetadata { get; set; } = new List<MetadataModel>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public record ModuleDependencyMetadataModel
public required string ModuleId { get; set; }
public required ModuleDependencyMetadataModelType Type { get; set; }
public required bool IsOptional { get; set; }
public required bool IsIncompatible { get; set; }
public required string? Version { get; set; }
public required string? VersionRange { get; set; }
public required IReadOnlyList<MetadataModel> AdditionalMetadata { get; set; } = new List<MetadataModel>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ public enum ModuleDependencyMetadataModelType
{
LoadBefore = 1,
LoadAfter = 2,
Incompatible = 3,
}

0 comments on commit 35b113a

Please sign in to comment.