Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Borrow Recorder in debug event handler (#762)
Browse files Browse the repository at this point in the history
Enables accessing recorded coverage without using the top-level `record()` function.
  • Loading branch information
ranweiler authored Mar 31, 2021
1 parent 6aca32e commit 7ef8223
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/agent/coverage/src/block/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ use crate::code::{CmdFilter, ModulePath};

pub fn record(cmd: Command, filter: CmdFilter) -> Result<CommandBlockCov> {
let mut cache = ModuleCache::default();
let recorder = Recorder::new(&mut cache, filter);
let mut recorder = Recorder::new(&mut cache, filter);
let timeout = Duration::from_secs(5);
let mut handler = RecorderEventHandler::new(recorder, timeout);
let mut handler = RecorderEventHandler::new(&mut recorder, timeout);
handler.run(cmd)?;
Ok(handler.recorder.into_coverage())
Ok(recorder.into_coverage())
}

#[derive(Debug)]
pub struct RecorderEventHandler<'a> {
recorder: Recorder<'a>,
pub struct RecorderEventHandler<'r, 'c> {
recorder: &'r mut Recorder<'c>,
started: Instant,
timed_out: bool,
timeout: Duration,
}

impl<'a> RecorderEventHandler<'a> {
pub fn new(recorder: Recorder<'a>, timeout: Duration) -> Self {
impl<'r, 'c> RecorderEventHandler<'r, 'c> {
pub fn new(recorder: &'r mut Recorder<'c>, timeout: Duration) -> Self {
let started = Instant::now();
let timed_out = false;

Expand Down Expand Up @@ -72,11 +72,11 @@ impl<'a> RecorderEventHandler<'a> {
}

#[derive(Debug)]
pub struct Recorder<'a> {
pub struct Recorder<'c> {
breakpoints: Breakpoints,

// Reference to allow in-memory reuse across runs.
cache: &'a mut ModuleCache,
cache: &'c mut ModuleCache,

// Note: this could also be a reference to enable reuse across runs, to
// support implicit calculation of total coverage for a corpus. For now,
Expand All @@ -86,8 +86,8 @@ pub struct Recorder<'a> {
filter: CmdFilter,
}

impl<'a> Recorder<'a> {
pub fn new(cache: &'a mut ModuleCache, filter: CmdFilter) -> Self {
impl<'c> Recorder<'c> {
pub fn new(cache: &'c mut ModuleCache, filter: CmdFilter) -> Self {
let breakpoints = Breakpoints::default();
let coverage = CommandBlockCov::default();

Expand Down Expand Up @@ -196,7 +196,7 @@ impl<'a> Recorder<'a> {
}
}

impl<'a> DebugEventHandler for RecorderEventHandler<'a> {
impl<'r, 'c> DebugEventHandler for RecorderEventHandler<'r, 'c> {
fn on_create_process(&mut self, dbg: &mut Debugger, module: &Module) {
if self.recorder.on_create_process(dbg, module).is_err() {
self.stop(dbg);
Expand Down

0 comments on commit 7ef8223

Please sign in to comment.