pub struct DebugAdapter { /* private fields */ }Expand description
A state-machine-based DAP client that manages a debug adapter process.
Handles spawning the debug adapter, performing the DAP initialize and launch/attach handshakes, sending requests, and processing responses. All state transitions are validated to maintain the lifecycle invariant.
§Concurrency
Same as LspClient – state in Arc<Mutex<>>,
separate from process/writer. Lock ordering: state -> process -> writer
-> pending_responses.
Implementations§
Source§impl DebugAdapter
impl DebugAdapter
Sourcepub fn new(
session: DebugSession,
adapter_command: String,
adapter_args: Vec<String>,
) -> Self
pub fn new( session: DebugSession, adapter_command: String, adapter_args: Vec<String>, ) -> Self
Creates a new debug adapter in the Stopped state.
session— The debug session this adapter belongs to.adapter_command— The command to spawn the debug adapter (e.g., “/usr/bin/gdb”).adapter_args— Arguments to pass to the adapter command.
Sourcepub async fn get_state(&self) -> DebugAdapterState
pub async fn get_state(&self) -> DebugAdapterState
Returns the current state of the debug adapter.
Sourcepub async fn start(&self) -> Result<(), String>
pub async fn start(&self) -> Result<(), String>
Spawns the debug adapter process and begins the initialization sequence.
Transitions from Stopped to Starting to Initializing. If spawning
fails, transitions to Crashed. A background task is spawned to read
responses from the adapter’s stdout.
Returns Ok(()) if the process was spawned successfully, or an error
describing the failure.
pub async fn stop(&self) -> Result<(), String>
pub async fn is_running(&self) -> bool
Sourcepub async fn initialize(&self) -> Result<Value, String>
pub async fn initialize(&self) -> Result<Value, String>
Examples found in repository?
8async fn main() -> Result<(), Box<dyn std::error::Error>> {
9 // Register the debug adapter
10 let pool = DebugAdapterPool::new();
11 pool
12 .register_adapter(
13 "cppdbg".to_string(),
14 "/usr/bin/gdb".to_string(),
15 vec!["--interpreter=dap".to_string()],
16 )
17 .await;
18
19 // Create a debug session
20 let manager = DebugManager::new();
21 let session_id = manager.create_session("main".to_string(), "cppdbg".to_string())?;
22 let session = manager.get_session(&session_id).unwrap();
23
24 // Start the adapter
25 let adapter = pool.create_session(session).await?;
26
27 // Initialize and set breakpoints
28 adapter.initialize().await?;
29 adapter
30 .set_breakpoints(
31 serde_json::json!({ "path": "/path/to/source.cpp" }),
32 vec![SourceBreakpoint {
33 line: 10,
34 column: None,
35 condition: None,
36 hit_condition: None,
37 log_message: None,
38 }],
39 )
40 .await?;
41
42 println!("Debug session initialized with breakpoints.");
43 Ok(())
44}pub async fn launch(&self, configuration: Value) -> Result<(), String>
pub async fn attach(&self, configuration: Value) -> Result<(), String>
Sourcepub async fn set_breakpoints(
&self,
source: Value,
breakpoints: Vec<SourceBreakpoint>,
) -> Result<Vec<Breakpoint>, String>
pub async fn set_breakpoints( &self, source: Value, breakpoints: Vec<SourceBreakpoint>, ) -> Result<Vec<Breakpoint>, String>
Examples found in repository?
8async fn main() -> Result<(), Box<dyn std::error::Error>> {
9 // Register the debug adapter
10 let pool = DebugAdapterPool::new();
11 pool
12 .register_adapter(
13 "cppdbg".to_string(),
14 "/usr/bin/gdb".to_string(),
15 vec!["--interpreter=dap".to_string()],
16 )
17 .await;
18
19 // Create a debug session
20 let manager = DebugManager::new();
21 let session_id = manager.create_session("main".to_string(), "cppdbg".to_string())?;
22 let session = manager.get_session(&session_id).unwrap();
23
24 // Start the adapter
25 let adapter = pool.create_session(session).await?;
26
27 // Initialize and set breakpoints
28 adapter.initialize().await?;
29 adapter
30 .set_breakpoints(
31 serde_json::json!({ "path": "/path/to/source.cpp" }),
32 vec![SourceBreakpoint {
33 line: 10,
34 column: None,
35 condition: None,
36 hit_condition: None,
37 log_message: None,
38 }],
39 )
40 .await?;
41
42 println!("Debug session initialized with breakpoints.");
43 Ok(())
44}