Introduce a memory shutdown lock.

This allows the debugger to access memory in a safe way that should never
crash.
Merge pull request #6586 from unknownbrackets/debugger

Introduce a memory shutdown lock