Grab stacktrace on signal.

This commit is contained in:
Deukhoofd 2020-08-18 19:26:39 +02:00
parent c852824c91
commit 59b4223d18
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
9 changed files with 46 additions and 8 deletions

View File

@ -10,5 +10,14 @@ namespace Arbutils.Generated
[DllImport("Arbutils", CallingConvention = CallingConvention.Cdecl, EntryPoint= "Arbutils_C_GetLastException")] [DllImport("Arbutils", CallingConvention = CallingConvention.Cdecl, EntryPoint= "Arbutils_C_GetLastException")]
internal static extern IntPtr GetLastException(); internal static extern IntPtr GetLastException();
/// <param name="callback">Function *</param>
/// <returns>void</returns>
[DllImport("Arbutils", CallingConvention = CallingConvention.Cdecl, EntryPoint= "Arbutils_C_SetSignalCallback")]
internal static extern void SetSignalCallback(IntPtr callback);
/// <returns>void</returns>
[DllImport("Arbutils", CallingConvention = CallingConvention.Cdecl, EntryPoint= "Arbutils_C_RaiseSignal")]
internal static extern void RaiseSignal();
} }
} }

View File

@ -14,5 +14,9 @@ namespace Creaturelib.Generated
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_C_GetLastExceptionStacktrace")] [DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_C_GetLastExceptionStacktrace")]
internal static extern IntPtr GetLastExceptionStacktrace(); internal static extern IntPtr GetLastExceptionStacktrace();
/// <returns>void</returns>
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_C_RaiseSignal")]
internal static extern void RaiseSignal();
} }
} }

BIN
PkmnLibSharp/Native/libArbutils.so (Stored with Git LFS)

Binary file not shown.

BIN
PkmnLibSharp/Native/libCreatureLib.so (Stored with Git LFS)

Binary file not shown.

BIN
PkmnLibSharp/Native/libpkmnLib.so (Stored with Git LFS)

Binary file not shown.

View File

@ -0,0 +1,22 @@
using System;
using System.Runtime.InteropServices;
namespace PkmnLibSharp.Utilities
{
public static class SignalHandler
{
public delegate void SignalDelegate(string s);
private delegate void InternalSignalDelegate(IntPtr ptr);
private static InternalSignalDelegate? _internalSignalDelegate;
public static void SetSignalListener(SignalDelegate del)
{
_internalSignalDelegate = ptr =>
{
del(ptr.PtrString()!);
};
Arbutils.Generated.C.SetSignalCallback(Marshal.GetFunctionPointerForDelegate(_internalSignalDelegate));
}
}
}

View File

