diff --git a/src/dwarf.rs b/src/dwarf.rs index d436c9d6..b0b0e1c0 100644 --- a/src/dwarf.rs +++ b/src/dwarf.rs @@ -21,16 +21,11 @@ use std::thread; use regex::Regex; -#[allow(non_upper_case_globals)] +#[allow(non_upper_case_globals, unused)] mod constants; #[allow(non_upper_case_globals)] mod debug_info; -pub struct ArangesCU { - pub debug_line_off: usize, - pub aranges: Vec<(u64, u64)>, -} - #[repr(C, packed)] struct DebugLinePrologueV2 { total_length: u32, @@ -749,7 +744,8 @@ impl DwarfResolver { /// from the given file. If the instance will be used for long /// running, you would want to load all data into memory to have /// the ability of handling all possible addresses. - pub fn open_for_addresses( + #[cfg(test)] + fn open_for_addresses( filename: &str, addresses: &[u64], line_number_info: bool, @@ -768,7 +764,8 @@ impl DwarfResolver { /// /// `filename` is the name of an ELF binary/or shared object that /// has .debug_line section. - pub fn open( + #[cfg(test)] + fn open( filename: &str, debug_line_info: bool, debug_info_symbols: bool, @@ -802,7 +799,8 @@ impl DwarfResolver { /// /// This function is pretty much the same as `find_line_as_ref()` /// except returning a copies of `String` instead of `&str`. - pub fn find_line(&self, address: u64) -> Option<(String, String, usize)> { + #[cfg(test)] + fn find_line(&self, address: u64) -> Option<(String, String, usize)> { let (dir, file, line_no) = self.find_line_as_ref(address)?; Some((String::from(dir), String::from(file), line_no)) } @@ -1216,6 +1214,12 @@ mod tests { parse_debug_line_elf_parser(&parser, &[]) } + #[allow(unused)] + struct ArangesCU { + debug_line_off: usize, + aranges: Vec<(u64, u64)>, + } + fn parse_aranges_cu(data: &[u8]) -> Result<(ArangesCU, usize), Error> { if data.len() < 12 { return Err(Error::new( diff --git a/src/dwarf/debug_info.rs b/src/dwarf/debug_info.rs index 7b1dc385..e41af7b3 100644 --- a/src/dwarf/debug_info.rs +++ b/src/dwarf/debug_info.rs @@ -33,6 +33,7 @@ fn decode_3bytes_usigned(data: &[u8]) -> u32 { data[0] as u32 | ((data[1] as u32) << 8) | ((data[2] as u32) << 16) } +#[allow(unused)] pub struct UnknownHeader { init_length: usize, bits64: bool, @@ -41,6 +42,7 @@ pub struct UnknownHeader { hdr_size: usize, } +#[allow(unused)] pub struct CUHeaderV5 { init_length: usize, bits64: bool, @@ -51,6 +53,7 @@ pub struct CUHeaderV5 { hdr_size: usize, } +#[allow(unused)] pub struct CUHeaderV4 { init_length: usize, bits64: bool, @@ -194,7 +197,6 @@ fn parse_abbrev_attr(data: &[u8]) -> Option<(u8, u8, u128, usize)> { #[derive(Clone)] pub enum AttrValue<'a> { - Signed(i64), Signed128(i128), Unsigned(u64), Unsigned128(u128), diff --git a/src/elf.rs b/src/elf.rs index 3231c90b..b2dd6750 100644 --- a/src/elf.rs +++ b/src/elf.rs @@ -255,18 +255,6 @@ fn read_elf_section_seek(file: &mut File, section: &Elf64_Shdr) -> Result<(), Er Ok(()) } -fn read_elf_section_offset_seek( - file: &mut File, - section: &Elf64_Shdr, - offset: usize, -) -> Result<(), Error> { - if offset as u64 >= section.sh_size { - return Err(Error::new(ErrorKind::InvalidInput, "the offset is too big")); - } - file.seek(SeekFrom::Start(section.sh_offset + offset as u64))?; - Ok(()) -} - fn get_elf_section_name<'a>(sect: &Elf64_Shdr, strtab: &'a [u8]) -> Option<&'a str> { extract_string(strtab, sect.sh_name as usize) } @@ -311,6 +299,7 @@ impl Elf64Parser { Ok(parser) } + #[cfg(test)] pub fn open(filename: &str) -> Result { let file = File::open(filename)?; let parser = Self::open_file(file); @@ -322,10 +311,6 @@ impl Elf64Parser { } } - pub fn get_filename(&self) -> &str { - &self.filename - } - fn ensure_ehdr(&self) -> Result<(), Error> { let mut me = self.backobj.borrow_mut(); @@ -510,17 +495,6 @@ impl Elf64Parser { ) } - pub fn section_offset_seek(&self, sect_idx: usize, offset: usize) -> Result<(), Error> { - self.check_section_index(sect_idx)?; - self.ensure_shdrs()?; - let me = self.backobj.borrow(); - read_elf_section_offset_seek( - &mut self.file.borrow_mut(), - &me.shdrs.as_ref().unwrap()[sect_idx], - offset, - ) - } - /// Read the raw data of the section of a given index. pub fn read_section_raw(&self, sect_idx: usize) -> Result, Error> { self.check_section_index(sect_idx)?; @@ -736,13 +710,6 @@ impl Elf64Parser { Ok(syms) } - pub fn get_num_symbols(&self) -> Result { - self.ensure_symtab()?; - - let me = self.backobj.borrow(); - Ok(me.symtab.as_ref().unwrap().len()) - } - #[cfg(test)] fn get_symbol(&self, idx: usize) -> Result<&Elf64_Sym, Error> { self.ensure_symtab()?; @@ -751,13 +718,6 @@ impl Elf64Parser { Ok(unsafe { &(*me).symtab.as_mut().unwrap()[idx] }) } - pub fn get_symbol_origin(&self, idx: usize) -> Result<&Elf64_Sym, Error> { - self.ensure_symtab()?; - - let me = self.backobj.as_ptr(); - Ok(unsafe { &(*me).symtab_origin.as_mut().unwrap()[idx] }) - } - #[cfg(test)] fn get_symbol_name(&self, idx: usize) -> Result<&str, Error> { let sym = self.get_symbol(idx)?; @@ -779,17 +739,6 @@ impl Elf64Parser { Ok(sym_name) } - pub fn get_all_symbols(&self) -> Result<&[Elf64_Sym], Error> { - self.ensure_symtab()?; - - let symtab = unsafe { - let me = self.backobj.as_ptr(); - let symtab_ref = (*me).symtab.as_mut().unwrap(); - symtab_ref - }; - Ok(symtab) - } - pub fn get_all_program_headers(&self) -> Result<&[Elf64_Phdr], Error> { self.ensure_phdrs()?; diff --git a/src/lib.rs b/src/lib.rs index 0f28ecc4..f550b8dc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -893,40 +893,6 @@ impl BlazeSymbolizer { }) } - #[allow(dead_code)] - fn find_address( - &self, - sym_srcs: &[SymbolSrcCfg], - name: &str, - opts: &FindAddrOpts, - ) -> Option> { - let resolver_map = ResolverMap::new(sym_srcs, &self.cache_holder).ok()?; - let mut found = vec![]; - for (_, resolver) in resolver_map.resolvers { - if let Some(mut syms) = resolver.find_address(name, opts) { - for sym in &mut syms { - if opts.offset_in_file { - if let Some(off) = resolver.addr_file_off(sym.address) { - sym.file_offset = off; - } - } - if opts.obj_file_name { - sym.obj_file_name = Some(resolver.get_obj_file_name().to_path_buf()); - } - } - found.append(&mut syms); - } - } - Some(found) - } - - #[allow(dead_code)] - fn find_line_info(&self, sym_srcs: &[SymbolSrcCfg], addr: u64) -> Option { - let resolver_map = ResolverMap::new(sym_srcs, &self.cache_holder).ok()?; - let resolver = resolver_map.find_resolver(addr)?; - resolver.find_line_info(addr) - } - fn find_addr_features_context(features: Vec) -> FindAddrOpts { let mut opts = FindAddrOpts { offset_in_file: false, diff --git a/src/tools.rs b/src/tools.rs index 3b8a1c73..3e018493 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -256,14 +256,3 @@ pub fn decode_sword(data: &[u8]) -> i32 { pub fn decode_udword(data: &[u8]) -> u64 { decode_uword(data) as u64 | ((decode_uword(&data[4..]) as u64) << 32) } - -#[allow(dead_code)] -#[inline(always)] -pub fn decode_swdord(data: &[u8]) -> i64 { - let udw = decode_udword(data); - if udw >= 0x8000000000000000 { - ((udw as i128) - 0x10000000000000000) as i64 - } else { - udw as i64 - } -}