on master help sign in
working lldb example
commitf92fb966c086b421b49a57d98ba21eedd56a99d5 authorDmitry Sharshakov <d3dx12.xx@gmail.com> dateSat 14 Aug 2021, 14:23 (5 years ago) parentae32159
2 files changed+46−31
helix-dap/examples/dap-lldb.rs+3−3 helix-dap/src/client.rs+43−28
helix-dap/examples/dap-lldb.rs+3−3
@@ -57,7 +57,7 @@ pub async fn main() -> Result<()> {
5757 "/tmp/cdebug/main.c".to_owned(),
5858 vec![SourceBreakpoint {
5959 line: 6,
60− column: Some(4),
60+ column: Some(2),
6161 condition: None,
6262 hit_condition: None,
6363 log_message: None,
@@ -82,7 +82,7 @@ pub async fn main() -> Result<()> {
8282 let threads = client.threads().await?;
8383 println!("threads: {:#?}", threads);
8484 let bt = client
85− .stack_trace(threads[2].id)
85+ .stack_trace(threads[0].id)
8686 .await
8787 .expect("expected stack trace");
8888 println!("stack trace: {:#?}", bt);
@@ -93,7 +93,7 @@ pub async fn main() -> Result<()> {
9393 println!("scopes: {:#?}", scopes);
9494 println!(
9595 "vars: {:#?}",
96− client.variables(scopes[1].variables_reference).await
96+ client.variables(scopes[0].variables_reference).await
9797 );
9898
9999 let mut _in = String::new();
helix-dap/src/client.rs+43−28
@@ -12,6 +12,7 @@ use std::sync::{
1212use std::{collections::HashMap, process::Stdio};
1313use tokio::{
1414 io::{AsyncBufRead, AsyncWrite, BufReader, BufWriter},
15+ join,
1516 net::TcpStream,
1617 process::{Child, Command},
1718 sync::{
@@ -449,7 +450,12 @@ impl Client {
449450 self.request_counter.fetch_add(1, Ordering::Relaxed)
450451 }
451452
452− async fn request(&self, command: String, arguments: Option<Value>) -> Result<Response> {
453+ async fn request(
454+ &self,
455+ command: String,
456+ arguments: Option<Value>,
457+ response: bool,
458+ ) -> Result<Option<Response>> {
453459 let (callback_rx, mut callback_tx) = channel(1);
454460
455461 let req = Request {
@@ -464,10 +470,11 @@ impl Client {
464470 .send(req)
465471 .expect("Failed to send request to debugger");
466472
467− callback_tx
468− .recv()
469− .await
470− .expect("Failed to receive response")
473+ if response {
474+ Ok(Some(callback_tx.recv().await.unwrap()?))
475+ } else {
476+ Ok(None)
477+ }
471478 }
472479
473480 pub fn capabilities(&self) -> &DebuggerCapabilities {
@@ -494,25 +501,25 @@ impl Client {
494501 };
495502
496503 let response = self
497− .request("initialize".to_owned(), to_value(args).ok())
498− .await?;
504+ .request("initialize".to_owned(), to_value(args).ok(), true)
505+ .await?
506+ .unwrap();
499507 self.capabilities = from_value(response.body.unwrap()).ok();
500508
501509 Ok(())
502510 }
503511
504512 pub async fn disconnect(&mut self) -> Result<()> {
505− self.request("disconnect".to_owned(), None).await?;
513+ self.request("disconnect".to_owned(), None, true).await?;
506514 Ok(())
507515 }
508516
509517 pub async fn launch(&mut self, args: impl Serialize) -> Result<()> {
510518 let mut initialized = self.listen_for_event("initialized".to_owned()).await;
511519
512− self.request("launch".to_owned(), to_value(args).ok())
513− .await?;
514−
515− initialized.recv().await;
520+ let res = self.request("launch".to_owned(), to_value(args).ok(), true);
521+ let ev = initialized.recv();
522+ join!(res, ev).0?;
516523
517524 Ok(())
518525 }
@@ -520,10 +527,9 @@ impl Client {
520527 pub async fn attach(&mut self, args: impl Serialize) -> Result<()> {
521528 let mut initialized = self.listen_for_event("initialized".to_owned()).await;
522529
523− self.request("attach".to_owned(), to_value(args).ok())
524− .await?;
525−
526− initialized.recv().await;
530+ let res = self.request("attach".to_owned(), to_value(args).ok(), false);
531+ let ev = initialized.recv();
532+ join!(res, ev).0?;
527533
528534 Ok(())
529535 }
@@ -549,15 +555,17 @@ impl Client {
549555 };
550556
551557 let response = self
552− .request("setBreakpoints".to_owned(), to_value(args).ok())
553− .await?;
558+ .request("setBreakpoints".to_owned(), to_value(args).ok(), true)
559+ .await?
560+ .unwrap();
554561 let body: Option<SetBreakpointsResponseBody> = from_value(response.body.unwrap()).ok();
555562
556563 Ok(body.map(|b| b.breakpoints).unwrap())
557564 }
558565
559566 pub async fn configuration_done(&mut self) -> Result<()> {
560− self.request("configurationDone".to_owned(), None).await?;
567+ self.request("configurationDone".to_owned(), None, true)
568+ .await?;
561569 Ok(())
562570 }
563571
@@ -565,8 +573,9 @@ impl Client {
565573 let args = ContinueArguments { thread_id };
566574
567575 let response = self
568− .request("continue".to_owned(), to_value(args).ok())
569− .await?;
576+ .request("continue".to_owned(), to_value(args).ok(), true)
577+ .await?
578+ .unwrap();
570579
571580 let body: Option<ContinueResponseBody> = from_value(response.body.unwrap()).ok();
572581
@@ -585,8 +594,9 @@ impl Client {
585594 };
586595
587596 let response = self
588− .request("stackTrace".to_owned(), to_value(args).ok())
589− .await?;
597+ .request("stackTrace".to_owned(), to_value(args).ok(), true)
598+ .await?
599+ .unwrap();
590600
591601 let body: StackTraceResponseBody = from_value(response.body.unwrap()).unwrap();
592602
@@ -594,7 +604,10 @@ impl Client {
594604 }
595605
596606 pub async fn threads(&mut self) -> Result<Vec<Thread>> {
597− let response = self.request("threads".to_owned(), None).await?;
607+ let response = self
608+ .request("threads".to_owned(), None, true)
609+ .await?
610+ .unwrap();
598611
599612 let body: ThreadsResponseBody = from_value(response.body.unwrap()).unwrap();
600613
@@ -605,8 +618,9 @@ impl Client {
605618 let args = ScopesArguments { frame_id };
606619
607620 let response = self
608− .request("scopes".to_owned(), to_value(args).ok())
609− .await?;
621+ .request("scopes".to_owned(), to_value(args).ok(), true)
622+ .await?
623+ .unwrap();
610624
611625 let body: ScopesResponseBody = from_value(response.body.unwrap()).unwrap();
612626
@@ -623,8 +637,9 @@ impl Client {
623637 };
624638
625639 let response = self
626− .request("variables".to_owned(), to_value(args).ok())
627− .await?;
640+ .request("variables".to_owned(), to_value(args).ok(), true)
641+ .await?
642+ .unwrap();
628643
629644 let body: VariablesResponseBody = from_value(response.body.unwrap()).unwrap();
630645