18 releases

0.7.6 Sep 1, 2023
0.7.4 Mar 27, 2023
0.7.1 Dec 22, 2022
0.6.3 Nov 18, 2022
0.2.0 May 10, 2021

#131 in Debugging

Download history 438/week @ 2023-08-10 511/week @ 2023-08-17 556/week @ 2023-08-24 531/week @ 2023-08-31 301/week @ 2023-09-07 376/week @ 2023-09-14 606/week @ 2023-09-21 520/week @ 2023-09-28 644/week @ 2023-10-05 170/week @ 2023-10-12 188/week @ 2023-10-19 100/week @ 2023-10-26 444/week @ 2023-11-02 311/week @ 2023-11-09 502/week @ 2023-11-16 421/week @ 2023-11-23

1,702 downloads per month
Used in 3 crates (2 directly)

MIT license

34KB
577 lines

gdb-command

CI Crates.io Documentation

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.7.6"

License

This crate is licensed under the MIT license.

Dependencies

~2.2–3MB
~54K SLoC