(object: &'file File<'data>)
| 261 | |
| 262 | impl<'file, 'data> DwarfLoader<'file, 'data> { |
| 263 | pub fn new(object: &'file File<'data>) -> Result<Self, Error> { |
| 264 | if !object.endianness().is_little_endian() { |
| 265 | Err(Error::UnexpectedElf( |
| 266 | "only little endian object files are supported", |
| 267 | ))? |
| 268 | } |
| 269 | |
| 270 | let section_layout = SectionLayout::for_object(object)?; |
| 271 | |
| 272 | let dwarf_sections = Arc::new(gimli::DwarfSections::load(|id| { |
| 273 | load_section(object, §ion_layout, id.name()) |
| 274 | })?); |
| 275 | // Also load `.eh_frame` which may be present in place of `.debug_frame`. |
| 276 | let eh_frame_section = load_section(object, §ion_layout, ".eh_frame")?; |
| 277 | |
| 278 | let dwarf = |
| 279 | dwarf_sections.borrow(|section| gimli::EndianSlice::new(section, gimli::LittleEndian)); |
| 280 | // SAFETY: erase lifetime. This is fine as `dwarf` will be dropped before `dwarf_sections`. |
| 281 | let dwarf_transmute = |
| 282 | unsafe { std::mem::transmute::<Dwarf<ReaderTy<'_>>, Dwarf<ReaderTy<'_>>>(dwarf) }; |
| 283 | |
| 284 | Ok(Self { |
| 285 | section_layout, |
| 286 | dwarf: dwarf_transmute, |
| 287 | dwarf_sections, |
| 288 | eh_frame_section, |
| 289 | }) |
| 290 | } |
| 291 | |
| 292 | // This returns the correct lifetime instead of the hacked one. |
| 293 | fn dwarf(&self) -> &Dwarf<ReaderTy<'_>> { |
nothing calls this directly
no test coverage detected