Inspired by a Mike Hearn comment on #3276 -- adds a couple of mutex-related routines:
AssertLockHeld("cs_foo") : if compiled -DDEBUG_LOCKORDER, walks the lock stack and makes sure the specified lock is held. If not, a message and the list of locks that ARE held are LogPrintf'ed and then assert(0) is called. Does nothing in normal builds.
LocksHeld() : -DDEBUG_LOCKORDER-only routine: returns a human-readable string with all of the locks held. This can be very handy to call from within an interactive debugging session (and it is used by AssertLockHeld).
I added AssertLockHeld("cs_main") to ProcessBlock as proof-of-concept; if we like this, adding AssertLockHeld calls to more routines can be done in subsequent pulls.
PS: compiling with -DDEBUG_LOCKORDER in the new autotools-world means a 'make clean' and then something like: CXXFLAGS='-DDEBUG_LOCKORDER' ./configure ...