2021-08-16 08:59:02 +04:00
|
|
|
use helix_dap::{events, Client, Event, Result, SourceBreakpoint};
|
2021-08-13 21:24:27 +04:00
|
|
|
use serde::{Deserialize, Serialize};
|
2021-08-16 09:05:10 +04:00
|
|
|
use serde_json::{from_value, to_value};
|
2021-08-14 10:14:05 +04:00
|
|
|
use tokio::sync::mpsc::Receiver;
|
2021-08-13 21:24:27 +04:00
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
struct LaunchArguments {
|
|
|
|
program: String,
|
2021-08-14 14:19:38 +04:00
|
|
|
console: String,
|
2021-08-13 21:24:27 +04:00
|
|
|
}
|
2021-08-12 17:35:15 +04:00
|
|
|
|
2021-08-14 10:14:05 +04:00
|
|
|
async fn output(mut output_event: Receiver<Event>) {
|
2021-08-15 11:14:11 +04:00
|
|
|
loop {
|
2021-08-16 08:59:02 +04:00
|
|
|
let body: events::Output =
|
2021-08-15 11:14:11 +04:00
|
|
|
from_value(output_event.recv().await.unwrap().body.unwrap()).unwrap();
|
|
|
|
println!(
|
|
|
|
"> [{}] {}",
|
|
|
|
body.category.unwrap_or("unknown".to_owned()),
|
|
|
|
body.output
|
|
|
|
);
|
|
|
|
}
|
2021-08-14 10:14:05 +04:00
|
|
|
}
|
|
|
|
|
2021-08-12 17:35:15 +04:00
|
|
|
#[tokio::main]
|
|
|
|
pub async fn main() -> Result<()> {
|
2021-08-12 17:45:01 +04:00
|
|
|
let base_config = fern::Dispatch::new().level(log::LevelFilter::Info);
|
|
|
|
|
|
|
|
let stderr_config = fern::Dispatch::new()
|
|
|
|
.format(|out, message, record| out.finish(format_args!("[{}] {}", record.level(), message)))
|
|
|
|
.chain(std::io::stderr());
|
|
|
|
|
|
|
|
base_config
|
|
|
|
.chain(stderr_config)
|
|
|
|
.apply()
|
|
|
|
.expect("Failed to set up logging");
|
|
|
|
|
2021-08-15 13:46:16 +04:00
|
|
|
let client = Client::tcp_process("lldb-vscode", vec![], "-p {}", 0).await;
|
2021-08-13 21:13:27 +04:00
|
|
|
println!("create: {:?}", client);
|
|
|
|
let mut client = client?;
|
2021-08-12 17:35:15 +04:00
|
|
|
|
2021-08-14 10:14:05 +04:00
|
|
|
let output_event = client.listen_for_event("output".to_owned()).await;
|
|
|
|
tokio::spawn(output(output_event));
|
|
|
|
|
2021-08-14 14:19:38 +04:00
|
|
|
println!("init: {:?}", client.initialize("lldb".to_owned()).await);
|
2021-08-14 12:41:23 +04:00
|
|
|
println!("caps: {:?}", client.capabilities());
|
2021-08-13 21:24:27 +04:00
|
|
|
|
|
|
|
let args = LaunchArguments {
|
2021-08-14 14:19:38 +04:00
|
|
|
program: "/tmp/cdebug/main".to_owned(),
|
|
|
|
console: "internalConsole".to_owned(),
|
2021-08-13 21:24:27 +04:00
|
|
|
};
|
|
|
|
|
2021-08-16 09:05:10 +04:00
|
|
|
println!("launch: {:?}", client.launch(to_value(args)?).await);
|
2021-08-12 17:35:15 +04:00
|
|
|
|
|
|
|
println!(
|
2021-08-12 18:49:12 +04:00
|
|
|
"breakpoints: {:#?}",
|
2021-08-12 17:35:15 +04:00
|
|
|
client
|
|
|
|
.set_breakpoints(
|
2021-08-14 14:19:38 +04:00
|
|
|
"/tmp/cdebug/main.c".to_owned(),
|
2021-08-12 17:35:15 +04:00
|
|
|
vec![SourceBreakpoint {
|
2021-08-14 14:31:05 +04:00
|
|
|
line: 6,
|
2021-08-14 15:23:19 +04:00
|
|
|
column: Some(2),
|
2021-08-12 22:23:55 +04:00
|
|
|
condition: None,
|
|
|
|
hit_condition: None,
|
|
|
|
log_message: None,
|
2021-08-12 17:35:15 +04:00
|
|
|
}]
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut _in = String::new();
|
|
|
|
std::io::stdin()
|
|
|
|
.read_line(&mut _in)
|
|
|
|
.expect("Failed to read line");
|
|
|
|
|
2021-08-14 09:42:06 +04:00
|
|
|
let mut stopped_event = client.listen_for_event("stopped".to_owned()).await;
|
|
|
|
|
2021-08-12 17:35:15 +04:00
|
|
|
println!("configurationDone: {:?}", client.configuration_done().await);
|
2021-08-14 09:42:06 +04:00
|
|
|
|
2021-08-16 08:59:02 +04:00
|
|
|
let stop: events::Stopped =
|
2021-08-14 10:25:44 +04:00
|
|
|
from_value(stopped_event.recv().await.unwrap().body.unwrap()).unwrap();
|
|
|
|
println!("stopped: {:?}", stop);
|
2021-08-14 09:42:06 +04:00
|
|
|
|
2021-08-14 14:19:38 +04:00
|
|
|
let threads = client.threads().await?;
|
|
|
|
println!("threads: {:#?}", threads);
|
|
|
|
let bt = client
|
2021-08-14 15:23:19 +04:00
|
|
|
.stack_trace(threads[0].id)
|
2021-08-14 14:19:38 +04:00
|
|
|
.await
|
|
|
|
.expect("expected stack trace");
|
2021-08-12 21:47:14 +04:00
|
|
|
println!("stack trace: {:#?}", bt);
|
|
|
|
let scopes = client
|
|
|
|
.scopes(bt.0[0].id)
|
|
|
|
.await
|
|
|
|
.expect("expected scopes for thread");
|
|
|
|
println!("scopes: {:#?}", scopes);
|
|
|
|
println!(
|
|
|
|
"vars: {:#?}",
|
2021-08-14 15:23:19 +04:00
|
|
|
client.variables(scopes[0].variables_reference).await
|
2021-08-12 21:47:14 +04:00
|
|
|
);
|
2021-08-12 17:35:15 +04:00
|
|
|
|
|
|
|
let mut _in = String::new();
|
|
|
|
std::io::stdin()
|
|
|
|
.read_line(&mut _in)
|
|
|
|
.expect("Failed to read line");
|
|
|
|
|
|
|
|
println!("continued: {:?}", client.continue_thread(0).await);
|
|
|
|
|
|
|
|
let mut _in = String::new();
|
|
|
|
std::io::stdin()
|
|
|
|
.read_line(&mut _in)
|
|
|
|
.expect("Failed to read line");
|
|
|
|
|
|
|
|
println!("disconnect: {:?}", client.disconnect().await);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|