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

Only use pseudo-handle for coverage dbghelp context #918

Merged
merged 2 commits into from
May 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/agent/coverage/src/block/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<'c> Recorder<'c> {
pub fn on_create_process(&mut self, dbg: &mut Debugger, module: &ModuleLoadInfo) -> Result<()> {
log::debug!("process created: {}", module.path().display());

// TODO: we should avoid loading symbols if the module is in the cache.
// Not necessary for PDB search, but enables use of other `dbghelp` APIs.
if let Err(err) = dbg.target().maybe_sym_initialize() {
log::error!(
"unable to initialize symbol handler for new process {}: {:?}",
Expand All @@ -121,8 +121,6 @@ impl<'c> Recorder<'c> {
pub fn on_load_dll(&mut self, dbg: &mut Debugger, module: &ModuleLoadInfo) -> Result<()> {
log::debug!("DLL loaded: {}", module.path().display());

// TODO: we should load symbols if the module is not in the cache (see on_create_process).

self.insert_module(dbg, module)
}

Expand Down Expand Up @@ -170,7 +168,12 @@ impl<'c> Recorder<'c> {
return Ok(());
}

match self.cache.fetch(&path, dbg.target().process_handle()) {
// Do not pass the debuggee's actual process handle here. Any passed handle is
// used as the symbol handler context within the cache's PDB search. Instead, use
// the default internal pseudo-handle for "static" `dbghelp` usage. This lets us
// query `dbghelp` immediately upon observing the `CREATE_PROCESS_DEBUG_EVENT`,
// before we would be able to for a running debuggee.
match self.cache.fetch(&path, None) {
Ok(Some(info)) => {
let new = self.coverage.insert(&path, info.blocks.iter().copied());

Expand Down