Last active
June 2, 2019 01:01
-
-
Save danmoseley/2d2add4b597c645c954772920b31e05c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define CONTRACTS_FULL | |
using System; | |
using System.Diagnostics; | |
using System.Diagnostics.Contracts; | |
using System.Reflection; | |
using System.Runtime.InteropServices; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace _1 | |
{ | |
class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
//var coreAssemblyInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(typeof(object).Assembly.Location); | |
//Console.WriteLine($"Hello World from Core {coreAssemblyInfo.ProductVersion}"); | |
//Console.WriteLine($"The location is {typeof(object).Assembly.Location}"); | |
//Console.WriteLine("hit key"); | |
//Console.Read(); | |
/* | |
c:\d\dotnet30\1\bin\Debug\netcoreapp3.0\win-x64\publish\1.exe so | |
c:\d\dotnet30\1\bin\Debug\netcoreapp3.0\win-x64\publish\1.exe oom | |
c:\d\dotnet30\1\bin\Debug\netcoreapp3.0\win-x64\publish\1.exe soe | |
c:\d\dotnet30\1\bin\Debug\netcoreapp3.0\win-x64\publish\1.exe thread | |
c:\d\dotnet30\1\bin\Debug\netcoreapp3.0\win-x64\publish\1.exe threadsoe | |
c:\d\dotnet30\1\bin\Debug\netcoreapp3.0\win-x64\publish\1.exe ff | |
c:\d\dotnet30\1\bin\Debug\netcoreapp3.0\win-x64\publish\1.exe av | |
c:\d\dotnet30\1\bin\Debug\netcoreapp3.0\win-x64\publish\1.exe ex | |
c:\d\dotnet30\1\bin\Debug\netcoreapp3.0\win-x64\publish\1.exe ff2 | |
c:\d\dotnet30\1\bin\Debug\netcoreapp3.0\win-x64\publish\1.exe con | |
c:\d\dotnet30\1\bin\Debug\netcoreapp3.0\win-x64\publish\1.exe af | |
c:\d\dotnet30\1\bin\Debug\netcoreapp3.0\win-x64\publish\1.exe af2 | |
c:\d\dotnet30\1\bin\Debug\netcoreapp3.0\win-x64\publish\1.exe teiso | |
*/ | |
X(args[0]); | |
} | |
public static unsafe void X(string arg) | |
{ | |
switch(arg) | |
{ | |
default: | |
Console.WriteLine("so ff av ex ff2 con af af2 teiso"); | |
break; | |
case "null": | |
throw null; | |
case "exnostack": | |
throw new ExceptionWithNoStack(null); | |
case "exnostackinner": | |
throw new ExceptionWithNoStack(new Exception("<innermsg>")); | |
case "so": | |
while (true) X("so"); | |
case "oom": | |
var arr = new string[Int32.MaxValue]; | |
break; | |
case "soe": | |
throw new StackOverflowException("<stackoverflowmsg>"); | |
case "thread": | |
var task = Task.Factory.StartNew(() => throw new Exception("<exceptionfromworker>")); | |
Task.WaitAll(task); | |
break; | |
case "threadsoe": | |
var task2 = Task.Factory.StartNew(() => X("so")); | |
Task.WaitAll(task2); | |
break; | |
case "threadoom": | |
var task3 = Task.Factory.StartNew(() => new string[Int32.MaxValue]); | |
Task.WaitAll(task3); | |
break; | |
case "threadnativeoom": | |
var task4 = Task.Factory.StartNew(() => Marshal.AllocHGlobal(new IntPtr(Int64.MaxValue))); | |
Task.WaitAll(task4); | |
break; | |
case "threadav": | |
var task5 = Task.Factory.StartNew(() => ((byte*)0xFFFFFFFF)[0] = 1); | |
Task.WaitAll(task5); | |
break; | |
case "ff": | |
Environment.FailFast("<reason>"); | |
break; | |
case "av": | |
((byte*)0xFFFFFFFF)[0] = 1; | |
break; | |
case "ex": | |
var ex = new Exception("<exception msg>", new NullReferenceException("<inner msg>")); | |
ex.Source = "<exception src>"; | |
throw ex; | |
case "ff2": | |
var ex2 = new Exception("<exception msg>", new NullReferenceException("<inner msg>")); | |
ex2.Source = "<exception src>"; | |
Environment.FailFast("<reason>", ex2); | |
break; | |
case "con": | |
Contract.Invariant(false); | |
break; | |
case "af": | |
Debug.Assert(false, "<assertion msg>", "<assertion detail>"); | |
break; | |
case "af2": | |
Debug.Assert(false); | |
break; | |
case "teiso": | |
typeof(Program).InvokeMember("X", BindingFlags.Static | BindingFlags.InvokeMethod | BindingFlags.Public, null, null, new[] { "so" }); | |
break; | |
} | |
} | |
} | |
public class ExceptionWithNoStack : Exception | |
{ | |
public ExceptionWithNoStack(Exception inner) | |
: base("<exmsg>", inner) | |
{ | |
} | |
public override string StackTrace | |
{ | |
get => null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment