#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn with_writer(
writer: W,
program: String,
args: Vec<String>,
dap_server: Arc<Mutex<DapServer>>,
) -> Result<Self> {
let recording_writer = RecordingWriter::new(writer, program, args)
.context("Failed to create RecordingWriter")?;
Ok(Self {
snapshots: Vec::new(),
is_recording: false,
dap_server,
writer: Some(recording_writer),
})
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn add_environment(&mut self, key: impl Into<String>, value: impl Into<String>) {
if let Some(ref mut writer) = self.writer {
writer.add_environment(key, value);
}
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn finalize(self) -> Result<()> {
if let Some(writer) = self.writer {
writer.finalize().context("Failed to finalize recording")?;
}
Ok(())
}
fn convert_to_recording_snapshot(exec_snapshot: &ExecutionSnapshot) -> Snapshot {
let stack_frames = exec_snapshot
.call_stack
.iter()
.map(|frame| {
let file = frame.source.as_ref().and_then(|s| s.path.clone());
let line = if frame.line >= 0 {
Some(frame.line as u32)
} else {
None
};
super::recording::StackFrame {
name: frame.name.clone(),
file,
line,
locals: HashMap::new(), }
})
.collect();
let timestamp_relative_ms = (exec_snapshot.timestamp / 1_000_000) as u32;
let frame_id = exec_snapshot.sequence as u64;
let instruction_pointer = 0u64;
Snapshot {
frame_id,
timestamp_relative_ms,
variables: exec_snapshot.variables.clone(),
stack_frames,
instruction_pointer,
memory_snapshot: None, }
}