Added missing guards to prevent attempts to write debug information when none was requested.