1 extern crate addr2line
;
2 extern crate fallible_iterator
;
3 extern crate findshlibs
;
8 use addr2line
::Context
;
9 use fallible_iterator
::FallibleIterator
;
10 use findshlibs
::{IterationControl, SharedLibrary, TargetSharedLibrary}
;
14 fn find_debuginfo() -> memmap2
::Mmap
{
15 let path
= std
::env
::current_exe().unwrap();
16 let file
= File
::open(&path
).unwrap();
17 let map
= unsafe { memmap2::Mmap::map(&file).unwrap() }
;
18 let file
= &object
::File
::parse(&*map
).unwrap();
19 if let Ok(uuid
) = file
.mach_uuid() {
20 for candidate
in path
.parent().unwrap().read_dir().unwrap() {
21 let path
= candidate
.unwrap().path();
22 if !path
.to_str().unwrap().ends_with(".dSYM") {
25 for candidate
in path
.join("Contents/Resources/DWARF").read_dir().unwrap() {
26 let path
= candidate
.unwrap().path();
27 let file
= File
::open(&path
).unwrap();
28 let map
= unsafe { memmap2::Mmap::map(&file).unwrap() }
;
29 let file
= &object
::File
::parse(&*map
).unwrap();
30 if file
.mach_uuid().unwrap() == uuid
{
42 let map
= find_debuginfo();
43 let file
= &object
::File
::parse(&*map
).unwrap();
44 let module_base
= file
.relative_address_base();
45 let ctx
= Context
::new(file
).unwrap();
48 TargetSharedLibrary
::each(|lib
| {
49 bias
= Some((lib
.virtual_memory_bias().0 as u64).wrapping_sub(module_base
));
50 IterationControl
::Break
53 let test
= |sym
: u64, expected_prefix
: &str| {
54 let ip
= sym
.wrapping_sub(bias
.unwrap());
56 let frames
= ctx
.find_frames(ip
).unwrap();
57 let frame
= frames
.last().unwrap().unwrap();
58 let name
= frame
.function
.as_ref().unwrap().demangle().unwrap();
59 // Old rust versions generate DWARF with wrong linkage name,
60 // so only check the start.
61 if !name
.starts_with(expected_prefix
) {
62 panic
!("incorrect name '{}', expected {:?}", name
, expected_prefix
);
66 test(test_function
as u64, "correctness::test_function");
68 small
::test_function
as u64,
69 "correctness::small::test_function",
71 test(auxiliary
::foo
as u64, "auxiliary::foo");
75 pub fn test_function() {
86 let map
= find_debuginfo();
87 let file
= &object
::File
::parse(&*map
).unwrap();
88 let ctx
= Context
::new(file
).unwrap();
90 assert
!(ctx
.find_frames(probe
).unwrap().count().unwrap() < 10);