Skip to content

Commit c708ded

Browse files
committed
feat: try to generalize a bit of move to first flow step logic: prepare jump_to_call
TODO: rr jump_to_call
1 parent 4c0ed93 commit c708ded

File tree

11 files changed

+61
-25
lines changed

11 files changed

+61
-25
lines changed

src/db-backend/src/bin/virtualization-layers.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ use std::path::PathBuf;
2020
extern crate db_backend;
2121
use db_backend::core::Core;
2222
use db_backend::db::Db;
23-
use db_backend::handler::{Handler, TraceKind};
23+
use db_backend::handler::Handler;
2424
use db_backend::rr_dispatcher::CtRRArgs;
25+
use db_backend::task::TraceKind;
2526
// use db_backend::receiver::Receiver;
2627
// use db_backend::response::Response;
2728

src/db-backend/src/dap_server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ use crate::dap::{self, Capabilities, DapMessage, Event, ProtocolMessage, Respons
22
use crate::dap_types;
33

44
use crate::db::Db;
5-
use crate::handler::{Handler, TraceKind};
5+
use crate::handler::Handler;
66
use crate::paths::CODETRACER_PATHS;
77
use crate::rr_dispatcher::CtRRArgs;
88
use crate::task::{
99
Action, CallSearchArg, CalltraceLoadArgs, CollapseCallsArgs, CtLoadFlowArguments,
1010
CtLoadLocalsArguments, FunctionLocation, LoadHistoryArg, LocalStepJump, Location, ProgramEvent, RunTracepointsArg,
11-
SourceCallJumpTarget, SourceLocation, StepArg, TracepointId, UpdateTableArgs,
11+
SourceCallJumpTarget, SourceLocation, StepArg, TraceKind, TracepointId, UpdateTableArgs,
1212
};
1313

1414
use crate::trace_processor::{load_trace_data, load_trace_metadata, TraceProcessor};

src/db-backend/src/db.rs

Lines changed: 11 additions & 2 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, Breakpoint, Call, CallArg, Location, ProgramEvent, RRTicks, NO_INDEX, NO_PATH, NO_POSITION, CtLoadLocalsArguments, Variable};
18+
use crate::task::{Action, Breakpoint, Call, CallArg, CoreTrace, 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;
@@ -1050,7 +1050,7 @@ impl Replay for DbReplay {
10501050
// let path_id = path_id_res?;
10511051
// let inner_map = &mut self.breakpoint_list[path_id.0];
10521052
// inner_map.remove(&loc.line);
1053-
todo!()
1053+
todo!()
10541054
}
10551055

10561056
fn delete_breakpoints(&mut self) -> Result<bool, Box<dyn Error>> {
@@ -1070,6 +1070,15 @@ impl Replay for DbReplay {
10701070
Ok(toggled_breakpoint)
10711071
}
10721072

1073+
fn jump_to_call(&mut self, location: &Location) -> Result<Location, Box<dyn Error>> {
1074+
let step = self.db.steps[StepId(location.rr_ticks.0)];
1075+
let call_key = step.call_key;
1076+
let first_call_step_id = self.db.calls[call_key].step_id;
1077+
self.jump_to(first_call_step_id)?;
1078+
let mut expr_loader = ExprLoader::new(CoreTrace::default());
1079+
self.load_location(&mut expr_loader)
1080+
}
1081+
10731082
fn current_step_id(&mut self) -> StepId {
10741083
self.step_id
10751084
}

src/db-backend/src/diff.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use runtime_tracing::FunctionId;
99
use log::info;
1010

1111
use crate::db::{Db,DbReplay};
12+
use crate::task::TraceKind;
1213
use crate::trace_processor::{load_trace_data, load_trace_metadata, TraceProcessor};
1314
use crate::flow_preloader::FlowPreloader;
1415

@@ -147,7 +148,7 @@ pub fn index_diff(diff: Diff, trace_folder: &Path, multitrace_folder: &Path) ->
147148
info!("diff_lines {diff_lines:?}");
148149
let mut flow_preloader = FlowPreloader::new();
149150
let mut replay = DbReplay::new(Box::new(db.clone()));
150-
let flow_update = flow_preloader.load_diff_flow(diff_lines, &db, &mut replay);
151+
let flow_update = flow_preloader.load_diff_flow(diff_lines, &db, TraceKind::DB, &mut replay);
151152

152153
let raw = serde_json::to_string(&flow_update)?;
153154
std::fs::write(multitrace_folder.join("diff_index.json"), raw)?;

src/db-backend/src/flow_preloader.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
expr_loader::ExprLoader,
44
task::{
55
Action, BranchesTaken, CoreTrace, FlowEvent, FlowStep, FlowUpdate, FlowUpdateState, FlowUpdateStateKind,
6-
FlowMode, FlowViewUpdate, Iteration, Location, Loop, LoopId, LoopIterationSteps, Position, RRTicks, StepCount
6+
FlowMode, FlowViewUpdate, Iteration, Location, Loop, LoopId, LoopIterationSteps, Position, RRTicks, StepCount, TraceKind,
77
},
88
replay::Replay,
99
value::Value,
@@ -27,13 +27,13 @@ impl FlowPreloader {
2727
}
2828
}
2929

30-
pub fn load(&mut self, location: Location, mode: FlowMode, replay: &mut dyn Replay) -> FlowUpdate {
30+
pub fn load(&mut self, location: Location, mode: FlowMode, kind: TraceKind, replay: &mut dyn Replay) -> FlowUpdate {
3131
info!("flow: load: {:?}", location);
3232
let path_buf = PathBuf::from(&location.path);
3333
match self.expr_loader.load_file(&path_buf) {
3434
Ok(_) => {
3535
info!("Expression loader complete!");
36-
let mut call_flow_preloader: CallFlowPreloader = CallFlowPreloader::new(self, location.clone(), HashSet::new(), HashSet::new(), mode);
36+
let mut call_flow_preloader: CallFlowPreloader = CallFlowPreloader::new(self, location.clone(), HashSet::new(), HashSet::new(), mode, kind);
3737
call_flow_preloader.load_flow(location, replay)
3838
}
3939
Err(e) => {
@@ -43,7 +43,7 @@ impl FlowPreloader {
4343
}
4444
}
4545

46-
pub fn load_diff_flow(&mut self, diff_lines: HashSet<(PathBuf, i64)>, db: &Db, replay: &mut dyn Replay) -> FlowUpdate {
46+
pub fn load_diff_flow(&mut self, diff_lines: HashSet<(PathBuf, i64)>, db: &Db, trace_kind: TraceKind, replay: &mut dyn Replay) -> FlowUpdate {
4747
info!("load_diff_flow");
4848
for diff_line in &diff_lines {
4949
match self.expr_loader.load_file(&diff_line.0) {
@@ -69,7 +69,7 @@ impl FlowPreloader {
6969
}
7070
}
7171

72-
let mut call_flow_preloader = CallFlowPreloader::new(self, Location::default(), diff_lines, diff_call_keys, FlowMode::Diff);
72+
let mut call_flow_preloader = CallFlowPreloader::new(self, Location::default(), diff_lines, diff_call_keys, FlowMode::Diff, trace_kind);
7373
let location = Location { line: 1, ..Location::default() };
7474
call_flow_preloader.load_flow(location, replay)
7575
}
@@ -97,10 +97,17 @@ pub struct CallFlowPreloader<'a> {
9797
diff_lines: HashSet<(PathBuf, i64)>,
9898
diff_call_keys: HashSet<i64>, // TODO: if we add Eq, Hash it seems we can do CallKey
9999
mode: FlowMode,
100+
trace_kind: TraceKind,
100101
}
101102

102103
impl<'a> CallFlowPreloader<'a> {
103-
pub fn new(flow_preloader: &'a FlowPreloader, location: Location, diff_lines: HashSet<(PathBuf, i64)>, diff_call_keys: HashSet<i64>, mode: FlowMode) -> Self {
104+
pub fn new(
105+
flow_preloader: &'a FlowPreloader,
106+
location: Location,
107+
diff_lines: HashSet<(PathBuf, i64)>,
108+
diff_call_keys: HashSet<i64>,
109+
mode: FlowMode,
110+
trace_kind: TraceKind) -> Self {
104111
CallFlowPreloader {
105112
flow_preloader,
106113
location,
@@ -110,6 +117,7 @@ impl<'a> CallFlowPreloader<'a> {
110117
diff_lines,
111118
diff_call_keys,
112119
mode,
120+
trace_kind,
113121
}
114122
}
115123

@@ -236,11 +244,17 @@ impl<'a> CallFlowPreloader<'a> {
236244
}
237245

238246
fn move_to_first_step(&self, from_step_id: StepId, replay: &mut dyn Replay) -> Result<(StepId, bool), Box<dyn Error>> {
239-
let (step_id, progressing) = match self.mode {
247+
let (mut step_id, mut progressing) = match self.mode {
240248
FlowMode::Call => (from_step_id, true),
241249
FlowMode::Diff => self.next_diff_flow_step(StepId(0), true, replay),
242250
};
243-
replay.jump_to(step_id)?;
251+
if self.trace_kind == TraceKind::DB {
252+
replay.jump_to(step_id)?;
253+
} else {
254+
let location = replay.jump_to_call(&self.location)?;
255+
step_id = StepId(location.rr_ticks.0);
256+
progressing = true;
257+
}
244258
Ok((step_id, progressing))
245259
}
246260

src/db-backend/src/handler.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::task::{
2727
CollapseCallsArgs, CoreTrace, DbEventKind, FrameInfo, FunctionLocation, FlowMode, HistoryResult, HistoryUpdate, Instruction,
2828
CtLoadFlowArguments, FlowUpdate, Instructions, LoadHistoryArg, LoadStepLinesArg, LoadStepLinesUpdate, LocalStepJump, Location, MoveState,
2929
Notification, NotificationKind, ProgramEvent, RRGDBStopSignal, RRTicks, RegisterEventsArg, RunTracepointsArg,
30-
SourceCallJumpTarget, SourceLocation, StepArg, Stop, StopType, Task, TraceUpdate, TracepointId, TracepointResults,
30+
SourceCallJumpTarget, SourceLocation, StepArg, Stop, StopType, Task, TraceKind, TraceUpdate, TracepointId, TracepointResults,
3131
UpdateTableArgs, Variable, NO_INDEX, NO_PATH, NO_POSITION, NO_STEP_ID,
3232
};
3333
use crate::tracepoint_interpreter::TracepointInterpreter;
@@ -60,12 +60,6 @@ pub struct Handler {
6060
pub load_flow_index: usize,
6161
}
6262

63-
#[derive(Debug, Clone, PartialEq)]
64-
pub enum TraceKind {
65-
DB,
66-
RR,
67-
}
68-
6963
// two choices:
7064
// return results and potentially
7165
// generate multiple events as a generator
@@ -454,7 +448,7 @@ impl Handler {
454448
// if possible for example
455449

456450
let flow_update = if arg.flow_mode == FlowMode::Call {
457-
self.flow_preloader.load(arg.location, arg.flow_mode, &mut *flow_replay)
451+
self.flow_preloader.load(arg.location, arg.flow_mode, self.trace_kind, &mut *flow_replay)
458452
} else {
459453
if let Some(raw_flow) = &self.raw_diff_index {
460454
serde_json::from_str::<FlowUpdate>(&raw_flow)?

src/db-backend/src/query.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use serde::{Deserialize, Serialize};
22

3-
use crate::task::{Action, Breakpoint, CtLoadLocalsArguments};
3+
use crate::task::{Action, Breakpoint, CtLoadLocalsArguments, Location};
44

55
#[derive(Debug, Clone, Serialize, Deserialize)]
66
#[serde(tag = "kind")]
@@ -15,4 +15,5 @@ pub enum CtRRQuery {
1515
DeleteBreakpoint { breakpoint: Breakpoint, },
1616
DeleteBreakpoints,
1717
ToggleBreakpoint { breakpoint: Breakpoint, },
18+
JumpToCall { location: Location },
1819
}

src/db-backend/src/replay.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ pub trait Replay: std::fmt::Debug {
2727
fn delete_breakpoint(&mut self, breakpoint: &Breakpoint) -> Result<bool, Box<dyn Error>>;
2828
fn delete_breakpoints(&mut self) -> Result<bool, Box<dyn Error>>;
2929
fn toggle_breakpoint(&mut self, breakpoint: &Breakpoint) -> Result<Breakpoint, Box<dyn Error>>;
30+
fn jump_to_call(&mut self, location: &Location) -> Result<Location, Box<dyn Error>>;
3031
fn current_step_id(&mut self) -> StepId;
3132
}

src/db-backend/src/rr_dispatcher.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,15 @@ impl Replay for RRDispatcher {
265265
)?)
266266
}
267267

268+
fn jump_to_call(&mut self, location: &Location) -> Result<Location, Box<dyn Error>> {
269+
self.ensure_active_stable()?;
270+
Ok(serde_json::from_str::<Location>(
271+
&self.stable.run_query(
272+
CtRRQuery::JumpToCall { location: location.clone() }
273+
)?
274+
)?)
275+
}
276+
268277
fn current_step_id(&mut self) -> StepId {
269278
// cache location or step_id and return
270279
// OR always load from worker

src/db-backend/src/step_lines_loader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::db::{Db, DbStep, DbReplay};
99
use crate::distinct_vec::DistinctVec;
1010
use crate::expr_loader::ExprLoader;
1111
use crate::flow_preloader::FlowPreloader;
12-
use crate::task::{FlowMode, LineStep, LineStepKind, LineStepValue, Location};
12+
use crate::task::{FlowMode, LineStep, LineStepKind, LineStepValue, Location, TraceKind};
1313

1414
#[derive(Debug, Clone)]
1515
pub struct StepLinesLoader {
@@ -87,7 +87,7 @@ impl StepLinesLoader {
8787
// let function_id = db.calls[call_key].function_id;
8888
// let function_first = db.functions[function_id].line;
8989
let mut replay = DbReplay::new(Box::new(db.clone()));
90-
let flow_update = flow_preloader.load(location, FlowMode::Call, &mut replay);
90+
let flow_update = flow_preloader.load(location, FlowMode::Call, TraceKind::DB, &mut replay);
9191
if !flow_update.error && !flow_update.view_updates.is_empty() {
9292
let flow_view_update = &flow_update.view_updates[0];
9393
for flow_step in flow_view_update.steps.iter() {

0 commit comments

Comments
 (0)