A crate to programmatically invoke debugging breakpoints with helping macros.
These macros are designed to help developers catch errors during debugging sessions that would otherwise be a panic (which may not be desirable in certain contexts) or simply a log message (which may go unnoticed).
This crate's internals are disabled by default, there are shims provided so breakpoints will not be compiled outside of a debugging context. This means that the macros in this crate can be used freely throughout your code without having to conditionally compile them out yourself.
NOTICE
You must use the
enable
feature of this crate (deactivated by default) to activate the breakpoints. This crate cannot detect the presence of a debugger.BREAKPOINTS REQUIRE NIGHTLY RUST
BREAKPOINTS REQUIRE ENABLING THE EXPERIMENTAL
core_intrinsics
FEATUREAdditonally, debugging may not land on the macro statements themselves. This can have the consequence that the debgger may pause on an internal module. To avoid this,
return
orcontinue
immediately following a macro invocation. Alternatively, use your debugger's "step-out" feature until you reenter the scope of your code.
Error messages are logged when used in conjuction with Tracing
Examples
// trigger the debugger
breakpoint!;
for i in 0..5
Usage
Prepare your environment for debugging Rust.
If you are using VSCode you will need the Rust Analyzer and Code LLDB (Linux/Mac) or the C/C++ (Windows) extensions. See Microsoft's Documentation on Rust Debugging in VSCode.
1. Enable Nightly Rust:
You can set a workspace toolchain override by adding a rust-toolchain.toml
file at the root of your project with the following contents:
[]
= "nightly"
OR you can set cargo to default to nightly globally:
2. Create a debug feature in your project that will only be active in the context of a debugger, i.e. not enabled by default.
Cargo.toml
:
[]
= []
= [
"unbug/enable"
]
3. enable the core_intrinsics feature in the root of your crate (src/main.rs
or src/lib.rs
)
src/main.rs
:
4. Pass your feature flag to cargo during your debug build.
Sample VSCode .vscode/launch.json
with LLDB (Linux/Mac):
Sample VSCode .vscode/launch.json
with msvc (Windows):
and complimentary .vscode/tasks.json
5. Select the debug launch configuration for your platform and start debugging
In VSCode, open the "Run and Debug" panel from the left sidebar.
launch configurations can be now found in the dropdown menu next to the green "Start Debugging" button.
License
Unbug is free and open source. All code in this repository is dual-licensed under either:
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
at your option.