Skip to content

Commit d8fa03e

Browse files
committed
fix: for now make it run with noop for some tasks; add more methods for Replay
1 parent 966d626 commit d8fa03e

File tree

4 files changed

+161
-18
lines changed

4 files changed

+161
-18
lines changed

src/db-backend/src/db.rs

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

2121
const NEXT_INTERNAL_STEP_OVERS_LIMIT: usize = 1_000;
@@ -789,6 +789,67 @@ impl DbReplay {
789789
self.step_id = step_id;
790790
}
791791
}
792+
793+
fn to_program_event(&self, event_record: &DbRecordEvent, index: usize) -> ProgramEvent {
794+
let step_id_int = event_record.step_id.0;
795+
let (path, line) = if step_id_int != NO_INDEX {
796+
let step_record = &self.db.steps[event_record.step_id];
797+
(
798+
self.db
799+
.workdir
800+
.join(self.db.load_path_from_id(&step_record.path_id))
801+
.display()
802+
.to_string(),
803+
step_record.line.0,
804+
)
805+
} else {
806+
(NO_PATH.to_string(), NO_POSITION)
807+
};
808+
809+
ProgramEvent {
810+
kind: event_record.kind,
811+
content: event_record.content.clone(),
812+
bytes: event_record.content.len(),
813+
rr_event_id: index,
814+
direct_location_rr_ticks: step_id_int,
815+
metadata: event_record.metadata.to_string(),
816+
stdout: true,
817+
event_index: index,
818+
tracepoint_result_index: NO_INDEX,
819+
high_level_path: path,
820+
high_level_line: line,
821+
base64_encoded: false,
822+
max_rr_ticks: self
823+
.db
824+
.steps
825+
.last()
826+
.unwrap_or(&DbStep {
827+
step_id: StepId(0),
828+
path_id: PathId(0),
829+
line: Line(0),
830+
call_key: CallKey(0),
831+
global_call_key: CallKey(0),
832+
})
833+
.step_id
834+
.0,
835+
}
836+
}
837+
838+
fn single_step_line(&self, step_index: usize, forward: bool) -> usize {
839+
// taking note of db.lines limits: returning a valid step id always
840+
if forward {
841+
if step_index < self.db.steps.len() - 1 {
842+
step_index + 1
843+
} else {
844+
step_index
845+
}
846+
} else if step_index > 0 {
847+
step_index - 1
848+
} else {
849+
// auto-returning the same 0 if stepping backwards from 0
850+
step_index
851+
}
852+
}
792853
}
793854

794855
impl Replay for DbReplay {
@@ -802,4 +863,35 @@ impl Replay for DbReplay {
802863
self.step_id_jump(StepId(0));
803864
Ok(())
804865
}
866+
867+
fn load_events(&mut self) -> Result<Events, Box<dyn Error>> {
868+
let mut events: Vec<ProgramEvent> = vec![];
869+
let mut first_events: Vec<ProgramEvent> = vec![];
870+
let mut contents: String = "".to_string();
871+
872+
for (i, event_record) in self.db.events.iter().enumerate() {
873+
let mut event = self.to_program_event(event_record, i);
874+
event.content = event_record.content.to_string();
875+
events.push(event.clone());
876+
if i < 20 {
877+
first_events.push(event);
878+
contents.push_str(&format!("{}\\n\n", event_record.content));
879+
}
880+
}
881+
882+
Ok(Events {
883+
events,
884+
first_events,
885+
contents,
886+
})
887+
}
888+
889+
fn step_in(&mut self, forward: bool) -> Result<(), Box<dyn Error>> {
890+
self.step_id = StepId(self.single_step_line(self.step_id.0 as usize, forward) as i64);
891+
Ok(())
892+
}
893+
894+
fn current_step_id(&self) -> StepId {
895+
self.step_id
896+
}
805897
}

src/db-backend/src/handler.rs

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,13 @@ impl Handler {
339339
}
340340

