1 extern crate addr2line
;
8 use std
::path
::{self, PathBuf}
;
12 fn release_fixture_path() -> PathBuf
{
13 if let Ok(p
) = env
::var("ADDR2LINE_FIXTURE_PATH") {
17 let mut path
= PathBuf
::new();
18 if let Ok(dir
) = env
::var("CARGO_MANIFEST_DIR") {
21 path
.push("fixtures");
22 path
.push("addr2line-release");
26 fn with_file
<F
: FnOnce(&object
::File
)>(target
: &path
::Path
, f
: F
) {
27 let file
= File
::open(target
).unwrap();
28 let map
= unsafe { memmap::Mmap::map(&file).unwrap() }
;
29 let file
= object
::File
::parse(&*map
).unwrap();
33 fn dwarf_load
<'a
>(object
: &object
::File
<'a
>) -> gimli
::Dwarf
<Cow
<'a
, [u8]>> {
34 let load_section
= |id
: gimli
::SectionId
| -> Result
<Cow
<'a
, [u8]>, gimli
::Error
> {
35 use object
::ObjectSection
;
38 .section_by_name(id
.name())
39 .and_then(|section
| section
.data().ok())
41 Ok(Cow
::Borrowed(data
))
43 gimli
::Dwarf
::load(&load_section
).unwrap()
47 dwarf
: &'a gimli
::Dwarf
<Cow
<[u8]>>,
48 ) -> gimli
::Dwarf
<gimli
::EndianSlice
<'a
, gimli
::LittleEndian
>> {
49 let borrow_section
: &dyn for<'b
> Fn(
51 ) -> gimli
::EndianSlice
<'b
, gimli
::LittleEndian
> =
52 &|section
| gimli
::EndianSlice
::new(&*section
, gimli
::LittleEndian
);
53 dwarf
.borrow(&borrow_section
)
58 let target
= release_fixture_path();
60 with_file(&target
, |file
| {
61 addr2line
::ObjectContext
::new(file
).unwrap();
66 fn parse_base_slice() {
67 let target
= release_fixture_path();
69 with_file(&target
, |file
| {
70 let dwarf
= dwarf_load(file
);
71 let dwarf
= dwarf_borrow(&dwarf
);
72 addr2line
::Context
::from_dwarf(dwarf
).unwrap();
78 let target
= release_fixture_path();
80 with_file(&target
, |file
| {
81 let context
= addr2line
::ObjectContext
::new(file
).unwrap();
82 context
.parse_lines().unwrap();
87 fn parse_lines_slice() {
88 let target
= release_fixture_path();
90 with_file(&target
, |file
| {
91 let dwarf
= dwarf_load(file
);
92 let dwarf
= dwarf_borrow(&dwarf
);
93 let context
= addr2line
::Context
::from_dwarf(dwarf
).unwrap();
94 context
.parse_lines().unwrap();
99 fn parse_functions_rc() {
100 let target
= release_fixture_path();
102 with_file(&target
, |file
| {
103 let context
= addr2line
::ObjectContext
::new(file
).unwrap();
104 context
.parse_functions().unwrap();
109 fn parse_functions_slice() {
110 let target
= release_fixture_path();
112 with_file(&target
, |file
| {
113 let dwarf
= dwarf_load(file
);
114 let dwarf
= dwarf_borrow(&dwarf
);
115 let context
= addr2line
::Context
::from_dwarf(dwarf
).unwrap();
116 context
.parse_functions().unwrap();