on 2158366 help sign in
helix/helix-dap/examples/dap-lldb.rs
116 lines 3.3 kB history raw
1use helix_dap::{events, Client, Event, Payload, Result, SourceBreakpoint};
2use serde::{Deserialize, Serialize};
3use serde_json::to_value;
4use tokio::sync::mpsc::UnboundedReceiver;
6#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
7#[serde(rename_all = "camelCase")]
8struct LaunchArguments {
9 program: String,
10 console: String,
13async fn dispatch(mut rx: UnboundedReceiver<Payload>) {
14 loop {
15 match rx.recv().await.unwrap() {
16 Payload::Event(Event::Output(events::Output {
17 category, output, ..
18 })) => {
19 println!(
20 "> [{}] {}",
21 category.unwrap_or("unknown".to_owned()),
22 output
23 );
24 }
25 Payload::Event(Event::Stopped(_)) => {
26 println!("stopped");
27 }
28 _ => {}
29 };
30 }
33#[tokio::main]
34pub async fn main() -> Result<()> {
35 let base_config = fern::Dispatch::new().level(log::LevelFilter::Info);
37 let stderr_config = fern::Dispatch::new()
38 .format(|out, message, record| out.finish(format_args!("[{}] {}", record.level(), message)))
39 .chain(std::io::stderr());
41 base_config
42 .chain(stderr_config)
43 .apply()
44 .expect("Failed to set up logging");
46 let (mut client, events) = Client::tcp_process("lldb-vscode", vec![], "-p {}", 0).await?;
47 println!("create: {:?}", client);
49 tokio::spawn(dispatch(events));
51 println!("init: {:?}", client.initialize("lldb".to_owned()).await);
52 println!("caps: {:?}", client.capabilities());
54 let args = LaunchArguments {
55 program: "/tmp/cdebug/main".to_owned(),
56 console: "internalConsole".to_owned(),
57 };
59 println!("launch: {:?}", client.launch(to_value(args)?).await);
61 println!(
62 "breakpoints: {:#?}",
63 client
64 .set_breakpoints(
65 "/tmp/cdebug/main.c".into(),
66 vec![SourceBreakpoint {
67 line: 6,
68 column: Some(2),
69 condition: None,
70 hit_condition: None,
71 log_message: None,
72 }]
73 )
74 .await
75 );
77 let mut _in = String::new();
78 std::io::stdin()
79 .read_line(&mut _in)
80 .expect("Failed to read line");
82 println!("configurationDone: {:?}", client.configuration_done().await);
84 let threads = client.threads().await?;
85 println!("threads: {:#?}", threads);
86 let bt = client
87 .stack_trace(threads[0].id)
88 .await
89 .expect("expected stack trace");
90 println!("stack trace: {:#?}", bt);
91 let scopes = client
92 .scopes(bt.0[0].id)
93 .await
94 .expect("expected scopes for thread");
95 println!("scopes: {:#?}", scopes);
96 println!(
97 "vars: {:#?}",
98 client.variables(scopes[0].variables_reference).await
99 );
101 let mut _in = String::new();
102 std::io::stdin()
103 .read_line(&mut _in)
104 .expect("Failed to read line");
106 println!("continued: {:?}", client.continue_thread(0).await);
108 let mut _in = String::new();
109 std::io::stdin()
110 .read_line(&mut _in)
111 .expect("Failed to read line");
113 println!("disconnect: {:?}", client.disconnect().await);
115 Ok(())