20 releases

0.7.8 Mar 10, 2024
0.7.6 Sep 1, 2023
0.7.4 Mar 27, 2023
0.7.1 Dec 22, 2022
0.2.0 May 10, 2021

#575 in Debugging

Download history 657/week @ 2024-08-15 817/week @ 2024-08-22 564/week @ 2024-08-29 1438/week @ 2024-09-05 1178/week @ 2024-09-12 1370/week @ 2024-09-19 1618/week @ 2024-09-26 1151/week @ 2024-10-03 1131/week @ 2024-10-10 1108/week @ 2024-10-17 1067/week @ 2024-10-24 943/week @ 2024-10-31 1426/week @ 2024-11-07 1228/week @ 2024-11-14 1340/week @ 2024-11-21 1225/week @ 2024-11-28

5,295 downloads per month
Used in 3 crates (2 directly)

MIT license

35KB
596 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.8"

License

This crate is licensed under the MIT license.

Dependencies

~2.2–3.5MB
~56K SLoC