Skip to content

Commit 933869b

Browse files
committed
refactor: generalize event jumping for db/rr
1 parent 325e211 commit 933869b

File tree

6 files changed

+44
-25
lines changed

6 files changed

+44
-25
lines changed

src/db-backend/src/db.rs

Lines changed: 9 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::{Events, Replay};
18-
use crate::task::{Action, Breakpoint, Call, CallArg, CoreTrace, Location, ProgramEvent, RRTicks, NO_INDEX, NO_PATH, NO_POSITION, CtLoadLocalsArguments, VariableWithRecord};
17+
use crate::replay::Replay;
18+
use crate::task::{Action, Breakpoint, Call, CallArg, CoreTrace, Events, Location, ProgramEvent, RRTicks, NO_INDEX, NO_PATH, NO_POSITION, CtLoadLocalsArguments, VariableWithRecord};
1919
use crate::value::{Type, Value, ValueRecordWithType};
2020

2121
const NEXT_INTERNAL_STEP_OVERS_LIMIT: usize = 1_000;
@@ -1128,6 +1128,13 @@ impl Replay for DbReplay {
11281128
self.load_location(&mut expr_loader)
11291129
}
11301130

1131+
fn event_jump(&mut self, event: &ProgramEvent) -> Result<bool, Box<dyn Error>> {
1132+
let step_id = StepId(event.direct_location_rr_ticks); // currently using this field
1133+
// for compat with rr/gdb core support
1134+
self.jump_to(step_id)?;
1135+
Ok(true)
1136+
}
1137+
11311138
fn current_step_id(&mut self) -> StepId {
11321139
self.step_id
11331140
}

src/db-backend/src/handler.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -640,9 +640,7 @@ impl Handler {
640640
}
641641

642642
pub fn event_jump(&mut self, _req: dap::Request, event: ProgramEvent) -> Result<(), Box<dyn Error>> {
643-
let step_id = StepId(event.direct_location_rr_ticks); // currently using this field
644-
// for compat with rr/gdb core support
645-
self.replay.jump_to(step_id)?;
643+
let _ = self.replay.event_jump(&event)?;
646644
self.step_id = self.replay.current_step_id();
647645
self.complete_move(false)?;
648646

src/db-backend/src/query.rs

Lines changed: 3 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, Location};
3+
use crate::task::{Action, Breakpoint, CtLoadLocalsArguments, Location, ProgramEvent};
44
use crate::lang::Lang;
55

66
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -17,4 +17,6 @@ pub enum CtRRQuery {
1717
DeleteBreakpoints,
1818
ToggleBreakpoint { breakpoint: Breakpoint },
1919
JumpToCall { location: Location },
20+
LoadAllEvents,
21+
EventJump { program_event: ProgramEvent },
2022
}

src/db-backend/src/replay.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,9 @@ use std::error::Error;
44
use crate::db::DbRecordEvent;
55
use crate::expr_loader::ExprLoader;
66
use crate::lang::Lang;
7-
use crate::task::{Action, Breakpoint, Location, ProgramEvent, CtLoadLocalsArguments, VariableWithRecord};
7+
use crate::task::{Action, Breakpoint, Events, Location, CtLoadLocalsArguments, ProgramEvent, VariableWithRecord};
88
use crate::value::ValueRecordWithType;
99

