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_version: String,
8 pub(crate) lldb_python_dir: 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 lldb_version = command(&lldb_exe)
18 .allow_failure()
19 .arg("--version")
20 .run_capture(builder)
21 .stdout_if_ok()
22 .and_then(|v| if v.trim().is_empty() { None } else { Some(v) })?;
23
24 let lldb_python_dir = command(&lldb_exe)
25 .allow_failure()
26 .arg("-P")
27 .run_capture_stdout(builder)
28 .stdout_if_ok()
29 .map(|p| p.lines().next().expect("lldb Python dir not found").to_string())?;
30
31 Some(Lldb { lldb_version, lldb_python_dir })
32}