bootstrap/core/debuggers/lldb.rs
1use std::path::PathBuf;
2
3use crate::core::builder::Builder;
4use crate::utils::exec::command;
5
6pub(crate) struct Lldb {
7 pub(crate) lldb_exe: PathBuf,
8 pub(crate) lldb_version: String,
9}
10
11pub(crate) fn discover_lldb(builder: &Builder<'_>) -> Option<Lldb> {
12 // FIXME(#148361): We probably should not be picking up whatever arbitrary
13 // lldb happens to be in the user's path, and instead require some kind of
14 // explicit opt-in or configuration.
15 let lldb_exe = builder.config.lldb.clone().unwrap_or_else(|| PathBuf::from("lldb"));
16
17 let mut cmd = command(&lldb_exe);
18 cmd.arg("--version");
19
20 // If a path to a LLDB binary was provided, it has to exist and return some version, to avoid
21 // silent failures.
22 let explicitly_set_lldb = builder.config.lldb.is_some();
23 if !explicitly_set_lldb {
24 cmd = cmd.allow_failure();
25 }
26 let lldb_version = cmd.run_capture(builder).stdout_if_ok().filter(|v| !v.trim().is_empty())?;
27
28 Some(Lldb { lldb_exe, lldb_version })
29}