[][src]Function bugsalot::debugger::state

pub fn state() -> State

What is the current state of the debugger, with regards to this process? Attached? Detatched? Unknown?

Platforms

PlatformStateNotes
WindowsOK
AndroidOK
LinuxOKSome versions of Windows Subsystem for Linux incorrectly report Detatched
FreeBSDOK?Untested
NetBSDOK?Untested
OS XOK?Untested
iOSOK?Untested
WASMN/AReturns Unknown. We could try to detect if devtools are open, but that's a browser specific mess, and you can usually get away with just invoking debugger;. That said, pull requests welcome.

KNOWN BUGS:

  • On some versions of Windows Subsystem for Linux, TracerPid may incorrectly be 0 when a debugger is attached, leading us to incorrectly report Detatched. If you encounter such a version, please file an issue that includes the result of cat /proc/version, so I can add version detection to report Unknown for affected versions.

Examples

use bugsalot::debugger;
 
match debugger::state() {
    debugger::State::Detatched  => println!("No debugger attached"),
    debugger::State::Attached   => println!("A debugger is attached"),
    debugger::State::Unknown    => println!("A debugger may or may not be attached"),
}
 
if cfg!(any(windows, target_os = "android", target_os = "linux")) {
    // Platform should be supported
    assert_ne!(debugger::state(), debugger::State::Unknown)
} else if cfg!(any(target_arch = "wasm32")) {
    // Platform is *not* supported
    assert_eq!(debugger::state(), debugger::State::Unknown)
} else {
    // Platform might be supported?  Might not?
}