@@ -0,0 +1,114 @@
1+use helix_dap::{Client, Event, OutputEventBody, Result, SourceBreakpoint, StoppedEventBody};
2+use serde::{Deserialize, Serialize};
3+use serde_json::from_value;
4+use tokio::sync::mpsc::Receiver;
5+
6+#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
7+#[serde(rename_all = "camelCase")]
8+struct LaunchArguments {
9+ program: String,
10+ console: String,
11+}
12+
13+async fn output(mut output_event: Receiver<Event>) {
14+ let body: OutputEventBody =
15+ from_value(output_event.recv().await.unwrap().body.unwrap()).unwrap();
16+ println!(
17+ "> [{}] {}",
18+ body.category.unwrap_or("unknown".to_owned()),
19+ body.output
20+ );
21+}
22+
23+#[tokio::main]
24+pub async fn main() -> Result<()> {
25+ let base_config = fern::Dispatch::new().level(log::LevelFilter::Info);
26+
27+ let stderr_config = fern::Dispatch::new()
28+ .format(|out, message, record| out.finish(format_args!("[{}] {}", record.level(), message)))
29+ .chain(std::io::stderr());
30+
31+ base_config
32+ .chain(stderr_config)
33+ .apply()
34+ .expect("Failed to set up logging");
35+
36+ let client = Client::tcp("127.0.0.1:7777".parse::<std::net::SocketAddr>().unwrap(), 0).await;
37+ println!("create: {:?}", client);
38+ let mut client = client?;
39+
40+ let output_event = client.listen_for_event("output".to_owned()).await;
41+ tokio::spawn(output(output_event));
42+
43+ println!("init: {:?}", client.initialize("lldb".to_owned()).await);
44+ println!("caps: {:?}", client.capabilities());
45+
46+ let args = LaunchArguments {
47+ program: "/tmp/cdebug/main".to_owned(),
48+ console: "internalConsole".to_owned(),
49+ };
50+
51+ println!("launch: {:?}", client.launch(args).await);
52+
53+ println!(
54+ "breakpoints: {:#?}",
55+ client
56+ .set_breakpoints(
57+ "/tmp/cdebug/main.c".to_owned(),
58+ vec![SourceBreakpoint {
59+ line: 8,
60+ column: Some(2),
61+ condition: None,
62+ hit_condition: None,
63+ log_message: None,
64+ }]
65+ )
66+ .await
67+ );
68+
69+ let mut _in = String::new();
70+ std::io::stdin()
71+ .read_line(&mut _in)
72+ .expect("Failed to read line");
73+
74+ let mut stopped_event = client.listen_for_event("stopped".to_owned()).await;
75+
76+ println!("configurationDone: {:?}", client.configuration_done().await);
77+
78+ let stop: StoppedEventBody =
79+ from_value(stopped_event.recv().await.unwrap().body.unwrap()).unwrap();
80+ println!("stopped: {:?}", stop);
81+
82+ let threads = client.threads().await?;
83+ println!("threads: {:#?}", threads);
84+ let bt = client
85+ .stack_trace(threads[2].id)
86+ .await
87+ .expect("expected stack trace");
88+ println!("stack trace: {:#?}", bt);
89+ let scopes = client
90+ .scopes(bt.0[0].id)
91+ .await
92+ .expect("expected scopes for thread");
93+ println!("scopes: {:#?}", scopes);
94+ println!(
95+ "vars: {:#?}",
96+ client.variables(scopes[1].variables_reference).await
97+ );
98+
99+ let mut _in = String::new();
100+ std::io::stdin()
101+ .read_line(&mut _in)
102+ .expect("Failed to read line");
103+
104+ println!("continued: {:?}", client.continue_thread(0).await);
105+
106+ let mut _in = String::new();
107+ std::io::stdin()
108+ .read_line(&mut _in)
109+ .expect("Failed to read line");
110+
111+ println!("disconnect: {:?}", client.disconnect().await);
112+
113+ Ok(())
114+}