Add support for debugging on old net35 mono #60
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
After a ton of research, I figured out how to add support for debugging on old mono that targets net35. A Unity game may ship with depending on the Unity version:
Adding this feature also fixes a regression from Doorstop 3 where it was no longer possible to debug using dnspy on these old mono because Doorstop 4 tried to enable the debugger and failed since it wasn't supported. Now, not only this works, but it no longer requires to have a patched mono.
To detect the mono, this was rather simple because checking the sources of unity's mono, I found old mono's runtime string can only start with v1 or v2 while new mono cannot and will typically start with v4. It just so happens that jit_init_version receives that string so I used it to detect which mono we are dealing with.
As for how this was done, old mono requires a different ordering of when to call jit_init_version where it must be called later than what you'll do on new mono. Since Doorstop was always doing what worked on new mono, it was crashing. After inspecting a development player of unity 5.5.4, I found that it would call debug_init right after jit_parse_options was called. What doorstop was doing is call jit_init_version right after debug_init, but it should have done it the other way around for old mono.
There was one last detail to handle: the protocol changed slightly such that to opt out of the suspend feature, it needs to have
defer=y
on top of the usualsuspend=n
. I simply changed the text it appends to accommodate depending on the mono used.I did a bunch of tests with this using dnspy and 3 IDEs and everything seems to work on both old and new mono. That being said, I wanted to test the capabilities of this since I find this to be quite a huge deal so I did some more indepth tests and here's what I found:
Due to the fact this pr also fixes a regression, I recommend that a release of doorstop is made with it (I can then send a pr to bepinex v5 and v6 so it gets the fix and the feature).