341341
pub fn load_locals(&mut self, req: dap::Request, _args: task::CtLoadLocalsArguments) -> Result<(), Box<dyn Error>> {
342+
if self.trace_kind == TraceKind::RR {
343+
let locals: Vec<Variable> = vec![];
344+
warn!("load_locals not implemented for rr yet");
345+
self.respond_dap(req, task::CtLoadLocalsResponseBody { locals })?;
346+
return Ok(());
347+
}
348+
342349
let full_value_locals: Vec<Variable> = self.db.variables[self.step_id]
343350
.iter()
344351
.map(|v| Variable {
@@ -448,6 +455,11 @@ impl Handler {
448455
_req: dap::Request,
449456
args: CalltraceLoadArgs,
450457
) -> Result<(), Box<dyn Error>> {
458+
if self.trace_kind == TraceKind::RR {
459+
warn!("load_calltrace_section not implemented for rr");
460+
return Ok(());
461+
}
462+
451463
let start_call_line_index = args.start_call_line_index;
452464
let call_lines = self.load_local_calltrace(args)?;
453465
let total_count = self.calc_total_calls();
@@ -466,6 +478,19 @@ impl Handler {
466478
}
467479

468480
pub fn load_flow(&mut self, _req: dap::Request, arg: CtLoadFlowArguments) -> Result<(), Box<dyn Error>> {
481+
if self.trace_kind == TraceKind::RR {
482+
warn!("flow not implemented for rr");
483+
return Ok(());
484+
}
485+
// TODO: something like this for db/rr:
486+
// {
487+
// // TODO: pass step_id to load_location and let it jump for RR if needed?
488+
// // or have a separate jump_to when it's not self.step_id?
489+
// self.replay.jump_to(step_id)?;
490+
// let location = self.replay.load_location(&mut self.expr_loader)?;
491+
// let flow_update = self.flow_preloader.load(location, FlowMode::Call, &self.replay);
492+
// }
493+
469494
let flow_update = if arg.flow_mode == FlowMode::Call {
470495
let step_id = StepId(arg.location.rr_ticks.0);
471496
let call_key = self.db.steps[step_id].call_key;
@@ -538,7 +563,9 @@ impl Handler {
538563
}
539564

540565
pub fn step_in(&mut self, forward: bool) -> Result<(), Box<dyn Error>> {
541-
self.step_id = StepId(self.single_step_line(self.step_id.0 as usize, forward) as i64);
566+
self.replay.step_in(forward)?;
567+
self.step_id = self.replay.current_step_id();
568+
542569
Ok(())
543570
}
544571

@@ -670,19 +697,11 @@ impl Handler {
670697
}
671698

672699
pub fn event_load(&mut self, _req: dap::Request) -> Result<(), Box<dyn Error>> {
673-
let mut events: Vec<ProgramEvent> = vec![];
674-
let mut first_events: Vec<ProgramEvent> = vec![];
675-
let mut contents: String = "".to_string();
700+
let events_data = self.replay.load_events()?;
676701

677-
for (i, event_record) in self.db.events.iter().enumerate() {
678-
let mut event = self.to_program_event(event_record, i);
679-
event.content = event_record.content.to_string();
680-
events.push(event.clone());
681-
if i < 20 {
682-
first_events.push(event);
683-
contents.push_str(&format!("{}\\n\n", event_record.content));
684-
}
685-
}
702+
let events = events_data.events;
703+
let first_events = events_data.first_events;
704+
let contents = events_data.contents;
686705

687706
self.event_db.register_events(DbEventKind::Record, &events, vec![-1]);
688707
self.event_db.refresh_global();

src/db-backend/src/replay.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1+
use runtime_tracing::StepId;
12
use std::error::Error;
23

34
use crate::expr_loader::ExprLoader;
4-
use crate::task::Location;
5+
use crate::task::{Location, ProgramEvent};
6+
7+
#[derive(Debug, Clone)]
8+
pub struct Events {
9+
pub events: Vec<ProgramEvent>,
10+
pub first_events: Vec<ProgramEvent>,
11+
pub contents: String,
12+
}
513

614
pub trait Replay: std::fmt::Debug {
715
fn load_location(&mut self, expr_loader: &mut ExprLoader) -> Result<Location, Box<dyn Error>>;
816
fn run_to_entry(&mut self) -> Result<(), Box<dyn Error>>;
17+
fn load_events(&mut self) -> Result<Events, Box<dyn Error>>;
18+
fn step_in(&mut self, forward: bool) -> Result<(), Box<dyn Error>>;
19+
fn current_step_id(&self) -> StepId;
920
}

src/db-backend/src/rr_dispatcher.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ use std::process::{Child, Command, Stdio};
77
use std::thread;
88
use std::time::Duration;
99

10-
use log::info;
10+
use log::{info, warn};
11+
use runtime_tracing::StepId;
1112

1213
use crate::expr_loader::ExprLoader;
1314
use crate::paths::ct_rr_worker_socket_path;
1415
use crate::query::CtRRQuery;
15-
use crate::replay::Replay;
16+
use crate::replay::{Events, Replay};
1617
use crate::task::Location;
1718

1819
#[derive(Debug)]
@@ -157,4 +158,24 @@ impl Replay for RRDispatcher {
157158
let _ok = self.stable.run_query(CtRRQuery::RunToEntry)?;
158159
Ok(())
159160
}
161+
162+
fn load_events(&mut self) -> Result<Events, Box<dyn Error>> {
163+
self.ensure_active_stable()?;
164+
warn!("TODO load_events rr");
165+
Ok(Events {
166+
events: vec![],
167+
first_events: vec![],
168+
contents: "".to_string(),
169+
})
170+
}
171+
172+
fn step_in(&mut self, forward: bool) -> Result<(), Box<dyn Error>> {
173+
todo!()
174+
}
175+
176+
fn current_step_id(&self) -> StepId {
177+
// cache location or step_id and return
178+
// OR always load from worker
179+
todo!()
180+
}
160181
}

0 commit comments

Comments
 (0)