Skip to content

Commit

Permalink
Don't skip entries with a zero address
Browse files Browse the repository at this point in the history
While these are typically invalid in executables, they are commonly found in
object files.

The extra parsing is a signifcant slowdown when parsing all inlined
functions, but that isn't something that is done in practice.

 name                                        before ns/iter  after ns/iter  diff ns/iter  diff %  speedup
 context_new_and_query_location_rc           2,934,098       2,974,950            40,852   1.39%   x 0.99
 context_new_and_query_location_slice        1,095,621       1,088,575            -7,046  -0.64%   x 1.01
 context_new_and_query_with_functions_rc     3,015,372       2,937,087           -78,285  -2.60%   x 1.03
 context_new_and_query_with_functions_slice  1,113,536       1,106,034            -7,502  -0.67%   x 1.01
 context_new_parse_functions_rc              24,044,280      24,155,066          110,786   0.46%   x 1.00
 context_new_parse_functions_slice           18,419,484      18,677,813          258,329   1.40%   x 0.99
 context_new_parse_inlined_functions_rc      53,407,830      67,349,900       13,942,070  26.10%   x 0.79
 context_new_parse_inlined_functions_slice   40,770,422      52,019,140       11,248,718  27.59%   x 0.78
 context_new_parse_lines_rc                  12,197,122      12,437,465          240,343   1.97%   x 0.98
 context_new_parse_lines_slice               7,708,400       8,106,853           398,453   5.17%   x 0.95
 context_new_rc                              2,451,931       2,487,168            35,237   1.44%   x 0.99
 context_new_slice                           686,375         679,285              -7,090  -1.03%   x 1.01
 context_query_location_rc                   1,024,982       1,041,449            16,467   1.61%   x 0.98
 context_query_location_slice                1,008,474       1,024,442            15,968   1.58%   x 0.98
 context_query_with_functions_rc             2,973,875       3,037,333            63,458   2.13%   x 0.98
 context_query_with_functions_slice          2,670,629       2,663,918            -6,711  -0.25%   x 1.00
  • Loading branch information
philipc committed Jul 3, 2020
1 parent bfccb76 commit e6d8468
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
24 changes: 9 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl<R: gimli::Reader> Context<R> {
}
}

ranges.for_each_range(&sections, &dw_unit, true, |range| {
ranges.for_each_range(&sections, &dw_unit, |range| {
unit_ranges.push(UnitRange {
range,
unit_id,
Expand Down Expand Up @@ -493,13 +493,11 @@ where
let end = row.address();
let mut rows = Vec::new();
mem::swap(&mut rows, &mut sequence_rows);
if start != 0 {
sequences.push(LineSequence {
start,
end,
rows: rows.into_boxed_slice(),
});
}
sequences.push(LineSequence {
start,
end,
rows: rows.into_boxed_slice(),
});
}
continue;
}
Expand Down Expand Up @@ -815,7 +813,7 @@ impl<R: gimli::Reader> Functions<R> {
}

let function_index = functions.len();
if ranges.for_each_range(sections, unit, false, |range| {
if ranges.for_each_range(sections, unit, |range| {
addresses.push(FunctionAddress {
range,
function: function_index,
Expand Down Expand Up @@ -1114,7 +1112,7 @@ impl<R: gimli::Reader> InlinedFunction<R> {
call_column,
});

ranges.for_each_range(sections, unit, false, |range| {
ranges.for_each_range(sections, unit, |range| {
inlined_addresses.push(InlinedFunctionAddress {
range,
call_depth: inlined_depth,
Expand Down Expand Up @@ -1158,15 +1156,11 @@ impl<R: gimli::Reader> RangeAttributes<R> {
&self,
sections: &gimli::Dwarf<R>,
unit: &gimli::Unit<R>,
allow_at_zero: bool,
mut f: F,
) -> Result<bool, Error> {
let mut added_any = false;
let mut add_range = |range: gimli::Range| {
// Ignore invalid DWARF so that a query of 0 does not give
// a long list of matches.
// TODO: don't ignore if there is a section at this address
if (allow_at_zero || range.begin != 0) && range.begin < range.end {
if range.begin < range.end {
f(range);
added_any = true
}
Expand Down
12 changes: 1 addition & 11 deletions tests/correctness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,12 @@ fn test_function() {
println!("x");
}

#[test]
fn zero_sequence() {
let map = find_debuginfo();
let file = &object::File::parse(&*map).unwrap();
let ctx = Context::new(file).unwrap();
for probe in 0..10 {
assert!(ctx.find_location(probe).unwrap().is_none());
}
}

#[test]
fn zero_function() {
let map = find_debuginfo();
let file = &object::File::parse(&*map).unwrap();
let ctx = Context::new(file).unwrap();
for probe in 0..10 {
assert!(ctx.find_frames(probe).unwrap().next().unwrap().is_none());
assert!(ctx.find_frames(probe).unwrap().count().unwrap() < 10);
}
}

0 comments on commit e6d8468

Please sign in to comment.