Skip to main content

Cached

Struct Cached 

Source
pub struct Cached { /* private fields */ }
Expand description

Coverage collector that maintains an in-memory mapping from source locations to execution counts.

Cached keeps a small cache mapping instruction addresses to source LineInfo (if available) and a coverage map counting visits per file and line. It also tracks the set of files seen.

Implementations§

Source§

impl Cached

Source

pub fn new() -> Self

Create a new, empty Cached collector.

§Returns

A new, empty Cached instance.

Source

pub fn coverage(&self, path: String, line: usize) -> Option<&usize>

Get the coverage count for path:line if present.

§Arguments
  • path - Source file path.
  • line - Line number in the source file.
§Returns

Some(&usize) with the execution count when present, otherwise None.

Source

pub fn files(&self) -> &HashSet<String>

Return the set of files observed by the collector.

§Returns

A reference to the HashSet of file paths that have been observed.

Source

pub fn print_source( &mut self, instruction: &Instruction, dwarf: &Dwarf<'_>, record: bool, ) -> Result<Option<String>>

Print the source line corresponding to instruction when available.

This looks up the DWARF line info for the instruction address and prints the source line if the file exists on disk. When record is true the collector updates its internal coverage counts and file set.

§Arguments
  • instruction - The disassembled instruction whose source line to print.
  • dwarf - DWARF helper used to resolve addresses to source lines.
  • record - When true the collector records coverage counts for the located source line.
§Errors

Returns an error if DWARF lookup fails.

Source

pub fn trace_with_source_print( &mut self, context: &Tracer, process: &Info, ) -> Result<i32>

Run the tracer and print source lines when available.

This convenience wraps trace_with using the collector’s print_source formatter so each executed instruction prints a source line when the DWARF information is present.

§Arguments
  • context - The tracer implementation used to run the program.
  • process - Process metadata for the target binary.
§Errors

Returns an error if DWARF construction fails or if tracing fails.

Source

pub fn trace_with_custom_progress( &mut self, context: &Tracer, process: &Info, dwarf: Option<&Dwarf<'_>>, record: bool, progress: impl ProgressFn, ) -> Result<i32>

Run the tracer using a custom progress function and optionally print source lines.

If dwarf is Some, the tracer will attempt to print source lines (when the layout indicates source); otherwise it falls back to the default printer. When record is true coverage counts are collected. The provided progress function is used for user interaction between instructions.

§Arguments
  • context - The tracer implementation used to run the program.
  • process - Process metadata for the target binary.
  • dwarf - Optional DWARF helper; when Some source printing is enabled.
  • record - If true, coverage counts are recorded.
  • progress - Custom progress function called between instructions.
§Errors

Returns an error if tracing or DWARF operations fail.

Source

pub fn trace_with_default_progress( &mut self, context: &Tracer, process: &Info, ) -> Result<i32>

Run the tracer with the default progress function and recording enabled.

This is the standard entry point for coverage collection: it tries to build DWARF info and then calls trace_with_custom_progress.

§Arguments
  • context - The tracer implementation used to run the program.
  • process - Process metadata for the target binary.
§Errors

Returns an error if DWARF construction or tracing fails.

Trait Implementations§

Source§

impl Default for Cached

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.