crabgrind is a small library that enables Rust programs to tap into
Valgrind's tools and environment.
It exposes full set of Valgrind's client requests in Rust, manages the structure, type conversions and enforces static typing where possible.
Minimum Supported Rust Version: 1.71
First, add crabgrind as a dependency in Cargo.toml
[dependencies]
crabgrind = "0.3"
or
cargo add crabgrind
Note: This crate is
no_stdand dependency-free
The crate needs access to a local Valgrind installation(or at least its headers) in order to read C macro definitions, constants, and supported requests.
The build script (build.rs) attempts to locate headers in this order:
VALGRIND_INCLUDE is set, it's value is added
to the search paths.pkg-config.If headers cannot be located, the crate will still compile without errors, however any request will panic at runtime.
Use some of the Client Requests:
fn main() {
assert!(
crabgrind::valgrind::running_mode().is_valgrind(),
":~$ valgrind {}", std::env::current_exe().unwrap().display()
);
crabgrind::println!("Hey, Valgrind!");
}
And run under Valgrind
:~$ cargo build :~$ valgrind ./target/debug/app
With default-features = false, all requests turn into no-op stubs and are
optimized out by the compiler. No build dependencies are pulled in.
[dependencies]
crabgrind = { version = "0.3", default-features = false }
[build-dependencies]
crabgrind = "0.3"
Valgrind's client request mechanism is a C implementation detail, exposed strictly via C macros. Since Rust does not support C preprocessor, these macros cannot be used directly.
crabgrind wraps the foundational VALGRIND_DO_CLIENT_REQUEST_EXPR macro via
FFI binding. All higher-level client requests are implemented in Rust on top of
this binding.
The overhead per request, compared to using C macros directly is strictly the cost of a single function call.
The implementation is independent of any specific Valgrind version. Instead, mismatches between requests and local Valgrind instance are handled at compile-time.
We are coupled to the Valgrind version present during compilation.
If a request is invoked at runtime that is unsupported by the active Valgrind instance (e.g. running under an older Valgrind), the call panics immediately, showing the version mismatch message and request requirements.
If your application is running without Valgrind, these requests execute as harmless machine code. They will not panic or segfault, and overhead is probably undetectable except in a tight loops.
crabgrind is distributed under MIT license.
Valgrind itself is a GPL3, however valgrind/*.h headers are distributed
under a BSD-style license, so we can use them without worrying about license
conflicts.
Rust
80.1%
C
13.5%
Python
3.3%
Nix
1.5%
Just
1.2%
crabgrind is a small library that enables Rust programs to tap into
Valgrind's tools and environment.
It exposes full set of Valgrind's client requests in Rust, manages the structure, type conversions and enforces static typing where possible.
Minimum Supported Rust Version: 1.71
First, add crabgrind as a dependency in Cargo.toml
[dependencies]
crabgrind = "0.3"
or
cargo add crabgrind
Note: This crate is
no_stdand dependency-free
The crate needs access to a local Valgrind installation(or at least its headers) in order to read C macro definitions, constants, and supported requests.
The build script (build.rs) attempts to locate headers in this order:
VALGRIND_INCLUDE is set, it's value is added
to the search paths.pkg-config.If headers cannot be located, the crate will still compile without errors, however any request will panic at runtime.
Use some of the Client Requests:
fn main() {
assert!(
crabgrind::valgrind::running_mode().is_valgrind(),
":~$ valgrind {}", std::env::current_exe().unwrap().display()
);
crabgrind::println!("Hey, Valgrind!");
}
And run under Valgrind
:~$ cargo build :~$ valgrind ./target/debug/app
With default-features = false, all requests turn into no-op stubs and are
optimized out by the compiler. No build dependencies are pulled in.
[dependencies]
crabgrind = { version = "0.3", default-features = false }
[build-dependencies]
crabgrind = "0.3"
Valgrind's client request mechanism is a C implementation detail, exposed strictly via C macros. Since Rust does not support C preprocessor, these macros cannot be used directly.
crabgrind wraps the foundational VALGRIND_DO_CLIENT_REQUEST_EXPR macro via
FFI binding. All higher-level client requests are implemented in Rust on top of
this binding.
The overhead per request, compared to using C macros directly is strictly the cost of a single function call.
The implementation is independent of any specific Valgrind version. Instead, mismatches between requests and local Valgrind instance are handled at compile-time.
We are coupled to the Valgrind version present during compilation.
If a request is invoked at runtime that is unsupported by the active Valgrind instance (e.g. running under an older Valgrind), the call panics immediately, showing the version mismatch message and request requirements.
If your application is running without Valgrind, these requests execute as harmless machine code. They will not panic or segfault, and overhead is probably undetectable except in a tight loops.
crabgrind is distributed under MIT license.
Valgrind itself is a GPL3, however valgrind/*.h headers are distributed
under a BSD-style license, so we can use them without worrying about license
conflicts.
Rust
80.1%
C
13.5%
Python
3.3%
Nix
1.5%
Just
1.2%