Last active
October 23, 2022 15:23
-
-
Save jbevain/37d5b1ad0cd3f0ff0eec223df6f28fd8 to your computer and use it in GitHub Desktop.
This file contains 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
using System.Net; | |
using Mono.Debugger.Soft; | |
using static System.Console; | |
static int PidToPort(int pid) => 56000 + (pid % 1000); | |
var pid = 49149; // process ID of the Unity Editor or the IL2CPP Game | |
var ip = IPAddress.Loopback; // IP where the Unity Editor/Game is running | |
var endPoint = new IPEndPoint(ip, PidToPort(pid)); | |
var vm = VirtualMachineManager.Connect(endPoint); | |
var exceptionRequest = vm.CreateExceptionRequest(exc_type: null, caught: true, uncaught: true); | |
exceptionRequest.Enable(); | |
var pumpSignal = true; | |
var eventPump = new Thread(() => | |
{ | |
while (pumpSignal) | |
{ | |
var eventSet = vm.GetNextEventSet(); | |
if (eventSet[0] is ExceptionEvent exceptionEvent) | |
{ | |
WriteLine($"Exception: {exceptionEvent.Exception.Type.FullName}"); | |
WriteLine($"StackTrace:"); | |
foreach (var frame in exceptionEvent.Thread.GetFrames()) | |
{ | |
WriteLine(frame.Location); | |
} | |
vm.Resume(); | |
} | |
} | |
}); | |
eventPump.Start(); | |
WriteLine("Press enter to quit"); | |
ReadLine(); | |
pumpSignal = false; | |
vm.Detach(); | |
WriteLine("Bye now"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compile against the
Mono.Debugger.Soft.dll
assembly that comes with your Mono installation. Unity ships with a local Mono installation.