1use std::ffi::OsStr;
2
3use anyhow::Result;
4use async_trait::async_trait;
5use gpui::AsyncApp;
6use task::DebugAdapterConfig;
7
8use crate::*;
9
10pub(crate) struct GdbDebugAdapter {}
11
12impl GdbDebugAdapter {
13 const ADAPTER_NAME: &'static str = "gdb";
14
15 pub(crate) fn new() -> Self {
16 GdbDebugAdapter {}
17 }
18}
19
20#[async_trait(?Send)]
21impl DebugAdapter for GdbDebugAdapter {
22 fn name(&self) -> DebugAdapterName {
23 DebugAdapterName(Self::ADAPTER_NAME.into())
24 }
25
26 async fn get_binary(
27 &self,
28 delegate: &dyn DapDelegate,
29 config: &DebugAdapterConfig,
30 user_installed_path: Option<std::path::PathBuf>,
31 _: &mut AsyncApp,
32 ) -> Result<DebugAdapterBinary> {
33 let user_setting_path = user_installed_path
34 .filter(|p| p.exists())
35 .and_then(|p| p.to_str().map(|s| s.to_string()));
36
37 /* GDB implements DAP natively so just need to */
38 let gdb_path = delegate
39 .which(OsStr::new("gdb"))
40 .and_then(|p| p.to_str().map(|s| s.to_string()))
41 .ok_or(anyhow!("Could not find gdb in path"));
42
43 if gdb_path.is_err() && user_setting_path.is_none() {
44 bail!("Could not find gdb path or it's not installed");
45 }
46
47 let gdb_path = user_setting_path.unwrap_or(gdb_path?);
48
49 Ok(DebugAdapterBinary {
50 command: gdb_path,
51 arguments: Some(vec!["-i=dap".into()]),
52 envs: None,
53 cwd: config.cwd.clone(),
54 connection: None,
55 })
56 }
57
58 async fn install_binary(
59 &self,
60 _version: AdapterVersion,
61 _delegate: &dyn DapDelegate,
62 ) -> Result<()> {
63 unimplemented!("GDB debug adapter cannot be installed by Zed (yet)")
64 }
65
66 async fn fetch_latest_adapter_version(&self, _: &dyn DapDelegate) -> Result<AdapterVersion> {
67 unimplemented!("Fetch latest GDB version not implemented (yet)")
68 }
69
70 async fn get_installed_binary(
71 &self,
72 _: &dyn DapDelegate,
73 _: &DebugAdapterConfig,
74 _: Option<std::path::PathBuf>,
75 _: &mut AsyncApp,
76 ) -> Result<DebugAdapterBinary> {
77 unimplemented!("GDB cannot be installed by Zed (yet)")
78 }
79
80 fn request_args(&self, config: &DebugAdapterConfig) -> Value {
81 json!({"program": config.program, "cwd": config.cwd})
82 }
83}