diff options
author | Alexis Christoforides <alexis@thenull.net> | 2020-06-12 05:45:12 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-12 05:45:12 +0300 |
commit | 540da38191e5889a3d5d2316e4e45750c0d29c44 (patch) | |
tree | 3d3859ec1b443982ac3ec2899034d79b93602b36 /mcs | |
parent | e51b4af9cd87b1a36022d7d774d7c1e98b65bdfd (diff) |
[merp] Add API methods for getting hashcode/reason of last crash (#19901)
* [merp] Add API methods for getting hashcode/reason of last crash
* Add test
* Review feedback and cleanup
Diffstat (limited to 'mcs')
-rw-r--r-- | mcs/class/corlib/Mono/Runtime.cs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/mcs/class/corlib/Mono/Runtime.cs b/mcs/class/corlib/Mono/Runtime.cs index 13f1bad8d31..4a181f9721f 100644 --- a/mcs/class/corlib/Mono/Runtime.cs +++ b/mcs/class/corlib/Mono/Runtime.cs @@ -27,6 +27,7 @@ // using System; +using System.IO; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -263,6 +264,43 @@ namespace Mono { } } + static string get_breadcrumb_value (string file_prefix, string directory_str, bool clear) + { + var allfiles = Directory.GetFiles (directory_str, $"{file_prefix}_*" ); + if (allfiles.Length == 0) + return string.Empty; + + if (allfiles.Length > 1) { + // it's impossible to tell which breadcrumb is the last one (let's not trust filesystem timestamps) + // delete the multiple files so at least next crash can make sense + try { + Array.ForEach (allfiles, f => File.Delete (f) ); + } catch (Exception) { } + + return string.Empty; + } + + if (clear) + File.Delete (allfiles [0]); + + var filename = Path.GetFileName (allfiles [0]); + return filename.Substring (file_prefix.Length + 1); + } + + static long CheckCrashReportHash (string directory_str, bool clear) + { + var value = get_breadcrumb_value ("crash_hash", directory_str, clear); + if (value == string.Empty) + return 0; + else + return Convert.ToInt64 (value, 16); + } + + static string CheckCrashReportReason (string directory_str, bool clear) + { + return get_breadcrumb_value ("crash_reason", directory_str, clear); + } + [MethodImplAttribute (MethodImplOptions.InternalCall)] static extern void AnnotateMicrosoftTelemetry_internal (IntPtr key, IntPtr val); |