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