From c7ba712de0093b78f6665dd75c3eb5fc0f40e3a7 Mon Sep 17 00:00:00 2001 From: Joe Ranweiler Date: Mon, 30 Jan 2023 09:46:58 -0800 Subject: [PATCH] Apply allowlist to all blocks within a function (#2785) --- src/agent/coverage/src/binary.rs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/agent/coverage/src/binary.rs b/src/agent/coverage/src/binary.rs index 8276c6c41..11cadff62 100644 --- a/src/agent/coverage/src/binary.rs +++ b/src/agent/coverage/src/binary.rs @@ -124,16 +124,27 @@ pub fn find_coverage_sites( continue; } - if let Some(location) = symcache.lookup(function.offset.0).next() { - if let Some(file) = location.file() { - let path = file.full_path(); + let blocks = block::sweep_region(module, &debuginfo, function.offset, function.size)?; - if allowlist.source_files.is_allowed(path) { - let blocks = - block::sweep_region(module, &debuginfo, function.offset, function.size)?; - offsets.extend(blocks.iter().map(|b| b.offset)); + for block in &blocks { + if let Some(location) = symcache.lookup(block.offset.0).next() { + if let Some(file) = location.file() { + let path = file.full_path(); + + // Apply allowlists per block, to account for inlining. The `location` values + // here describe the top of the inline-inclusive call stack. + if !allowlist.functions.is_allowed(&path) { + continue; + } + + if !allowlist.source_files.is_allowed(&path) { + continue; + } + + offsets.insert(block.offset); } } + println!(); } }