All Projects → jfrimmel → cargo-valgrind

jfrimmel / cargo-valgrind

Licence: Apache-2.0, MIT licenses found Licenses found Apache-2.0 LICENSE-APACHE MIT LICENSE-MIT
A cargo subcommand, that runs valgrind and displays its output in a helpful manner.

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to cargo-valgrind

cargo-aur
Prepare Rust projects to be released on the Arch Linux User Repository
Stars: ✭ 49 (-25.76%)
Mutual labels:  cargo, cargo-subcommand, cargo-plugin
cargo-wix
A cargo subcommand to build Windows installers for rust projects using the WiX Toolset
Stars: ✭ 142 (+115.15%)
Mutual labels:  cargo, cargo-subcommand
eta-ffi
A command line tool to automate the generation of ffi import code for the bindings of various Java libraries.
Stars: ✭ 19 (-71.21%)
Mutual labels:  ffi, ffi-bindings
Rust Python Example
Example of using Rust to Extend Python
Stars: ✭ 699 (+959.09%)
Mutual labels:  ffi, cargo
cargo-clone
A cargo subcommand to fetch the source code of a Rust crate
Stars: ✭ 72 (+9.09%)
Mutual labels:  cargo, cargo-subcommand
cargo-release
Cargo subcommand `release`: everything about releasing a rust crate.
Stars: ✭ 854 (+1193.94%)
Mutual labels:  cargo, cargo-subcommand
ffi-libc
Useful Ruby FFI bindings for libc
Stars: ✭ 32 (-51.52%)
Mutual labels:  ffi, ffi-bindings
memcheck-cover
An HTML generator for Valgrind's Memcheck tool
Stars: ✭ 30 (-54.55%)
Mutual labels:  valgrind, leak
cargo-supply-chain
Gather author, contributor and publisher data on crates in your dependency graph.
Stars: ✭ 287 (+334.85%)
Mutual labels:  cargo, cargo-subcommand
rust-ffi-examples
FFI examples written in Rust
Stars: ✭ 42 (-36.36%)
Mutual labels:  ffi, ffi-bindings
cargo-cook
A rust cargo subcommand which cooks your crate
Stars: ✭ 29 (-56.06%)
Mutual labels:  cargo, cargo-subcommand
cargo-limit
Cargo with less noise: warnings are skipped until errors are fixed, Neovim integration, etc.
Stars: ✭ 105 (+59.09%)
Mutual labels:  cargo, cargo-plugin
haskell-libui
Haskell bindings to the libui C library.
Stars: ✭ 45 (-31.82%)
Mutual labels:  ffi
wasm
Utilities for loading and running WASM modules from Dart code
Stars: ✭ 252 (+281.82%)
Mutual labels:  ffi
Compiler-Principle
词法分析,LL(1) 文法分析,LR(1) 文法分析
Stars: ✭ 18 (-72.73%)
Mutual labels:  ffi
massif.js
Visualize Valgrind Massif memory consumption online.
Stars: ✭ 30 (-54.55%)
Mutual labels:  valgrind
nix-template
Make creating nix expressions easy
Stars: ✭ 161 (+143.94%)
Mutual labels:  cargo
clr-loader
Loader for different .NET runtimes
Stars: ✭ 16 (-75.76%)
Mutual labels:  ffi
cross
“Zero setup” cross compilation and “cross testing” of Rust crates
Stars: ✭ 3,550 (+5278.79%)
Mutual labels:  cargo
deno bindgen
Simplified glue code generation for Deno FFI libraries written in Rust.
Stars: ✭ 142 (+115.15%)
Mutual labels:  ffi

cargo-valgrind

A cargo subcommand, that runs valgrind and collects its output in a helpful manner.

Latest version Documentation

This command extends cargo with the capability to directly run valgrind on any crate executable. The output of valgrind is then used to mark the binary as pass/fail.

This command should not be necessary for ordinary Rust programs, especially if you are only using safe Rust code. But if you do FFI-related stuff (either by simply using a FFI-binding crate or because you are developing a safe wrapper for such FFI bindings) it may be really helpful to check, whether the memory usages across the FFI borders are correct.

Usage

A typical mistake would be:

use std::ffi::CString;
use std::os::raw::c_char;

extern "C" {
    fn puts(s: *const c_char);
}

fn main() {
    let string = CString::new("Test").unwrap();

    let ptr = string.into_raw();
    unsafe { puts(ptr) };

    // unsafe { CString::from_raw(ptr) };
}

The memory of the variable string will never be freed. If you run cargo valgrind run it your shell, it detects the leak:

$ cargo valgrind run
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/cstring`
Test
       Error Leaked 5 bytes
        Info at realloc (vg_replace_malloc.c:826)
             at realloc (alloc.rs:125)
             at realloc (alloc.rs:184)
             at reserve_internal<u8,alloc::alloc::Global> (raw_vec.rs:666)
             at reserve_exact<u8,alloc::alloc::Global> (raw_vec.rs:411)
             at reserve_exact<u8> (vec.rs:482)
             at std::ffi::c_str::CString::from_vec_unchecked (c_str.rs:355)
             at std::ffi::c_str::CString::_new (c_str.rs:330)
             at std::ffi::c_str::CString::new (c_str.rs:324)
             at cstring::main (main.rs:9)
             at std::rt::lang_start::{{closure}} (rt.rs:64)
             at {{closure}} (rt.rs:49)
             at std::panicking::try::do_call (panicking.rs:293)
             at __rust_maybe_catch_panic (lib.rs:85)
             at try<i32,closure> (panicking.rs:272)
             at catch_unwind<closure,i32> (panic.rs:394)
             at std::rt::lang_start_internal (rt.rs:48)
             at std::rt::lang_start (rt.rs:64)
             at main
     Summary Leaked 5 B total

Un-commenting the unsafe { CString::from_raw(ptr) }; re-takes the memory and frees it correctly. cargo valgrind run will compile the binary for you and won't detect a leak, since there is no leak anymore.

If you would like to pass flags to valgrind (for example to run an alternate subtool), you can set the VALGRINDFLAGS environment variable to a space-delimited list of valid Valgrind options.

Note: users of cargo-valgrind version 1.x should mind the changed command line. Previously there was a cargo valgrind subcommand, that replaced the cargo run or cargo test commands. Now the command line is cargo valgrind <command>, where <command> can be any normal cargo subcommand.

Installation

Requirements

You need to have valgrind installed and in the PATH (you can test this by running valgrind --help in your shell).

You'll also need to have cargo installed and in the PATH, but since this is a cargo subcommand, you will almost certainly have it already installed.

Install the binary

Run the following command to install from crates.io:

$ cargo install cargo-valgrind

This will install the latest official released version.

If you want to use the latest changes, that were not yet published to crates.io, you can install the binary from the git-repository like this:

$ cargo install --git https://github.com/jfrimmel/cargo-valgrind

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in cargo-valgrind by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].