Merge DebugCrash branch into master.

This gets all the bug fixes introduced as part of the bug hunt, but avoids the commented out code and disabled parts.

Includes Affinty flag setting code, and new logging.