Skip to content

Commit 5753772

Browse files
committed
feat: start generalizing breakpoint/source line jump logic; not finished
also TODO: add rr logic for the new primitives
1 parent 57be897 commit 5753772

File tree

6 files changed

+56
-30
lines changed

6 files changed

+56
-30
lines changed

src/db-backend/src/dap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ pub fn read_dap_message_from_reader<R: std::io::BufRead>(reader: &mut R) -> DapR
400400
.read_exact(&mut buf)
401401
.map_err(|e| serde_json::Error::custom(e.to_string()))?;
402402
let json_text = std::str::from_utf8(&buf).map_err(|e| serde_json::Error::custom(e.to_string()))?;
403-
info!("DAP raw <- {json_text}");
403+
// info!("DAP raw <- {json_text}");
404404
from_json(json_text)
405405
}
406406

src/db-backend/src/dap_server.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ pub fn handle_message<T: DapTransport>(
282282
ctx: &mut Ctx,
283283
) -> Result<(), Box<dyn Error>> {
284284
info!("Handling message: {:?}", msg);
285+
if let DapMessage::Request(req) = msg {
286+
info!(" request {}", req.command);
287+
}
288+
285289
match msg {
286290
DapMessage::Request(req) if req.command == "initialize" => {
287291
let capabilities = Capabilities {

src/db-backend/src/db.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::distinct_vec::DistinctVec;
1515
use crate::expr_loader::ExprLoader;
1616
use crate::lang::Lang;
1717
use crate::replay::{Events, Replay};
18-
use crate::task::{Action, Call, CallArg, Location, ProgramEvent, RRTicks, NO_INDEX, NO_PATH, NO_POSITION, CtLoadLocalsArguments, Variable};
18+
use crate::task::{Action, Breakpoint, Call, CallArg, Location, ProgramEvent, RRTicks, NO_INDEX, NO_PATH, NO_POSITION, CtLoadLocalsArguments, Variable};
1919
use crate::value::{Type, Value};
2020

2121
const NEXT_INTERNAL_STEP_OVERS_LIMIT: usize = 1_000;
@@ -777,24 +777,19 @@ pub enum EndOfProgram {
777777
// pub place: Place,
778778
// }
779779

780-
#[derive(Debug, Clone, Serialize, Deserialize)]
781-
pub struct BreakpointRecord {
782-
pub is_active: bool,
783-
}
784-
785780
// type LineTraceMap = HashMap<usize, Vec<(usize, String)>>;
786781

787782
#[derive(Debug)]
788783
pub struct DbReplay {
789784
pub db: Box<Db>,
790785
pub step_id: StepId,
791786
pub call_key: CallKey,
792-
pub breakpoint_list: Vec<HashMap<usize, BreakpointRecord>>,
787+
pub breakpoint_list: Vec<HashMap<usize, Breakpoint>>,
793788
}
794789

795790
impl DbReplay {
796791
pub fn new(db: Box<Db>) -> DbReplay {
797-
let mut breakpoint_list: Vec<HashMap<usize, BreakpointRecord>> = Default::default();
792+
let mut breakpoint_list: Vec<HashMap<usize, Breakpoint>> = Default::default();
798793
breakpoint_list.resize_with(db.paths.len(), HashMap::new);
799794
DbReplay { db, step_id: StepId(0), call_key: CallKey(0), breakpoint_list }
800795
}
@@ -924,6 +919,10 @@ impl DbReplay {
924919
// false: hasn't hit a breakpoint
925920
Ok(false)
926921
}
922+
923+
fn load_path_id(&self, path: &str) -> Option<PathId> {
924+
self.db.path_map.get(path).copied()
925+
}
927926
}
928927

929928
impl Replay for DbReplay {
@@ -1031,6 +1030,16 @@ impl Replay for DbReplay {
10311030
Ok(true)
10321031
}
10331032

1033+
fn add_breakpoint(&mut self, path: &str, line: i64) -> Result<Breakpoint, Box<dyn Error>> {
1034+
let path_id_res: Result<PathId, Box<dyn Error>> = self
1035+
.load_path_id(&loc.path)
1036+
.ok_or(format!("can't add a breakpoint: can't find path `{}`` in trace", loc.path).into());
1037+
let path_id = path_id_res?;
1038+
let inner_map = &mut self.breakpoint_list[path_id.0];
1039+
let breakpoint = Breakpoint { enabled: true, id: self.breakpoint_next_id };
1040+
self.breakpoint_next_i
1041+
inner_map.insert(loc.line, Breakpoint { is_active: true });
1042+
}
10341043
fn current_step_id(&mut self) -> StepId {
10351044
self.step_id
10361045
}

src/db-backend/src/handler.rs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use runtime_tracing::{CallKey, EventLogKind, Line, PathId, StepId, VariableId, N
1010

1111
use crate::calltrace::Calltrace;
1212
use crate::dap::{self, DapClient, DapMessage};
13-
use crate::db::{BreakpointRecord, Db, DbCall, DbRecordEvent, DbReplay, DbStep};
13+
use crate::db::{Db, DbCall, DbRecordEvent, DbReplay, DbStep};
1414
use crate::event_db::{EventDb, SingleTableId};
1515
use crate::expr_loader::ExprLoader;
1616
use crate::flow_preloader::FlowPreloader;
@@ -57,8 +57,6 @@ pub struct Handler {
5757
pub replay: Box<dyn Replay>,
5858
pub ct_rr_args: CtRRArgs,
5959
pub load_flow_index: usize,
60-
61-
pub breakpoint_list: Vec<HashMap<usize, BreakpointRecord>>,
6260
}
6361

6462
#[derive(Debug, Clone, PartialEq)]
@@ -94,8 +92,6 @@ impl Handler {
9492
let calltrace = Calltrace::new(&db);
9593
let trace = CoreTrace::default();
9694
let mut expr_loader = ExprLoader::new(trace.clone());
97-
let mut breakpoint_list: Vec<HashMap<usize, BreakpointRecord>> = Default::default();
98-
breakpoint_list.resize_with(db.paths.len(), HashMap::new);
9995
let step_lines_loader = StepLinesLoader::new(&db, &mut expr_loader);
10096
let replay: Box<dyn Replay> = if trace_kind == TraceKind::DB {
10197
Box::new(DbReplay::new(db.clone()))
@@ -110,7 +106,6 @@ impl Handler {
110106
last_call_key: CallKey(0),
111107
indirect_send,
112108
// sender,
113-
breakpoint_list,
114109
event_db: EventDb::new(),
115110
flow_preloader: FlowPreloader::new(),
116111
expr_loader,
@@ -809,14 +804,31 @@ impl Handler {
809804
_req: dap::Request,
810805
source_location: SourceLocation,
811806
) -> Result<(), Box<dyn Error>> {
812-
if let Some(step_id) = self.get_closest_step_id(&source_location) {
813-
self.replay.jump_to(step_id)?;
814-
self.step_id = self.replay.current_step_id();
815-
self.complete_move(false)?;
816-
Ok(())
807+
if self.trace_kind == TraceKind::DB {
808+
if let Some(step_id) = self.get_closest_step_id(&source_location) {
809+
self.replay.jump_to(step_id)?;
810+
self.step_id = self.replay.current_step_id();
811+
self.complete_move(false)?;
812+
Ok(())
813+
} else {
814+
let err: String = format!("unknown location: {}", &source_location);
815+
Err(err.into())
816+
}
817817
} else {
818-
let err: String = format!("unknown location: {}", &source_location);
819-
Err(err.into())
818+
let b = self.replay.add_breakpoint(&source_location.path, source_location.line as i64)?;
819+
match self.replay.step(Action::Continue, true) {
820+
Ok(_) => {
821+
self.replay.delete_breakpoint(&b)?; // make sure we do it before potential `?` fail in next functions
822+
let _location = self.replay.load_location(&mut self.expr_loader)?;
823+
self.step_id = self.replay.current_step_id();
824+
self.complete_move(false)?;
825+
Ok(())
826+
}
827+
Err(e) => {
828+
self.replay.delete_breakpoint(&b)?;
829+
Err(e)
830+
}
831+
}
820832
}
821833
}
822834

@@ -882,13 +894,8 @@ impl Handler {
882894
}
883895

884896
pub fn add_breakpoint(&mut self, loc: SourceLocation, _task: Task) -> Result<(), Box<dyn Error>> {
885-
let path_id_res: Result<PathId, Box<dyn Error>> = self
886-
.load_path_id(&loc.path)
887-
.ok_or(format!("can't add a breakpoint: can't find path `{}`` in trace", loc.path).into());
888-
let path_id = path_id_res?;
889-
let inner_map = &mut self.breakpoint_list[path_id.0];
890-
inner_map.insert(loc.line, BreakpointRecord { is_active: true });
891-
Ok(())
897+
self.replay.add_breakpoint(&loc.path, loc.line as i64)?;
898+
Ok(())
892899
}
893900

894901
pub fn delete_breakpoint(&mut self, loc: SourceLocation, _task: Task) -> Result<(), Box<dyn Error>> {

src/db-backend/src/replay.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::error::Error;
33

44
use crate::db::DbRecordEvent;
55
use crate::expr_loader::ExprLoader;
6-
use crate::task::{Action, Location, ProgramEvent, CtLoadLocalsArguments, Variable};
6+
use crate::task::{Action, Breakpoint, Location, ProgramEvent, CtLoadLocalsArguments, Variable};
77

88
#[derive(Debug, Clone)]
99
pub struct Events {
@@ -23,5 +23,7 @@ pub trait Replay: std::fmt::Debug {
2323
fn load_return_value(&mut self) -> Result<ValueRecord, Box<dyn Error>>;
2424
fn load_step_events(&mut self, step_id: StepId, exact: bool) -> Vec<DbRecordEvent>;
2525
fn jump_to(&mut self, step_id: StepId) -> Result<bool, Box<dyn Error>>;
26+
fn add_breakpoint(&mut self, path: &str, line: i64) -> Result<Breakpoint, Box<dyn Error>>;
27+
fn delete_breakpoint(&mut self, breakpoint: &Breakpoint) -> Result<bool, Box<dyn Error>>;
2628
fn current_step_id(&mut self) -> StepId;
2729
}

src/db-backend/src/task.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,10 @@ pub struct TracepointResults {
16401640
pub first_update: bool,
16411641
}
16421642

1643+
pub struct Breakpoint {
1644+
pub id: i64,
1645+
pub enabled: bool,
1646+
}
16431647
pub static mut TASK_ID_MAP: &mut [usize] = &mut [0; 100];
16441648
pub static mut EVENT_ID_MAP: &mut [usize] = &mut [0; 100];
16451649

0 commit comments

Comments
 (0)