@ -1 +1 @@
{"enums":[{"byteSize":4,"filename":"Arbutils","name":"float_denorm_style","values":{"-1":"denorm_indeterminate","0":"denorm_absent","1":"denorm_present"}},{"byteSize":4,"filename":"Arbutils","name":"float_round_style","values":{"-1":"round_indeterminate","0":"round_toward_zero","1":"round_to_nearest","2":"round_toward_infinity","3":"round_toward_neg_infinity"}}],"functions":[{"filename":"Arbutils","name":"Arbutils_C_GetLastException","parameters":[],"returns":"const char *"},{"filename":"Arbutils","name":"Arbutils_Random_Construct","parameters":[],"returns":"Random *"},{"filename":"Arbutils","name":"Arbutils_Random_ConstructWithSeed","parameters":[{"name":"seed","type":"long unsigned int"}],"returns":"Random *"},{"filename":"Arbutils","name":"Arbutils_Random_Destruct","parameters":[{"name":"p","type":"Random *"}],"returns":"void"},{"filename":"Arbutils","name":"Arbutils_Random_GetFloat","parameters":[{"name":"p","type":"Random *"}],"returns":"float"},{"filename":"Arbutils","name":"Arbutils_Random_GetDouble","parameters":[{"name":"p","type":"Random *"}],"returns":"double"},{"filename":"Arbutils","name":"Arbutils_Random_Get","parameters":[{"name":"p","type":"Random *"}],"returns":"int"},{"filename":"Arbutils","name":"Arbutils_Random_GetWithMax","parameters":[{"name":"p","type":"Random *"},{"name":"max","type":"int"},{"name":"out","type":"int &"}],"returns":"unsigned char"},{"filename":"Arbutils","name":"Arbutils_Random_GetInLimits","parameters":[{"name":"p","type":"Random *"},{"name":"min","type":"int"},{"name":"max","type":"int"},{"name":"out","type":"int &"}],"returns":"unsigned char"},{"filename":"Arbutils","name":"Arbutils_Random_GetUnsigned","parameters":[{"name":"p","type":"Random *"}],"returns":"unsigned int"},{"filename":"Arbutils","name":"Arbutils_Random_GetUnsignedWithMax","parameters":[{"name":"p","type":"Random *"},{"name":"max","type":"unsigned int"},{"name":"out","type":"unsigned int &"}],"returns":"unsigned char"},{"filename":"Arbutils","name":"Arbutils_Random_GetUnsignedInLimits","parameters":[{"name":"p","type":"Random *"},{"name":"min","type":"unsigned int"},{"name":"max","type":"unsigned int"},{"name":"out","type":"unsigned int &"}],"returns":"unsigned char"},{"filename":"Arbutils","name":"Arbutils_Random_GetSeed","parameters":[{"name":"p","type":"Random *"}],"returns":"long unsigned int"}]} {"enums":[{"byteSize":4,"filename":"Arbutils","name":"float_denorm_style","values":{"-1":"denorm_indeterminate","0":"denorm_absent","1":"denorm_present"}},{"byteSize":4,"filename":"Arbutils","name":"float_round_style","values":{"-1":"round_indeterminate","0":"round_toward_zero","1":"round_to_nearest","2":"round_toward_infinity","3":"round_toward_neg_infinity"}}],"functions":[{"filename":"Arbutils","name":"Arbutils_C_GetLastException","parameters":[],"returns":"const char *"},{"filename":"Arbutils","name":"Arbutils_C_SetSignalCallback","parameters":[{"name":"callback","type":"Function *"}],"returns":"void"},{"filename":"Arbutils","name":"Arbutils_C_RaiseSignal","parameters":[],"returns":"void"},{"filename":"Arbutils","name":"Arbutils_Random_Construct","parameters":[],"returns":"Random *"},{"filename":"Arbutils","name":"Arbutils_Random_ConstructWithSeed","parameters":[{"name":"seed","type":"long unsigned int"}],"returns":"Random *"},{"filename":"Arbutils","name":"Arbutils_Random_Destruct","parameters":[{"name":"p","type":"Random *"}],"returns":"void"},{"filename":"Arbutils","name":"Arbutils_Random_GetFloat","parameters":[{"name":"p","type":"Random *"}],"returns":"float"},{"filename":"Arbutils","name":"Arbutils_Random_GetDouble","parameters":[{"name":"p","type":"Random *"}],"returns":"double"},{"filename":"Arbutils","name":"Arbutils_Random_Get","parameters":[{"name":"p","type":"Random *"}],"returns":"int"},{"filename":"Arbutils","name":"Arbutils_Random_GetWithMax","parameters":[{"name":"p","type":"Random *"},{"name":"max","type":"int"},{"name":"out","type":"int &"}],"returns":"unsigned char"},{"filename":"Arbutils","name":"Arbutils_Random_GetInLimits","parameters":[{"name":"p","type":"Random *"},{"name":"min","type":"int"},{"name":"max","type":"int"},{"name":"out","type":"int &"}],"returns":"unsigned char"},{"filename":"Arbutils","name":"Arbutils_Random_GetUnsigned","parameters":[{"name":"p","type":"Random *"}],"returns":"unsigned int"},{"filename":"Arbutils","name":"Arbutils_Random_GetUnsignedWithMax","parameters":[{"name":"p","type":"Random *"},{"name":"max","type":"unsigned int"},{"name":"out","type":"unsigned int &"}],"returns":"unsigned char"},{"filename":"Arbutils","name":"Arbutils_Random_GetUnsignedInLimits","parameters":[{"name":"p","type":"Random *"},{"name":"min","type":"unsigned int"},{"name":"max","type":"unsigned int"},{"name":"out","type":"unsigned int &"}],"returns":"unsigned char"},{"filename":"Arbutils","name":"Arbutils_Random_GetSeed","parameters":[{"name":"p","type":"Random *"}],"returns":"long unsigned int"}]}

File diff suppressed because one or more lines are too long

View File

@ -3,6 +3,7 @@ using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using NUnit.Framework; using NUnit.Framework;
using PkmnLibSharp.Battling; using PkmnLibSharp.Battling;
using PkmnLibSharp.Utilities;
namespace PkmnLibSharpTests namespace PkmnLibSharpTests
{ {
@ -20,6 +21,8 @@ namespace PkmnLibSharpTests
{ {
Console.WriteLine($"[{level.ToString().ToUpperInvariant()}] {s}"); Console.WriteLine($"[{level.ToString().ToUpperInvariant()}] {s}");
}); });
SignalHandler.SetSignalListener(s => throw new Exception("Encountered a catastrophic signal. \n" + s));
} }
} }
} }