diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /library/backtrace/crates/line-tables-only/src/lib.rs | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | library/backtrace/crates/line-tables-only/src/lib.rs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/library/backtrace/crates/line-tables-only/src/lib.rs b/library/backtrace/crates/line-tables-only/src/lib.rs new file mode 100644 index 000000000..bd5afcb3a --- /dev/null +++ b/library/backtrace/crates/line-tables-only/src/lib.rs @@ -0,0 +1,57 @@ +#[cfg(test)] +mod tests { + use std::path::Path; + use backtrace::Backtrace; + use libc::c_void; + + pub type Callback = extern "C" fn(data: *mut c_void); + + extern "C" { + fn foo(cb: Callback, data: *mut c_void); + } + + extern "C" fn store_backtrace(data: *mut c_void) { + let bt = backtrace::Backtrace::new(); + unsafe { *(data as *mut Option<Backtrace>) = Some(bt) }; + } + + fn assert_contains(backtrace: &Backtrace, + expected_name: &str, + expected_file: &str, + expected_line: u32) { + + let expected_file = Path::new(expected_file); + + for frame in backtrace.frames() { + for symbol in frame.symbols() { + if let Some(name) = symbol.name() { + if name.as_bytes() == expected_name.as_bytes() { + assert!(symbol.filename().unwrap().ends_with(expected_file)); + assert_eq!(symbol.lineno(), Some(expected_line)); + return; + } + } + } + } + + panic!("symbol {:?} not found in backtrace: {:?}", expected_name, backtrace); + } + + /// Verifies that when debug info includes only lines tables the generated + /// backtrace is still generated successfully. The test exercises behaviour + /// that failed previously when compiling with clang -g1. + /// + /// The test case uses C rather than rust, since at that time when it was + /// written the debug info generated at level 1 in rustc was essentially + /// the same as at level 2. + #[test] + #[cfg_attr(windows, ignore)] + fn backtrace_works_with_line_tables_only() { + let mut backtrace: Option<Backtrace> = None; + unsafe { foo(store_backtrace, &mut backtrace as *mut _ as *mut c_void) }; + let backtrace = backtrace.expect("backtrace"); + assert_contains(&backtrace, "foo", "src/callback.c", 13); + assert_contains(&backtrace, "bar", "src/callback.c", 9); + assert_contains(&backtrace, "baz", "src/callback.c", 5); + } +} |