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

Try to use Sancov tables when recording Windows coverage #844

Merged
merged 15 commits into from
May 4, 2021
43 changes: 43 additions & 0 deletions src/agent/coverage/examples/pdb_sancov_tables.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

use anyhow::Result;
use structopt::StructOpt;

#[derive(Debug, PartialEq, StructOpt)]
struct Opt {
#[structopt(long)]
pe: std::path::PathBuf,

#[structopt(long)]
pdb: Option<std::path::PathBuf>,
}

#[cfg(target_os = "windows")]
fn main() -> Result<()> {
use coverage::block::pe_provider::PeSancovBasicBlockProvider;
use goblin::pe::PE;
use pdb::PDB;

let opt = Opt::from_args();

let data = std::fs::read(&opt.pe)?;
let pe = PE::parse(&data)?;

let pdb = opt
.pdb
.clone()
.unwrap_or_else(|| opt.pe.with_extension("pdb"));
let pdb = std::fs::File::open(pdb)?;
let mut pdb = PDB::open(pdb)?;

let mut provider = PeSancovBasicBlockProvider::new(&data, &pe, &mut pdb);
let blocks = provider.provide()?;

println!("blocks = {:x?}", blocks);

Ok(())
}

#[cfg(target_os = "linux")]
fn main() {}
3 changes: 3 additions & 0 deletions src/agent/coverage/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#[cfg(target_os = "linux")]
pub mod linux;

#[cfg(target_os = "windows")]
pub mod pe_provider;

#[cfg(target_os = "windows")]
pub mod windows;

Expand Down
Loading