Skip to content

Commit fd96f5b

Browse files
committed
feat: start prototyping experimental rr with db backend: TODO rr process
1 parent 05668da commit fd96f5b

File tree

7 files changed

+87
-10
lines changed

7 files changed

+87
-10
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ 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;
23+
use db_backend::handler::{Handler, TraceKind};
2424
// use db_backend::receiver::Receiver;
2525
// use db_backend::response::Response;
2626

@@ -78,7 +78,7 @@ fn main() -> Result<(), Box<dyn Error>> {
7878
let db = Db::new(&PathBuf::from(""));
7979
// receiver.setup_for_virtualization_layers(&cli.socket_path, cli.caller_process_pid)?;
8080

81-
let mut _handler = Handler::construct(Box::new(db), true);
81+
let mut _handler = Handler::construct(TraceKind::DB, Box::new(db), true);
8282

8383
// receiver.receive_loop(&mut handler)?;
8484

src/db-backend/src/dap_server.rs

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

44
use crate::db::Db;
5-
use crate::handler::Handler;
5+
use crate::handler::{Handler, TraceKind};
66
use crate::paths::CODETRACER_PATHS;
77
use crate::task::{
88
gen_task_id, Action, CallSearchArg, CalltraceLoadArgs, CollapseCallsArgs, CtLoadFlowArguments,
@@ -106,13 +106,23 @@ fn launch(trace_folder: &Path, trace_file: &Path, raw_diff_index: Option<String>
106106
let mut proc = TraceProcessor::new(&mut db);
107107
proc.postprocess(&trace)?;
108108

109-
let mut handler = Handler::new(Box::new(db));
109+
let mut handler = Handler::new(TraceKind::DB, Box::new(db));
110110
handler.dap_client.seq = seq;
111111
handler.raw_diff_index = raw_diff_index;
112112
handler.run_to_entry(dap::Request::default())?;
113113
Ok(handler)
114114
} else {
115-
Err("problem with reading metadata or path trace files".into())
115+
warn!("problem with reading metadata or path trace files: try rr?");
116+
let path = trace_folder.join("rr");
117+
if path.exists() {
118+
let db = Db::new(&PathBuf::from(""));
119+
let mut handler = Handler::new(TraceKind::RR, Box::new(db));
120+
handler.dap_client.seq = seq;
121+
handler.run_to_entry(dap::Request::default())?;
122+
Ok(handler)
123+
} else {
124+
Err("problem with reading metadata or path trace files".into())
125+
}
116126
}
117127
}
118128

src/db-backend/src/handler.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::event_db::{EventDb, SingleTableId};
1515
use crate::expr_loader::ExprLoader;
1616
use crate::flow_preloader::FlowPreloader;
1717
use crate::program_search_tool::ProgramSearchTool;
18+
use crate::rr_dispatcher::{RRDispatcher};
1819
// use crate::response::{};
1920
use crate::dap_types;
2021
// use crate::dap_types::Source;
@@ -51,9 +52,18 @@ pub struct Handler {
5152
pub raw_diff_index: Option<String>,
5253
pub previous_step_id: StepId,
5354

55+
pub trace_kind: TraceKind,
56+
pub rr: RRDispatcher,
5457
pub breakpoint_list: Vec<HashMap<usize, BreakpointRecord>>,
5558
}
5659

60+
#[derive(Debug, Clone)]
61+
pub enum TraceKind {
62+
DB,
63+
RR
64+
}
65+
66+
5767
#[derive(Debug, Clone, Serialize, Deserialize)]
5868
pub struct BreakpointRecord {
5969
pub is_active: bool,
@@ -80,11 +90,11 @@ type LineTraceMap = HashMap<usize, Vec<(usize, String)>>;
8090
// sender.
8191

8292
impl Handler {
83-
pub fn new(db: Box<Db>) -> Handler {
84-
Self::construct(db, false)
93+
pub fn new(trace_kind: TraceKind, db: Box<Db>) -> Handler {
94+
Self::construct(trace_kind, db, false)
8595
}
8696

87-
pub fn construct(db: Box<Db>, indirect_send: bool) -> Handler {
97+
pub fn construct(trace_kind: TraceKind, db: Box<Db>, indirect_send: bool) -> Handler {
8898
let calltrace = Calltrace::new(&db);
8999
let trace = CoreTrace::default();
90100
let mut expr_loader = ExprLoader::new(trace.clone());
@@ -93,6 +103,7 @@ impl Handler {
93103
let step_lines_loader = StepLinesLoader::new(&db, &mut expr_loader);
94104
// let sender = sender::Sender::new();
95105
Handler {
106+
trace_kind,
96107
db,
97108
step_id: StepId(0),
98109
last_call_key: CallKey(0),
@@ -107,6 +118,7 @@ impl Handler {
107118
step_lines_loader,
108119
dap_client: DapClient::default(),
109120
previous_step_id: StepId(0),
121+
rr: RRDispatcher::new(),
110122
resulting_dap_messages: vec![],
111123
raw_diff_index: None,
112124
}
@@ -273,7 +285,14 @@ impl Handler {
273285
}
274286

275287
pub fn run_to_entry(&mut self, _req: dap::Request) -> Result<(), Box<dyn Error>> {
276-
self.step_id_jump(StepId(0));
288+
match self.trace_kind {
289+
TraceKind::DB => {
290+
self.step_id_jump(StepId(0));
291+
},
292+
TraceKind::RR => {
293+
self.rr.run_to_entry()?;
294+
},
295+
}
277296
self.complete_move(true)?;
278297
Ok(())
279298
}
@@ -1814,6 +1833,7 @@ mod tests {
18141833
}
18151834
let trace_metadata_file = path.join("trace_metadata.json");
18161835
let trace = load_trace_data(&trace_file, trace_file_format).expect("expected that it can load the trace file");
1836+
info!("trace {:?}", trace);
18171837
let trace_metadata =
18181838
load_trace_metadata(&trace_metadata_file).expect("expected that it can load the trace metadata file");
18191839
let mut db = Db::new(&trace_metadata.workdir);

src/db-backend/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub mod handler;
3939
pub mod lang;
4040
pub mod paths;
4141
pub mod program_search_tool;
42+
pub mod rr_dispatcher;
4243
pub mod step_lines_loader;
4344
pub mod task;
4445
pub mod trace_processor;

src/db-backend/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ mod handler;
3838
mod lang;
3939
mod paths;
4040
mod program_search_tool;
41+
mod rr_dispatcher;
4142
mod step_lines_loader;
4243
mod task;
4344
mod trace_processor;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use std::error::Error;
2+
3+
#[derive(Debug, Clone)]
4+
pub struct RRDispatcher {
5+
pub stable: RRProcess,
6+
}
7+
8+
#[derive(Debug, Clone)]
9+
pub struct RRProcess {
10+
pub name: String,
11+
pub active: bool,
12+
// TODO: os process,sockets? ipc?, other metadata
13+
}
14+
15+
impl RRDispatcher {
16+
pub fn new() -> RRDispatcher {
17+
RRDispatcher {
18+
stable: RRProcess::new("stable"),
19+
}
20+
}
21+
22+
pub fn run_to_entry(&mut self) -> Result<(), Box<dyn Error>> {
23+
self.ensure_active_stable()?;
24+
self.stable.run_to_entry()
25+
}
26+
27+
pub fn ensure_active_stable(&mut self) -> Result<(), Box<dyn Error>> {
28+
todo!() // start stable process if not active, store fields, setup ipc? store in stable
29+
}
30+
}
31+
32+
impl RRProcess {
33+
pub fn new(name: &str) -> RRProcess {
34+
RRProcess {
35+
name: name.to_string(),
36+
active: false,
37+
}
38+
}
39+
40+
pub fn run_to_entry(&mut self) -> Result<(), Box<dyn Error>> {
41+
// send to process or directly run `start` / similar low level commands
42+
// load / update location ? (or leave this for later?)
43+
todo!()
44+
}
45+
}

src/db-backend/src/trace_processor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ pub fn load_trace_data(
450450
pub fn load_trace_metadata(trace_metadata_file: &Path) -> Result<TraceMetadata, Box<dyn Error>> {
451451
// copied and adapted from https://stackoverflow.com/a/70926549/438099
452452
let path = expanduser(trace_metadata_file.display().to_string())?;
453-
let raw_bytes = fs::read(&path).unwrap_or_else(|_| panic!("metadata file {path:?} read error"));
453+
let raw_bytes = fs::read(&path)?; //.unwrap_or_else(|_| panic!("metadata file {path:?} read error"));
454454
let raw = str::from_utf8(&raw_bytes)?;
455455

456456
let trace_metadata: TraceMetadata = serde_json::from_str(raw)?;

0 commit comments

Comments
 (0)