Skip to content

Commit 6cf7f5d

Browse files
author
zhuyunxing
committed
coverage. Let coverage-dump support parsing mcdc info
1 parent d8f3dde commit 6cf7f5d

File tree

1 file changed

+47
-4
lines changed

1 file changed

+47
-4
lines changed

src/tools/coverage-dump/src/covfun.rs

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,13 @@ pub(crate) fn dump_covfun_mappings(
7070
}
7171
// If the mapping is a branch region, print both of its arms
7272
// in resolved form (even if they aren't expressions).
73-
MappingKind::Branch { r#true, r#false } => {
73+
MappingKind::Branch { r#true, r#false }
74+
| MappingKind::MCDCBranch { r#true, r#false, .. } => {
7475
println!(" true = {}", expression_resolver.format_term(r#true));
7576
println!(" false = {}", expression_resolver.format_term(r#false));
7677
}
78+
79+
MappingKind::MCDCDecision { .. } => {}
7780
_ => (),
7881
}
7982
}
@@ -159,11 +162,30 @@ impl<'a> Parser<'a> {
159162
match high {
160163
0 => unreachable!("zero kind should have already been handled as a code mapping"),
161164
2 => Ok(MappingKind::Skip),
162-
4 => {
165+
4 | 6 => {
163166
let r#true = self.read_simple_term()?;
164167
let r#false = self.read_simple_term()?;
165-
Ok(MappingKind::Branch { r#true, r#false })
168+
if high == 6 {
169+
let condition_id = self.read_uleb128_u32()?;
170+
let true_next_id = self.read_uleb128_u32()?;
171+
let false_next_id = self.read_uleb128_u32()?;
172+
Ok(MappingKind::MCDCBranch {
173+
r#true,
174+
r#false,
175+
condition_id,
176+
true_next_id,
177+
false_next_id,
178+
})
179+
} else {
180+
Ok(MappingKind::Branch { r#true, r#false })
181+
}
166182
}
183+
5 => {
184+
let bitmap_idx = self.read_uleb128_u32()?;
185+
let conditions_num = self.read_uleb128_u32()?;
186+
Ok(MappingKind::MCDCDecision { bitmap_idx, conditions_num })
187+
}
188+
167189
_ => Err(anyhow!("unknown mapping kind: {raw_mapping_kind:#x}")),
168190
}
169191
}
@@ -224,7 +246,28 @@ enum MappingKind {
224246
// Using raw identifiers here makes the dump output a little bit nicer
225247
// (via the derived Debug), at the expense of making this tool's source
226248
// code a little bit uglier.
227-
Branch { r#true: CovTerm, r#false: CovTerm },
249+
Branch {
250+
r#true: CovTerm,
251+
r#false: CovTerm,
252+
},
253+
MCDCBranch {
254+
r#true: CovTerm,
255+
r#false: CovTerm,
256+
// These attributes are printed in Debug but not used directly.
257+
#[allow(dead_code)]
258+
condition_id: u32,
259+
#[allow(dead_code)]
260+
true_next_id: u32,
261+
#[allow(dead_code)]
262+
false_next_id: u32,
263+
},
264+
MCDCDecision {
265+
// These attributes are printed in Debug but not used directly.
266+
#[allow(dead_code)]
267+
bitmap_idx: u32,
268+
#[allow(dead_code)]
269+
conditions_num: u32,
270+
},
228271
}
229272

230273
struct MappingRegion {

0 commit comments

Comments
 (0)