pj64team / Project64-Legacy

Finishing what we started.
79 stars 7 forks source link

Fix some crashes in the debug tools #79

Closed parasyte closed 1 year ago

parasyte commented 1 year ago

This removes one of the two exception handlers (using SEH). This is the easy one, because it's completely outside of the critical path. None of the core emulation uses it. The "command" exception handler is specific to debug tools and cheats.

There is absolutely no use for the exception handler! It adds extra overhead (See https://preshing.com/20110807/the-cost-of-enabling-exception-handling/) just to save one or two branches. It's a headache to debug, it obscures control flow, and the x86 disassembler that it requires is notoriously incomplete and buggy.

Some people might be more concerned about the cost of those branches on the critical path, so it is not getting changed here. (Side note: any concerns about the branches on the critical path should also be just as concerned about the SEH overhead on the critical path, but let's table that conversation for now.)

This fixes a crash in the memory editor bookmarking non-RDRAM addresses and many of the debug tools in the debug build. This latter crash was pure gold caused by the EDX register randomly becoming the load destination chosen by the compiler, but the exception handler hadn't been updated for it!

I didn't want to rewrite the whole x86 disassembler that has to exist in the "CPU" exception handler... It's bad enough that the exception handler exists at all. The best solution was just to remove it.

As a nice bonus, removing the exception handler also simplifies the control flow, which is now explicit as you read the code. No surprises!