Skip to content

Commit

Permalink
Another flag for the stacktrace decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
eggrobin committed Aug 23, 2024
1 parent e3e538c commit 81dec48
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions stacktrace_decoder/stacktrace_decoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ private static Int64 GetBaseAddress(bool unity_crash,
@":.*\] Base address is ([0-9A-F]+)$");
Match base_address_match;
do {
Check(!stream.EndOfStream, $"Could not find base address");
base_address_match = base_address_regex.Match(stream.ReadLine());
} while (!base_address_match.Success);
string base_address_string = base_address_match.Groups[1].ToString();
Expand Down Expand Up @@ -100,6 +101,7 @@ private static string Comment(string comment) {
}

private static void Main(string[] args) {
Int64? base_address_override = null;
bool unity_crash = false;
Func<string, string> comment = Comment;
bool snippets = true;
Expand All @@ -114,15 +116,20 @@ private static void Main(string[] args) {

for (int i = 2; i < args.Length; ++i) {
string flag = args[i];
var match = Regex.Match(flag, "--unity-crash-at-commit=([0-9a-f]{40})");
if (!unity_crash && match.Success) {
var base_address_match = Regex.Match(flag, "--base-address=(0x[0-9A-F]+)");
var unity_crash_match = Regex.Match(flag, "--unity-crash-at-commit=([0-9a-f]{40})");
if (!base_address_override.HasValue && base_address_match.Success) {
base_address_override = Convert.ToInt64(
base_address_match.Groups[1].ToString(), 16);
} else if (!unity_crash && unity_crash_match.Success) {
unity_crash = true;
commit = match.Groups[1].ToString();
commit = unity_crash_match.Groups[1].ToString();
} else if (snippets && flag == "--no-snippet") {
snippets = false;
} else if (comment == Comment && flag == "--no-comment") {
comment = (_) => "";
} else {
Console.WriteLine($"Unrecognized argument {flag}");
PrintUsage();
return;
}
Expand All @@ -148,7 +155,7 @@ private static void Main(string[] args) {
$"Warning: version is dirty; line numbers may be incorrect."));
}
}
Int64 principia_base_address = GetBaseAddress(
Int64 principia_base_address = base_address_override ?? GetBaseAddress(
unity_crash,
@"(?i)GameData\\Principia\\x64\\principia.dll:principia.dll " +
@"\(([0-9A-F]+)\)",
Expand All @@ -162,14 +169,16 @@ private static void Main(string[] args) {
if (unity_crash) {
Match stack_start_match;
do {
stack_start_match =
Regex.Match(stream.ReadLine(),
@"========== OUTPUTT?ING STACK TRACE ==================");
stack_start_match = Regex.Match(
stream.ReadLine(),
@"={10} OUTPUTT?ING STACK TRACE ={10}|Stack Trace of Crashed Thread");
} while (!stack_start_match.Success);
}
string log_line;
Match stack_match;
do {
Check(!stream.EndOfStream,
$"Could not find stack trace in {info_file_uri}");
log_line = stream.ReadLine();
stack_match = stack_regex.Match(log_line);
} while (!stack_match.Success);
Expand All @@ -194,7 +203,8 @@ private static void Main(string[] args) {
for (;
stack_match.Success ||
(unity_crash &&
!Regex.IsMatch(log_line, "========== END OF STACKTRACE ==========="));
!Regex.IsMatch(log_line,
"={10} END OF STACKTRACE ={10}|Stacks for Running Threads:"));
log_line = stream.ReadLine(), stack_match = stack_regex.Match(log_line)) {
if (!stack_match.Success) {
continue;
Expand Down Expand Up @@ -244,8 +254,16 @@ private static void Main(string[] args) {

private static void PrintUsage() {
Console.WriteLine("Usage: stacktrace_decoder " +
"<info_file_uri> <principia_dll_directory> " +
"[--unity-crash-at-commit=<sha1>] " +
"<INFO log> <principia_dll_directory> " +
"[--no-comment] [--no-snippet]");
Console.WriteLine(" stacktrace_decoder " +
"<Player.log> <principia_dll_directory> " +
"--unity-crash-at-commit=<sha1> " +
"[--no-comment] [--no-snippet]");
Console.WriteLine(" stacktrace_decoder " +
"<error.log> <principia_dll_directory> " +
"--unity-crash-at-commit=<sha1> " +
"--base-address=0x<hex> " +
"[--no-comment] [--no-snippet]");
}
}
Expand Down

0 comments on commit 81dec48

Please sign in to comment.