Skip to content

Commit

Permalink
Upstream debugger changes from iced-gui branch
Browse files Browse the repository at this point in the history
  • Loading branch information
simonrw committed Dec 6, 2023
1 parent 1a929e8 commit bd8e9a0
Showing 1 changed file with 37 additions and 25 deletions.
62 changes: 37 additions & 25 deletions debugger/src/internals.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Context;
use std::collections::HashMap;
use std::{collections::HashMap, path::PathBuf};
use transport::{
requests, responses,
types::{Source, SourceBreakpoint, ThreadId},
Expand Down Expand Up @@ -156,34 +156,46 @@ impl DebuggerInternals {
return Ok(());
}

let first_breakpoint = self.breakpoints.values().next().unwrap();

let req = requests::RequestBody::SetBreakpoints(requests::SetBreakpoints {
source: Source {
name: first_breakpoint.name.clone(),
path: Some(first_breakpoint.path.clone()),
// group breakpoints by source file and send in multiple batches
let breakpoints_by_source = self.breakpoints_by_source();

for (source, breakpoints) in &breakpoints_by_source {
let req = requests::RequestBody::SetBreakpoints(requests::SetBreakpoints {
source: Source {
name: Some(source.display().to_string()),
path: Some(source.clone()),
..Default::default()
},
lines: Some(breakpoints.iter().map(|b| b.line).collect()),
breakpoints: Some(
breakpoints
.iter()
.map(|b| SourceBreakpoint {
line: b.line,
..Default::default()
})
.collect(),
),
..Default::default()
},
lines: Some(self.breakpoints.values().map(|b| b.line).collect()),
breakpoints: Some(
self.breakpoints
.values()
.map(|b| SourceBreakpoint {
line: b.line,
..Default::default()
})
.collect(),
),
..Default::default()
});

let _ = self
.client
.send(req)
.context("broadcasting breakpoints to debugee")?;
});

let _ = self
.client
.send(req)
.context("broadcasting breakpoints to debugee")?;
}
Ok(())
}

fn breakpoints_by_source(&self) -> HashMap<PathBuf, Vec<Breakpoint>> {
let mut out = HashMap::new();
for breakpoint in self.breakpoints.values() {
let file_breakpoints = out.entry(breakpoint.path.clone()).or_insert(Vec::new());
file_breakpoints.push(breakpoint.clone());
}
out
}

fn next_id(&mut self) -> BreakpointId {
self.current_breakpoint_id += 1;
self.current_breakpoint_id
Expand Down

0 comments on commit bd8e9a0

Please sign in to comment.