save/restore debug flag on non-global environments