Skip to content

Commit

Permalink
Remove more unused code or declare it test only
Browse files Browse the repository at this point in the history
Remove more unused code or declare it test only so that we can
eventually remove global allowance of the `dead_code` lint. If we need
some of the removed functionality we can always get it back from version
control, as discussed in person.

Signed-off-by: Daniel Müller <deso@posteo.net>
  • Loading branch information
d-e-s-o authored and danielocfb committed Dec 15, 2022
1 parent 8308d84 commit c78091f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 107 deletions.
22 changes: 13 additions & 9 deletions src/dwarf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion src/dwarf/debug_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -41,6 +42,7 @@ pub struct UnknownHeader {
hdr_size: usize,
}

#[allow(unused)]
pub struct CUHeaderV5 {
init_length: usize,
bits64: bool,
Expand All @@ -51,6 +53,7 @@ pub struct CUHeaderV5 {
hdr_size: usize,
}

#[allow(unused)]
pub struct CUHeaderV4 {
init_length: usize,
bits64: bool,
Expand Down Expand Up @@ -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),
Expand Down
53 changes: 1 addition & 52 deletions src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -311,6 +299,7 @@ impl Elf64Parser {
Ok(parser)
}

#[cfg(test)]
pub fn open(filename: &str) -> Result<Elf64Parser, Error> {
let file = File::open(filename)?;
let parser = Self::open_file(file);
Expand All @@ -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();

Expand Down Expand Up @@ -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<Vec<u8>, Error> {
self.check_section_index(sect_idx)?;
Expand Down Expand Up @@ -736,13 +710,6 @@ impl Elf64Parser {
Ok(syms)
}

pub fn get_num_symbols(&self) -> Result<usize, Error> {
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()?;
Expand All @@ -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)?;
Expand All @@ -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()?;

Expand Down
34 changes: 0 additions & 34 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,40 +893,6 @@ impl BlazeSymbolizer {
})
}

#[allow(dead_code)]
fn find_address(
&self,
sym_srcs: &[SymbolSrcCfg],
name: &str,
opts: &FindAddrOpts,
) -> Option<Vec<SymbolInfo>> {
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<AddressLineInfo> {
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<FindAddrFeature>) -> FindAddrOpts {
let mut opts = FindAddrOpts {
offset_in_file: false,
Expand Down
11 changes: 0 additions & 11 deletions src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit c78091f

Please sign in to comment.