-
-
Notifications
You must be signed in to change notification settings - Fork 204
Expand file tree
/
Copy pathProgram.cs
More file actions
67 lines (57 loc) · 2.39 KB
/
Program.cs
File metadata and controls
67 lines (57 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
namespace dotnet_signal;
using System;
using System.Runtime.InteropServices;
class Program
{
[DllImport("crash", EntryPoint = "native_crash")]
static extern void native_crash();
[DllImport("crash", EntryPoint = "enable_sigaltstack")]
static extern void enable_sigaltstack();
[DllImport("sentry", EntryPoint = "sentry_options_new")]
static extern IntPtr sentry_options_new();
[DllImport("sentry", EntryPoint = "sentry_options_set_handler_strategy")]
static extern IntPtr sentry_options_set_handler_strategy(IntPtr options, int strategy);
[DllImport("sentry", EntryPoint = "sentry_options_set_debug")]
static extern IntPtr sentry_options_set_debug(IntPtr options, int debug);
[DllImport("sentry", EntryPoint = "sentry_init")]
static extern int sentry_init(IntPtr options);
static void Main(string[] args)
{
var githubActions = Environment.GetEnvironmentVariable("GITHUB_ACTIONS") ?? string.Empty;
if (githubActions == "true") {
// Set up our own `sigaltstack` for this thread if we're running on GHA because of a failure to run any
// signal handler after the initial setup. This behavior is locally non-reproducible and likely runner-related.
// I ran this against .net7/8/9 on at least 10 different Linux setups, and it worked on all, but on GHA
// it only works if we __don't__ accept the already installed `sigaltstack`.
enable_sigaltstack();
}
// setup minimal sentry-native
var options = sentry_options_new();
sentry_options_set_handler_strategy(options, 1);
sentry_options_set_debug(options, 1);
sentry_init(options);
var doNativeCrash = args is ["native-crash"];
if (doNativeCrash)
{
native_crash();
}
else if (args.Contains("managed-exception"))
{
try
{
Console.WriteLine("dereference a NULL object from managed code");
var s = default(string);
var c = s.Length;
}
catch (NullReferenceException exception)
{
}
}
else if (args.Contains("unhandled-managed-exception"))
{
Console.WriteLine("dereference a NULL object from managed code (unhandled)");
var s = default(string);
var c = s.Length;
}
}
}