Skip to main content

bootstrap/core/debuggers/
gdb.rs

1use std::path::PathBuf;
2
3use crate::core::android;
4use crate::core::builder::Builder;
5use crate::core::config::DebuggerPath;
6use crate::utils::exec::BootstrapCommand;
7
8pub(crate) struct Gdb {
9    pub(crate) gdb: PathBuf,
10}
11
12pub(crate) fn discover_gdb(
13    builder: &Builder<'_>,
14    android: Option<&android::Android>,
15) -> Option<Gdb> {
16    // If there's an explicitly-configured gdb, use that.
17    match &builder.config.gdb {
18        Some(DebuggerPath::Path(path)) => {
19            return Some(Gdb { gdb: path.clone() });
20        }
21        Some(DebuggerPath::Discover) => {}
22        None => return None,
23    }
24
25    // Otherwise, fall back to whatever gdb is sitting around in PATH.
26    let gdb = match android {
27        Some(android::Android { android_cross_path, .. }) => android_cross_path.join("bin/gdb"),
28        None => PathBuf::from("gdb"),
29    };
30
31    // Check whether an ambient gdb exists, by running `gdb --version`.
32    let output = {
33        let mut gdb_command = BootstrapCommand::new(&gdb).allow_failure();
34        gdb_command.arg("--version");
35        gdb_command.run_capture(builder)
36    };
37
38    if output.is_success() { Some(Gdb { gdb }) } else { None }
39}