10-
11-
#[derive(Debug, Clone)]
12-
pub struct Events {
13-
pub events: Vec<ProgramEvent>,
14-
pub first_events: Vec<ProgramEvent>,
15-
pub contents: String,
16-
}
17-
1810
pub trait Replay: std::fmt::Debug {
1911
fn load_location(&mut self, expr_loader: &mut ExprLoader) -> Result<Location, Box<dyn Error>>;
2012
fn run_to_entry(&mut self) -> Result<(), Box<dyn Error>>;
@@ -34,5 +26,6 @@ pub trait Replay: std::fmt::Debug {
3426
fn delete_breakpoints(&mut self) -> Result<bool, Box<dyn Error>>;
3527
fn toggle_breakpoint(&mut self, breakpoint: &Breakpoint) -> Result<Breakpoint, Box<dyn Error>>;
3628
fn jump_to_call(&mut self, location: &Location) -> Result<Location, Box<dyn Error>>;
29+
fn event_jump(&mut self, event: &ProgramEvent) -> Result<bool, Box<dyn Error>>;
3730
fn current_step_id(&mut self) -> StepId;
3831
}

src/db-backend/src/rr_dispatcher.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ use std::thread;
88
use std::time::Duration;
99
use std::ffi::OsStr;
1010

11-
use log::{info, warn, error};
11+
use log::{info, error};
1212
use runtime_tracing::StepId;
1313

1414
use crate::db::DbRecordEvent;
1515
use crate::expr_loader::ExprLoader;
1616
use crate::lang::Lang;
1717
use crate::paths::ct_rr_worker_socket_path;
1818
use crate::query::CtRRQuery;
19-
use crate::replay::{Events, Replay};
20-
use crate::task::{Action, Breakpoint, Location, CtLoadLocalsArguments, VariableWithRecord};
19+
use crate::replay::Replay;
20+
use crate::task::{Action, Breakpoint, Events, Location, CtLoadLocalsArguments, ProgramEvent, VariableWithRecord};
2121
use crate::value::ValueRecordWithType;
2222

2323
#[derive(Debug)]
@@ -199,12 +199,13 @@ impl Replay for RRDispatcher {
199199

200200
fn load_events(&mut self) -> Result<Events, Box<dyn Error>> {
201201
self.ensure_active_stable()?;
202-
warn!("TODO load_events rr");
203-
Ok(Events {
204-
events: vec![],
205-
first_events: vec![],
206-
contents: "".to_string(),
207-
})
202+
let events = serde_json::from_str::<Events>(&self.stable.run_query(CtRRQuery::LoadAllEvents)?)?;
203+
Ok(events)
204+
// Ok(Events {
205+
// events: vec![],
206+
// first_events: vec![],
207+
// contents: "".to_string(),
208+
// })
208209
}
209210

210211
fn step(&mut self, action: Action, forward: bool) -> Result<bool, Box<dyn Error>> {
@@ -297,6 +298,15 @@ impl Replay for RRDispatcher {
297298
)?)
298299
}
299300

301+
fn event_jump(&mut self, event: &ProgramEvent) -> Result<bool, Box<dyn Error>> {
302+
self.ensure_active_stable()?;
303+
Ok(serde_json::from_str::<bool>(
304+
&self.stable.run_query(
305+
CtRRQuery::EventJump { program_event: event.clone() }
306+
)?
307+
)?)
308+
}
309+
300310
fn current_step_id(&mut self) -> StepId {
301311
// cache location or step_id and return
302312
// OR always load from worker

src/db-backend/src/task.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ impl FlowUpdate {
673673
}
674674
}
675675

676-
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
676+
#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
677677
#[serde(rename_all(serialize = "camelCase", deserialize = "camelCase"))]
678678
pub struct ProgramEvent {
679679
pub kind: EventLogKind,
@@ -1668,6 +1668,15 @@ pub enum TraceKind {
16681668
RR,
16691669
}
16701670

1671+
#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
1672+
#[serde(rename_all(serialize = "camelCase", deserialize = "camelCase"))]
1673+
pub struct Events {
1674+
pub events: Vec<ProgramEvent>,
1675+
pub first_events: Vec<ProgramEvent>,
1676+
pub contents: String,
1677+
}
1678+
1679+
16711680
pub static mut TASK_ID_MAP: &mut [usize] = &mut [0; 100];
16721681
pub static mut EVENT_ID_MAP: &mut [usize] = &mut [0; 100];
16731682

0 commit comments

Comments
 (0)