Skip to content

Commit

Permalink
Merge branch 'master' into build/bump-cpp-demangle
Browse files Browse the repository at this point in the history
* master:
  feat(symcache): Bump SYMCACHE_VERSION to 5
  fix(debuginfo): Detect all scopes when collecting inlinees (#221)
  fix(debuginfo): Calculate line record sizes for DWARF (#220)
  • Loading branch information
jan-auer committed Apr 20, 2020
2 parents 7105ff4 + 6682bf6 commit 2b3b521
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 35 deletions.
12 changes: 9 additions & 3 deletions debuginfo/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,15 @@ pub struct LineInfo<'data> {

impl fmt::Debug for LineInfo<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("LineInfo")
.field("address", &format_args!("{:#x}", self.address))
.field("file", &self.file)
let mut s = f.debug_struct("LineInfo");
s.field("address", &format_args!("{:#x}", self.address));

match self.size {
Some(size) => s.field("size", &format_args!("{:#x}", size)),
None => s.field("size", &self.size),
};

s.field("file", &self.file)
.field("line", &self.line)
.finish()
}
Expand Down
21 changes: 15 additions & 6 deletions debuginfo/src/dwarf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ struct DwarfRow {
address: u64,
file_index: u64,
line: Option<u64>,
size: Option<u64>,
}

/// A sequence in the DWARF line program.
Expand All @@ -202,6 +203,13 @@ impl<'d, 'a> DwarfLineProgram<'d> {

while let Ok(Some((_, &program_row))) = state_machine.next_row() {
let address = program_row.address();

if let Some(last_row) = sequence_rows.last_mut() {
if address >= last_row.address {
last_row.size = Some(address - last_row.address);
}
}

if program_row.end_sequence() {
// Theoretically, there could be multiple DW_LNE_end_sequence in a row. We're not
// interested in empty sequences, so we can skip them completely.
Expand Down Expand Up @@ -242,6 +250,7 @@ impl<'d, 'a> DwarfLineProgram<'d> {
address,
file_index,
line,
size: None,
});
}
prev_address = address;
Expand Down Expand Up @@ -557,7 +566,7 @@ impl<'d, 'a> DwarfUnit<'d, 'a> {
last = Some((row.file_index, line));
lines.push(LineInfo {
address: row.address - self.inner.info.load_address,
size: None,
size: row.size,
file,
line,
});
Expand Down Expand Up @@ -613,18 +622,18 @@ impl<'d, 'a> DwarfUnit<'d, 'a> {
_ => skipped_depth = None,
}

// Flush all functions out that exceed the current iteration depth. Since we
// encountered an entry at this level, there will be no more inlinees to the
// previous function at the same level or any of it's children.
stack.flush(depth, &mut functions);

// Skip anything that is not a function.
let inline = match entry.tag() {
constants::DW_TAG_subprogram => false,
constants::DW_TAG_inlined_subroutine => true,
_ => continue,
};

// Flush all functions out that exceed the current iteration depth. Since we
// encountered a function at this level, there will be no more inlinees to the
// previous function at the same level or any of it's children.
stack.flush(depth, &mut functions);

range_buf.clear();
let (call_line, call_file) = self.parse_ranges(entry, range_buf)?;

Expand Down
12 changes: 7 additions & 5 deletions debuginfo/src/pdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,13 @@ impl<'s> Unit<'s> {
_ => skipped_depth = None,
}

// Flush all functions out that exceed the current iteration depth. Since we
// encountered a symbol at this level, there will be no more inlinees to the
// previous function at the same level or any of it's children.
if symbol.ends_scope() {
stack.flush(depth, &mut functions);
}

let function = match symbol.parse() {
Ok(SymbolData::Procedure(proc)) => {
proc_offsets.push((depth, proc.offset));
Expand All @@ -1058,11 +1065,6 @@ impl<'s> Unit<'s> {
_ => continue,
};

// Flush all functions out that exceed the current iteration depth. Since we
// encountered a function at this level, there will be no more inlinees to the
// previous function at the same level or any of it's children.
stack.flush(depth, &mut functions);

match function {
Some(function) => stack.push(depth, function),
None => skipped_depth = Some(depth),
Expand Down
5 changes: 5 additions & 0 deletions debuginfo/src/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ impl<'a> FunctionStack<'a> {
pub fn flush(&mut self, depth: isize, destination: &mut Vec<Function<'a>>) {
let len = self.0.len();

// Fast path if the last item is already a parent of the current depth.
if self.0.last().map_or(false, |&(d, _)| d < depth) {
return;
}

// Search for the first function that lies at or beyond the specified depth.
let cutoff = self.0.iter().position(|&(d, _)| d >= depth).unwrap_or(len);

Expand Down
25 changes: 11 additions & 14 deletions debuginfo/tests/snapshots/test_objects__elf_functions.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ expression: "FunctionsDebug(&functions[..10], 0)"
0x1ec5: main.cpp:9 (../linux)
0x1ec7: main.cpp:15 (../linux)
0x1eda: main.cpp:19 (../linux)
0x1ee0: stdio2.h:104 (/usr/include/x86_64-linux-gnu/bits)
0x1ee0: main.cpp:10 (../linux)
0x1ef7: main.cpp:19 (../linux)

> 0x1ec7: printf (0x13)
0x1ec7: stdio2.h:104 (/usr/include/x86_64-linux-gnu/bits)
0x1ee0: main.cpp:10 (../linux)

> 0x1ee0: printf (0x17)
0x1ee0: stdio2.h:104 (/usr/include/x86_64-linux-gnu/bits)
> 0x1ee0: printf (0x17)
0x1ee0: stdio2.h:104 (/usr/include/x86_64-linux-gnu/bits)

> 0x1f00: _ZN15google_breakpad18MinidumpDescriptorD1Ev (0x32)
0x1f00: minidump_descriptor.h:48 (../deps/breakpad/src/client/linux/handler)
Expand Down Expand Up @@ -558,7 +557,7 @@ expression: "FunctionsDebug(&functions[..10], 0)"
0x23aa: exception_handler.cc:170 (../deps/breakpad/src/client/linux/handler)
0x23b2: exception_handler.cc:171 (../deps/breakpad/src/client/linux/handler)
0x23b9: exception_handler.cc:170 (../deps/breakpad/src/client/linux/handler)
0x23bb: linux_syscall_support.h:3533 (../deps/third_party/lss)
0x23bb: exception_handler.cc:176 (../deps/breakpad/src/client/linux/handler)
0x2408: exception_handler.cc:176 (../deps/breakpad/src/client/linux/handler)
0x241d: exception_handler.cc:175 (../deps/breakpad/src/client/linux/handler)
0x2425: linux_syscall_support.h:3533 (../deps/third_party/lss)
Expand All @@ -568,10 +567,9 @@ expression: "FunctionsDebug(&functions[..10], 0)"

> 0x23b2: sys_sigaltstack (0x7)
0x23b2: linux_syscall_support.h:3533 (../deps/third_party/lss)
0x23bb: exception_handler.cc:176 (../deps/breakpad/src/client/linux/handler)

> 0x23bb: sys_sigaltstack (0x71)
0x23bb: linux_syscall_support.h:3533 (../deps/third_party/lss)
> 0x23bb: sys_sigaltstack (0x71)
0x23bb: linux_syscall_support.h:3533 (../deps/third_party/lss)

> 0x220f: _ZNSt7__cxx114listIN15google_breakpad9AppMemoryESaIS2_EED4Ev (0x31)
0x220f: stl_list.h:507 (/usr/include/c++/5/bits)
Expand Down Expand Up @@ -772,7 +770,7 @@ expression: "FunctionsDebug(&functions[..10], 0)"
0x282f: exception_handler.cc:550 (../deps/breakpad/src/client/linux/handler)
0x2832: exception_handler.cc:550 (../deps/breakpad/src/client/linux/handler)
0x2861: exception_handler.cc:551 (../deps/breakpad/src/client/linux/handler)
0x286e: linux_syscall_support.h:3718 (../deps/third_party/lss)
0x286e: exception_handler.cc:553 (../deps/breakpad/src/client/linux/handler)
0x288c: exception_handler.cc:553 (../deps/breakpad/src/client/linux/handler)
0x2891: linux_syscall_support.h:3718 (../deps/third_party/lss)
0x28b2: exception_handler.cc:553 (../deps/breakpad/src/client/linux/handler)
Expand Down Expand Up @@ -865,13 +863,12 @@ expression: "FunctionsDebug(&functions[..10], 0)"

> 0x2832: sys_prctl (0x2f)
0x2832: linux_syscall_support.h:3479 (../deps/third_party/lss)
0x286e: exception_handler.cc:553 (../deps/breakpad/src/client/linux/handler)

> 0x286e: sys_waitpid (0x49)
0x286e: linux_syscall_support.h:4496 (../deps/third_party/lss)
> 0x286e: sys_waitpid (0x49)
0x286e: linux_syscall_support.h:4496 (../deps/third_party/lss)

> 0x286e: sys_wait4 (0x49)
0x286e: linux_syscall_support.h:3718 (../deps/third_party/lss)
> 0x286e: sys_wait4 (0x49)
0x286e: linux_syscall_support.h:3718 (../deps/third_party/lss)

> 0x28cd: sys_close (0x2a)
0x28cd: linux_syscall_support.h:3357 (../deps/third_party/lss)
Expand Down
3 changes: 2 additions & 1 deletion symcache/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ use crate::error::{SymCacheError, SymCacheErrorKind};
pub const SYMCACHE_MAGIC: [u8; 4] = *b"SYMC";

/// The latest version of the file format.
pub const SYMCACHE_VERSION: u32 = 4;
pub const SYMCACHE_VERSION: u32 = 5;

// Version history:
//
// 1: Initial implementation
// 2: PR #58: Migrate from UUID to Debug ID
// 3: PR #148: Consider all PT_LOAD segments in ELF
// 4: PR #155: Functions with more than 65k line records
// 5: PR #221: Invalid inlinee nesting leading to wrong stack traces

/// Loads binary data from a segment.
pub(crate) fn get_slice(data: &[u8], offset: usize, len: usize) -> Result<&[u8], io::Error> {
Expand Down
10 changes: 4 additions & 6 deletions symcache/tests/snapshots/test_writer__functions_macos.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
---
created: "2019-07-02T08:47:28.591628Z"
creator: insta@0.8.1
source: symcache/tests/test_writer.rs
expression: FunctionsDebug(&symcache)
---
Expand Down Expand Up @@ -565,7 +563,6 @@ expression: FunctionsDebug(&symcache)
3480 _ZNSt3__16__sortIRNS_6__lessIN15google_breakpad15DynamicImageRefES3_EEPS3_EEvT0_S7_T_
3505 _ZNKSt3__16__lessIN15google_breakpad15DynamicImageRefES2_EclERKS2_S5_
3505 _ZNK15google_breakpad15DynamicImageRefltERKS0_
3517 _ZNKSt3__16__lessIN15google_breakpad15DynamicImageRefES2_EclERKS2_S5_
3517 _ZNSt3__17__sort3IRNS_6__lessIN15google_breakpad15DynamicImageRefES3_EEPS3_EEjT0_S7_S7_T_
3517 _ZNKSt3__16__lessIN15google_breakpad15DynamicImageRefES2_EclERKS2_S5_
3517 _ZNK15google_breakpad15DynamicImageRefltERKS0_
Expand Down Expand Up @@ -601,6 +598,7 @@ expression: FunctionsDebug(&symcache)
362a _ZNK15google_breakpad12DynamicImage14GetLoadAddressEv
362e _ZNKSt3__16__lessIN15google_breakpad15DynamicImageRefES2_EclERKS2_S5_
362e _ZNK15google_breakpad15DynamicImageRefltERKS0_
36dc _ZNKSt3__16__lessIN15google_breakpad15DynamicImageRefES2_EclERKS2_S5_
36dc _ZNK15google_breakpad15DynamicImageRefltERKS0_
36e6 _ZN15google_breakpad12DynamicImageltERKS0_
36e6 _ZNK15google_breakpad12DynamicImage14GetLoadAddressEv
Expand Down Expand Up @@ -977,9 +975,9 @@ expression: FunctionsDebug(&symcache)
4c8e _ZN15google_breakpad17MinidumpGenerator23SetExceptionInformationEiiij
4d80 _ZN15google_breakpad16ExceptionHandler14WaitForMessageEPv
4db7 _ZN15google_breakpad16ExceptionHandler14SuspendThreadsEv
4e42 _ZN15google_breakpad16ExceptionHandler13ResumeThreadsEv
4e42 _ZN15google_breakpad16ExceptionHandler14SuspendThreadsEv
4ee5 _ZN15google_breakpad19breakpad_exc_serverEP17mach_msg_header_tS1_
4fad _ZN15google_breakpad16ExceptionHandler13ResumeThreadsEv
5060 _ZN15google_breakpad16ExceptionHandler14SuspendThreadsEv
50d0 _ZN15google_breakpad16ExceptionHandler13ResumeThreadsEv
5140 _ZN15google_breakpad16ExceptionHandler16UninstallHandlerEb
Expand Down Expand Up @@ -1276,10 +1274,10 @@ expression: FunctionsDebug(&symcache)
7351 _ZNSt3__116allocator_traitsINS_9allocatorIhEEE10deallocateERS2_Phm
7351 _ZNSt3__19allocatorIhE10deallocateEPhm
7351 _ZNSt3__112__deallocateEPv
7379 _ZNSt3__16vectorIhNS_9allocatorIhEEED1Ev
7379 _ZN15google_breakpad12UntypedMDRVA4CopyEPKvm
73a0 _ZN15google_breakpad12UntypedMDRVA4CopyEPKvm
73ba _ZNK15google_breakpad12UntypedMDRVA8locationEv
73e3 _ZNSt3__16vectorIhNS_9allocatorIhEEED1Ev
73e3 _ZNSt3__16vectorIhNS_9allocatorIhEEED2Ev
73e3 _ZNSt3__113__vector_baseIhNS_9allocatorIhEEED2Ev
73ed _ZNSt3__113__vector_baseIhNS_9allocatorIhEEE5clearEv
Expand Down Expand Up @@ -1496,7 +1494,6 @@ expression: FunctionsDebug(&symcache)
a620 _ZNSt3__116allocator_traitsINS_9allocatorItEEE8allocateERS2_m
a620 _ZNSt3__19allocatorItE8allocateEmPKv
a624 _ZNSt3__110__allocateEm
a63d _ZNSt3__16vectorItNS_9allocatorItEEE26__swap_out_circular_bufferERNS_14__split_bufferItRS2_EEPt
a63d _ZNSt3__16vectorItNS_9allocatorItEEE12__move_rangeEPtS4_S4_
a652 _ZNSt3__16vectorItNS_9allocatorItEEE18__construct_at_endEmRKt
a68b _ZNSt3__116allocator_traitsINS_9allocatorItEEE9constructItJRKtEEEvRS2_PT_DpOT0_
Expand All @@ -1513,6 +1510,7 @@ expression: FunctionsDebug(&symcache)
a98c _ZNSt3__116allocator_traitsINS_9allocatorItEEE9constructItJRKtEEEvRS2_PT_DpOT0_
a98c _ZNSt3__116allocator_traitsINS_9allocatorItEEE11__constructItJRKtEEEvNS_17integral_constantIbLb1EEERS2_PT_DpOT0_
a98c _ZNSt3__19allocatorItE9constructItJRKtEEEvPT_DpOT0_
aa41 _ZNSt3__16vectorItNS_9allocatorItEEE26__swap_out_circular_bufferERNS_14__split_bufferItRS2_EEPt
aa41 _ZNSt3__116allocator_traitsINS_9allocatorItEEE20__construct_backwardItEENS_9enable_ifIXaaoosr7is_sameIS2_NS1_IT_EEEE5valuentsr15__has_constructIS2_PS6_S6_EE5valuesr31is_trivially_move_constructibleIS6_EE5valueEvE4typeERS2_S8_S8_RS8_
aa7e _ZNSt3__116allocator_traitsINS_9allocatorItEEE19__construct_forwardItEENS_9enable_ifIXaaoosr7is_sameIS2_NS1_IT_EEEE5valuentsr15__has_constructIS2_PS6_S6_EE5valuesr31is_trivially_move_constructibleIS6_EE5valueEvE4typeERS2_S8_S8_RS8_
aa99 _ZNSt3__14swapIPtEENS_9enable_ifIXaasr21is_move_constructibleIT_EE5valuesr18is_move_assignableIS3_EE5valueEvE4typeERS3_S6_
Expand Down

0 comments on commit 2b3b521

Please sign in to comment.