8 releases (5 breaking)

Uses new Rust 2021

0.6.0 Sep 21, 2022
0.5.2 Sep 2, 2022
0.5.1 Aug 29, 2022
0.4.0 Aug 2, 2022
0.1.0 May 5, 2021

#88 in Debugging

Download history 9/week @ 2022-06-07 2/week @ 2022-06-21 3/week @ 2022-07-05 6/week @ 2022-07-12 3/week @ 2022-07-19 6/week @ 2022-07-26 92/week @ 2022-08-02 21/week @ 2022-08-09 5/week @ 2022-08-16 77/week @ 2022-08-23 95/week @ 2022-08-30 90/week @ 2022-09-06 79/week @ 2022-09-13 35/week @ 2022-09-20

320 downloads per month

MIT license

31KB
536 lines

gdb-command

CI Crates.io

gdb-command is a library providing API for manipulating gdb in batch mode. It supports:

  • Execution of target program (Local type).
  • Opening core of target program (Core type).
  • Attaching to remote process (Remote type).

Example

use std::process::Command;
use std::thread;
use std::time::Duration;
use gdb_command::*;

fn main () -> error::Result<()> {
    // Get stack trace from running program (stopped at crash)
    let result = GdbCommand::new(&ExecType::Local(&["tests/bins/test_abort", "A"])).r().bt().launch()?;

    // Get stack trace from core
    let result = GdbCommand::new(
            &ExecType::Core {target: "tests/bins/test_canary",
                core: "tests/bins/core.test_canary"})
        .bt().launch()?;

    // Get info from remote attach to process
    let mut child = Command::new("tests/bins/test_callstack_remote")
       .spawn()
       .expect("failed to execute child");

    thread::sleep(Duration::from_millis(10));

    // To run this test: echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
    let result = GdbCommand::new(&ExecType::Remote(&child.id().to_string()))
        .bt()
        .regs()
        .disassembly()
        .launch();
    child.kill().unwrap();

    Ok(())
}

Installation

[dependencies]
gdb-command = "0.6.0"

License

This crate is licensed under the MIT license.

Dependencies

~1–1.3MB
~37K SLoC