2021-10-17 07:11:59 +02:00
|
|
|
use helix_dap::{events, Client, Event, Payload, Result, SourceBreakpoint, ThreadId};
|
2021-08-13 19:24:27 +02:00
|
|
|
use serde::{Deserialize, Serialize};
|
2021-08-22 11:13:43 +02:00
|
|
|
use serde_json::to_value;
|
2021-08-21 19:19:11 +02:00
|
|
|
use tokio::sync::mpsc::UnboundedReceiver;
|
2021-08-13 19:24:27 +02:00
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
struct LaunchArguments {
|
|
|
|
program: String,
|
2021-08-14 12:19:38 +02:00
|
|
|
console: String,
|
2021-08-13 19:24:27 +02:00
|
|
|
}
|
2021-08-12 15:35:15 +02:00
|
|
|
|
2021-08-21 19:19:11 +02:00
|
|
|
async fn dispatch(mut rx: UnboundedReceiver<Payload>) {
|
2021-08-15 09:14:11 +02:00
|
|
|
loop {
|
2021-08-21 19:19:11 +02:00
|
|
|
match rx.recv().await.unwrap() {
|
2021-08-22 11:13:43 +02:00
|
|
|
Payload::Event(Event::Output(events::Output {
|
|
|
|
category, output, ..
|
|
|
|
})) => {
|
|
|
|
println!(
|
|
|
|
"> [{}] {}",
|
|
|
|
category.unwrap_or("unknown".to_owned()),
|
|
|
|
output
|
|
|
|
);
|
|
|
|
}
|
|
|
|
Payload::Event(Event::Stopped(_)) => {
|
|
|
|
println!("stopped");
|
|
|
|
}
|
|
|
|
_ => {}
|
2021-08-21 19:19:11 +02:00
|
|
|
};
|
2021-08-15 09:14:11 +02:00
|
|
|
}
|
2021-08-14 08:14:05 +02:00
|
|
|
}
|
|
|
|
|
2021-08-12 15:35:15 +02:00
|
|
|
#[tokio::main]
|
|
|
|
pub async fn main() -> Result<()> {
|
2021-08-12 15:45:01 +02: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-21 19:19:11 +02:00
|
|
|
let (mut client, events) = Client::tcp_process("lldb-vscode", vec![], "-p {}", 0).await?;
|
2021-08-13 19:13:27 +02:00
|
|
|
println!("create: {:?}", client);
|
2021-08-12 15:35:15 +02:00
|
|
|
|
2021-08-21 19:19:11 +02:00
|
|
|
tokio::spawn(dispatch(events));
|
2021-08-14 08:14:05 +02:00
|
|
|
|
2021-08-30 15:09:41 +02:00
|
|
|
println!(
|
|
|
|
"init: {:?}",
|
|
|
|
client.initialize("lldb-vscode".to_owned()).await
|
|
|
|
);
|
2021-08-14 10:41:23 +02:00
|
|
|
println!("caps: {:?}", client.capabilities());
|
2021-08-13 19:24:27 +02:00
|
|
|
|
|
|
|
let args = LaunchArguments {
|
2021-08-14 12:19:38 +02:00
|
|
|
program: "/tmp/cdebug/main".to_owned(),
|
|
|
|
console: "internalConsole".to_owned(),
|
2021-08-13 19:24:27 +02:00
|
|
|
};
|
|
|
|
|
2021-08-16 07:05:10 +02:00
|
|
|
println!("launch: {:?}", client.launch(to_value(args)?).await);
|
2021-08-12 15:35:15 +02:00
|
|
|
|
|
|
|
println!(
|
2021-08-12 16:49:12 +02:00
|
|
|
"breakpoints: {:#?}",
|
2021-08-12 15:35:15 +02:00
|
|
|
client
|
|
|
|
.set_breakpoints(
|
2021-08-20 15:48:59 +02:00
|
|
|
"/tmp/cdebug/main.c".into(),
|
2021-08-12 15:35:15 +02:00
|
|
|
vec![SourceBreakpoint {
|
2021-08-14 12:31:05 +02:00
|
|
|
line: 6,
|
2021-08-14 13:23:19 +02:00
|
|
|
column: Some(2),
|
2021-08-12 20:23:55 +02:00
|
|
|
condition: None,
|
|
|
|
hit_condition: None,
|
|
|
|
log_message: None,
|
2021-08-12 15:35:15 +02:00
|
|
|
}]
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut _in = String::new();
|
|
|
|
std::io::stdin()
|
|
|
|
.read_line(&mut _in)
|
|
|
|
.expect("Failed to read line");
|
|
|
|
|
|
|
|
println!("configurationDone: {:?}", client.configuration_done().await);
|
2021-08-14 07:42:06 +02:00
|
|
|
|
2021-09-04 18:36:36 +02:00
|
|
|
let mut _in = String::new();
|
|
|
|
std::io::stdin()
|
|
|
|
.read_line(&mut _in)
|
|
|
|
.expect("Failed to read line");
|
|
|
|
|
2021-08-14 12:19:38 +02:00
|
|
|
let threads = client.threads().await?;
|
|
|
|
println!("threads: {:#?}", threads);
|
|
|
|
let bt = client
|
2021-08-14 13:23:19 +02:00
|
|
|
.stack_trace(threads[0].id)
|
2021-08-14 12:19:38 +02:00
|
|
|
.await
|
|
|
|
.expect("expected stack trace");
|
2021-08-12 19:47:14 +02: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 13:23:19 +02:00
|
|
|
client.variables(scopes[0].variables_reference).await
|
2021-08-12 19:47:14 +02:00
|
|
|
);
|
2021-08-12 15:35:15 +02:00
|
|
|
|
|
|
|
let mut _in = String::new();
|
|
|
|
std::io::stdin()
|
|
|
|
.read_line(&mut _in)
|
|
|
|
.expect("Failed to read line");
|
|
|
|
|
2021-10-17 07:11:59 +02:00
|
|
|
println!(
|
|
|
|
"continued: {:?}",
|
|
|
|
client.continue_thread(ThreadId::default()).await
|
|
|
|
);
|
2021-08-12 15:35:15 +02:00
|
|
|
|
|
|
|
let mut _in = String::new();
|
|
|
|
std::io::stdin()
|
|
|
|
.read_line(&mut _in)
|
|
|
|
.expect("Failed to read line");
|
|
|
|
|
|
|
|
println!("disconnect: {:?}", client.disconnect().await);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|