Skip to main content

debugger/setup/
registry.rs

1//! Debugger registry and metadata
2//!
3//! Contains information about all supported debuggers and their installation methods.
4
5use super::installer::Installer;
6use std::fmt;
7use std::sync::Arc;
8
9/// Supported platforms
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum Platform {
12    Linux,
13    MacOS,
14    Windows,
15}
16
17impl Platform {
18    /// Get the current platform
19    pub fn current() -> Self {
20        #[cfg(target_os = "linux")]
21        return Platform::Linux;
22
23        #[cfg(target_os = "macos")]
24        return Platform::MacOS;
25
26        #[cfg(target_os = "windows")]
27        return Platform::Windows;
28
29        #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
30        return Platform::Linux; // Default fallback
31    }
32}
33
34impl fmt::Display for Platform {
35    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36        match self {
37            Platform::Linux => write!(f, "linux"),
38            Platform::MacOS => write!(f, "macos"),
39            Platform::Windows => write!(f, "windows"),
40        }
41    }
42}
43
44/// Information about a debugger
45#[derive(Debug, Clone)]
46pub struct DebuggerInfo {
47    /// Unique identifier (e.g., "lldb", "codelldb")
48    pub id: &'static str,
49    /// Display name
50    pub name: &'static str,
51    /// Supported languages
52    pub languages: &'static [&'static str],
53    /// Supported platforms
54    pub platforms: &'static [Platform],
55    /// Brief description
56    pub description: &'static str,
57    /// Whether this is the primary adapter for its languages
58    pub primary: bool,
59}
60
61/// All available debuggers
62static DEBUGGERS: &[DebuggerInfo] = &[
63    DebuggerInfo {
64        id: "gdb",
65        name: "GDB",
66        languages: &["c", "cpp"],
67        platforms: &[Platform::Linux, Platform::MacOS, Platform::Windows],
68        description: "GDB native DAP adapter",
69        primary: true,
70    },
71    DebuggerInfo {
72        id: "cuda-gdb",
73        name: "CUDA-GDB",
74        languages: &["cuda", "c", "cpp"],
75        platforms: &[Platform::Linux],
76        description: "NVIDIA CUDA debugger with DAP support",
77        primary: true,
78    },
79    DebuggerInfo {
80        id: "lldb",
81        name: "lldb-dap",
82        languages: &["c", "cpp", "rust", "swift"],
83        platforms: &[Platform::Linux, Platform::MacOS],
84        description: "LLVM's native DAP adapter",
85        primary: true,
86    },
87    DebuggerInfo {
88        id: "codelldb",
89        name: "CodeLLDB",
90        languages: &["c", "cpp", "rust"],
91        platforms: &[Platform::Linux, Platform::MacOS, Platform::Windows],
92        description: "Feature-rich LLDB-based debugger",
93        primary: false,
94    },
95    DebuggerInfo {
96        id: "python",
97        name: "debugpy",
98        languages: &["python"],
99        platforms: &[Platform::Linux, Platform::MacOS, Platform::Windows],
100        description: "Microsoft's Python debugger",
101        primary: true,
102    },
103    DebuggerInfo {
104        id: "go",
105        name: "Delve",
106        languages: &["go"],
107        platforms: &[Platform::Linux, Platform::MacOS, Platform::Windows],
108        description: "Go debugger with DAP support",
109        primary: true,
110    },
111];
112
113/// Get all registered debuggers
114pub fn all_debuggers() -> &'static [DebuggerInfo] {
115    DEBUGGERS
116}
117
118/// Get debugger info by ID
119pub fn get_debugger(id: &str) -> Option<&'static DebuggerInfo> {
120    DEBUGGERS.iter().find(|d| d.id == id)
121}
122
123/// Get debuggers for a specific language
124pub fn debuggers_for_language(language: &str) -> Vec<&'static DebuggerInfo> {
125    DEBUGGERS
126        .iter()
127        .filter(|d| d.languages.contains(&language))
128        .collect()
129}
130
131/// Get the primary debugger for a language
132pub fn primary_debugger_for_language(language: &str) -> Option<&'static DebuggerInfo> {
133    DEBUGGERS
134        .iter()
135        .find(|d| d.languages.contains(&language) && d.primary)
136}
137
138/// Get an installer for a debugger
139pub fn get_installer(id: &str) -> Option<Arc<dyn Installer>> {
140    use super::adapters;
141
142    match id {
143        "gdb" => Some(Arc::new(adapters::gdb::GdbInstaller)),
144        "cuda-gdb" => Some(Arc::new(adapters::cuda_gdb::CudaGdbInstaller)),
145        "lldb" => Some(Arc::new(adapters::lldb::LldbInstaller)),
146        "codelldb" => Some(Arc::new(adapters::codelldb::CodeLldbInstaller)),
147        "python" => Some(Arc::new(adapters::debugpy::DebugpyInstaller)),
148        "go" => Some(Arc::new(adapters::delve::DelveInstaller)),
149        _ => None,
150    }
151}
152
153#[cfg(test)]
154mod tests {
155    use super::*;
156
157    #[test]
158    fn test_all_debuggers_has_entries() {
159        assert!(!all_debuggers().is_empty());
160    }
161
162    #[test]
163    fn test_get_debugger() {
164        assert!(get_debugger("lldb").is_some());
165        assert!(get_debugger("nonexistent").is_none());
166    }
167
168    #[test]
169    fn test_debuggers_for_language() {
170        let rust_debuggers = debuggers_for_language("rust");
171        assert!(!rust_debuggers.is_empty());
172    }
173}