22// Licensed under the MIT License.
33
44use std:: collections:: { BTreeMap , BTreeSet } ;
5+ use std:: convert;
56use std:: num:: NonZeroU32 ;
67
78use anyhow:: { Context , Result } ;
@@ -11,6 +12,7 @@ use debuggable_module::load_module::LoadModule;
1112use debuggable_module:: loader:: Loader ;
1213use debuggable_module:: path:: FilePath ;
1314use debuggable_module:: { Module , Offset } ;
15+ use symbolic:: symcache:: transform:: { SourceLocation , Transformer } ;
1416
1517use crate :: allowlist:: AllowList ;
1618use crate :: binary:: BinaryCoverage ;
@@ -69,6 +71,30 @@ pub fn binary_to_source_coverage(
6971 let mut symcache = vec ! [ ] ;
7072 let mut converter = SymCacheConverter :: new ( ) ;
7173
74+ if cfg ! ( windows) {
75+ use symbolic:: symcache:: transform:: Function ;
76+ struct CaseInsensitive { }
77+ impl Transformer for CaseInsensitive {
78+ fn transform_function < ' f > ( & ' f mut self , f : Function < ' f > ) -> Function < ' f > {
79+ f
80+ }
81+
82+ fn transform_source_location < ' f > (
83+ & ' f mut self ,
84+ mut sl : SourceLocation < ' f > ,
85+ ) -> SourceLocation < ' f > {
86+ sl. file . name = sl. file . name . to_ascii_lowercase ( ) . into ( ) ;
87+ sl. file . directory = sl. file . directory . map ( |d| d. to_ascii_lowercase ( ) . into ( ) ) ;
88+ sl. file . comp_dir = sl. file . comp_dir . map ( |d| d. to_ascii_lowercase ( ) . into ( ) ) ;
89+ sl
90+ }
91+ }
92+
93+ let case_insensitive_transformer = CaseInsensitive { } ;
94+
95+ converter. add_transformer ( case_insensitive_transformer) ;
96+ }
97+
7298 let exe = Object :: parse ( module. executable_data ( ) ) ?;
7399 converter. process_object ( & exe) ?;
74100
@@ -104,18 +130,13 @@ pub fn binary_to_source_coverage(
104130 } ;
105131
106132 if let Some ( file) = location. file ( ) {
107- let file_path = if cfg ! ( windows) {
108- // Windows paths are case insensitive.
109- FilePath :: new ( file. full_path ( ) . to_ascii_lowercase ( ) ) ?
110- } else {
111- FilePath :: new ( file. full_path ( ) ) ?
112- } ;
113-
114133 // Only include relevant inlinees.
115- if !source_allowlist. is_allowed ( & file_path ) {
134+ if !source_allowlist. is_allowed ( & file . full_path ( ) ) {
116135 continue ;
117136 }
118137
138+ let file_path = FilePath :: new ( file. full_path ( ) ) ?;
139+
119140 // We have a hit.
120141 let file_coverage = source. files . entry ( file_path) . or_default ( ) ;
121142 let line = Line ( line_number) ;
0 commit comments