debugger/
commands.rs

1//! CLI command definitions
2//!
3//! Defines the clap commands for the debugger CLI.
4
5use clap::Subcommand;
6use std::path::PathBuf;
7
8#[derive(Subcommand)]
9pub enum Commands {
10    /// Start debugging a program
11    Start {
12        /// Path to the executable to debug
13        program: PathBuf,
14
15        /// Arguments to pass to the program
16        #[arg(last = true)]
17        args: Vec<String>,
18
19        /// Debug adapter to use (default: lldb-dap)
20        #[arg(long)]
21        adapter: Option<String>,
22
23        /// Stop at program entry point
24        #[arg(long)]
25        stop_on_entry: bool,
26    },
27
28    /// Attach to a running process
29    Attach {
30        /// Process ID to attach to
31        pid: u32,
32
33        /// Debug adapter to use (default: lldb-dap)
34        #[arg(long)]
35        adapter: Option<String>,
36    },
37
38    /// Breakpoint management
39    #[command(subcommand)]
40    Breakpoint(BreakpointCommands),
41
42    /// Shorthand for 'breakpoint add'
43    #[command(name = "break", alias = "b")]
44    Break {
45        /// Location: file:line or function name
46        location: String,
47
48        /// Condition for the breakpoint
49        #[arg(long, short)]
50        condition: Option<String>,
51    },
52
53    /// Continue execution
54    #[command(alias = "c")]
55    Continue,
56
57    /// Step over (execute current line, step over function calls)
58    #[command(alias = "n")]
59    Next,
60
61    /// Step into (execute current line, step into function calls)
62    #[command(alias = "s")]
63    Step,
64
65    /// Step out (run until current function returns)
66    #[command(alias = "out")]
67    Finish,
68
69    /// Pause execution
70    Pause,
71
72    /// Print stack trace
73    #[command(alias = "bt")]
74    Backtrace {
75        /// Maximum number of frames to show
76        #[arg(long, default_value = "20")]
77        limit: usize,
78
79        /// Show local variables for each frame
80        #[arg(long)]
81        locals: bool,
82    },
83
84    /// Show local variables in current frame
85    Locals,
86
87    /// Print/evaluate expression
88    #[command(alias = "p")]
89    Print {
90        /// Expression to evaluate
91        expression: String,
92    },
93
94    /// Evaluate expression (can have side effects)
95    Eval {
96        /// Expression to evaluate
97        expression: String,
98    },
99
100    /// Show current position with source context and variables
101    #[command(alias = "where")]
102    Context {
103        /// Number of context lines to show
104        #[arg(long, default_value = "5")]
105        lines: usize,
106    },
107
108    /// List all threads
109    Threads,
110
111    /// Switch to a specific thread
112    Thread {
113        /// Thread ID to switch to
114        id: Option<i64>,
115    },
116
117    /// Navigate to a specific stack frame
118    Frame {
119        /// Frame number (0 = innermost/current)
120        number: Option<usize>,
121    },
122
123    /// Move up the stack (to caller)
124    Up,
125
126    /// Move down the stack (toward current frame)
127    Down,
128
129    /// Wait for next stop event (breakpoint, step completion, etc.)
130    Await {
131        /// Timeout in seconds
132        #[arg(long, default_value = "300")]
133        timeout: u64,
134    },
135
136    /// Get debuggee stdout/stderr output
137    Output {
138        /// Stream output continuously
139        #[arg(long)]
140        follow: bool,
141
142        /// Get last N lines of output
143        #[arg(long)]
144        tail: Option<usize>,
145
146        /// Clear output buffer
147        #[arg(long)]
148        clear: bool,
149    },
150
151    /// Get daemon/session status
152    Status,
153
154    /// Stop debugging (terminates debuggee and session)
155    Stop,
156
157    /// Detach from process (process keeps running)
158    Detach,
159
160    /// Restart program (re-launch with same arguments)
161    Restart,
162
163    /// View daemon logs (for debugging)
164    Logs {
165        /// Number of lines to show (default: 50)
166        #[arg(long, short = 'n', default_value = "50")]
167        lines: usize,
168
169        /// Follow log output (like tail -f)
170        #[arg(long, short)]
171        follow: bool,
172
173        /// Clear the log file
174        #[arg(long)]
175        clear: bool,
176    },
177
178    /// [Hidden] Run in daemon mode - spawned automatically
179    #[command(hide = true)]
180    Daemon,
181
182    /// Install and manage debug adapters
183    Setup {
184        /// Debugger to install (e.g., lldb, codelldb, python, go)
185        debugger: Option<String>,
186
187        /// Install specific version
188        #[arg(long)]
189        version: Option<String>,
190
191        /// List available debuggers and their status
192        #[arg(long)]
193        list: bool,
194
195        /// Check installed debuggers
196        #[arg(long)]
197        check: bool,
198
199        /// Auto-install debuggers for detected project types
200        #[arg(long, name = "auto")]
201        auto_detect: bool,
202
203        /// Uninstall a debugger
204        #[arg(long)]
205        uninstall: bool,
206
207        /// Show installation path for a debugger
208        #[arg(long)]
209        path: bool,
210
211        /// Force reinstall even if already installed
212        #[arg(long)]
213        force: bool,
214
215        /// Show what would be installed without installing
216        #[arg(long)]
217        dry_run: bool,
218
219        /// Output results as JSON
220        #[arg(long)]
221        json: bool,
222    },
223
224    /// Execute a test scenario defined in a YAML file
225    Test {
226        /// Path to the YAML test scenario file
227        path: PathBuf,
228
229        /// Verbose output
230        #[arg(long, short)]
231        verbose: bool,
232    },
233}
234
235#[derive(Subcommand)]
236pub enum BreakpointCommands {
237    /// Add a breakpoint
238    Add {
239        /// Location: file:line or function name
240        location: String,
241
242        /// Condition for the breakpoint
243        #[arg(long, short)]
244        condition: Option<String>,
245
246        /// Hit count (break after N hits)
247        #[arg(long)]
248        hit_count: Option<u32>,
249    },
250
251    /// Remove a breakpoint
252    Remove {
253        /// Breakpoint ID to remove
254        id: Option<u32>,
255
256        /// Remove all breakpoints
257        #[arg(long)]
258        all: bool,
259    },
260
261    /// List all breakpoints
262    List,
263
264    /// Enable a breakpoint
265    Enable {
266        /// Breakpoint ID to enable
267        id: u32,
268    },
269
270    /// Disable a breakpoint
271    Disable {
272        /// Breakpoint ID to disable
273        id: u32,
274    },
275}