This function returns whether The Debug Overlay is currently open or not.
is_debug_overlay_open();
var _open = is_debug_overlay_open();
show_debug_overlay(!_open);
The above code first calls is_debug_overlay_open and assigns the result to a temporary variable _open. It then toggles the debug overlay by passing the negated value to show_debug_overlay.