Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove enable_debug_info_syms flag from DwarfResolver #377

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 8 additions & 32 deletions src/dwarf/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ pub(crate) struct DwarfResolver {
units: Units<'static>,
parser: Rc<ElfParser>,
line_number_info: bool,
enable_debug_info_syms: bool,
}

impl DwarfResolver {
Expand All @@ -64,11 +63,7 @@ impl DwarfResolver {
&self.parser
}

pub fn from_parser(
parser: Rc<ElfParser>,
line_number_info: bool,
debug_info_symbols: bool,
) -> Result<Self, Error> {
pub fn from_parser(parser: Rc<ElfParser>, line_number_info: bool) -> Result<Self, Error> {
// SAFETY: We own the `ElfParser` and make sure that it stays
// around while the `Units` object uses it. As such, it
// is fine to conjure a 'static lifetime here.
Expand All @@ -81,7 +76,6 @@ impl DwarfResolver {
units,
parser,
line_number_info,
enable_debug_info_syms: debug_info_symbols,
};
Ok(slf)
}
Expand All @@ -91,9 +85,9 @@ impl DwarfResolver {
/// `filename` is the name of an ELF binary/or shared object that
/// has .debug_line section.
#[cfg(test)]
pub fn open(filename: &Path, debug_line_info: bool, debug_info_symbols: bool) -> Result<Self> {
pub fn open(filename: &Path, debug_line_info: bool) -> Result<Self> {
let parser = ElfParser::open(filename)?;
Self::from_parser(Rc::new(parser), debug_line_info, debug_info_symbols)
Self::from_parser(Rc::new(parser), debug_line_info)
}

/// Find source code information of an address.
Expand Down Expand Up @@ -180,15 +174,6 @@ impl DwarfResolver {

/// Lookup the symbol at an address.
pub(crate) fn find_sym(&self, addr: Addr) -> Result<Option<IntSym<'_>>, Error> {
// TODO: This conditional logic is weird and potentially
// unnecessary. Consider removing it or moving it higher
// in the call chain.
if !self.enable_debug_info_syms {
return Err(Error::with_unsupported(
"debug info symbol information has been disabled",
))
}

let result = self.units.find_function(addr)?;
if let Some((function, language)) = result {
let name = function
Expand Down Expand Up @@ -219,15 +204,6 @@ impl DwarfResolver {
/// * `name` - is the symbol name to find.
/// * `opts` - is the context giving additional parameters.
pub(crate) fn find_addr(&self, name: &str, opts: &FindAddrOpts) -> Result<Vec<SymInfo>> {
// TODO: This conditional logic is weird and potentially
// unnecessary. Consider removing it or moving it higher
// in the call chain.
if !self.enable_debug_info_syms {
return Err(Error::with_unsupported(
"debug info symbol information has been disabled",
))
}

if let SymType::Variable = opts.sym_type {
return Err(Error::with_unsupported("not implemented"))
}
Expand Down Expand Up @@ -294,7 +270,7 @@ mod tests {
#[test]
fn debug_repr() {
let bin_name = current_exe().unwrap();
let resolver = DwarfResolver::open(&bin_name, true, true).unwrap();
let resolver = DwarfResolver::open(&bin_name, true).unwrap();
assert_ne!(format!("{resolver:?}"), "");
}

Expand All @@ -304,9 +280,9 @@ mod tests {
let bin_name = Path::new(&env!("CARGO_MANIFEST_DIR"))
.join("data")
.join("test-stable-addresses.bin");
let resolver = DwarfResolver::open(bin_name.as_ref(), true, false).unwrap();
let resolver = DwarfResolver::open(bin_name.as_ref(), true).unwrap();

let info = resolver.find_code_info(0x2000100, false).unwrap().unwrap();
let info = resolver.find_code_info(0x2000100, true).unwrap().unwrap();
assert_ne!(info.direct.1.dir, PathBuf::new());
assert_eq!(info.direct.1.file, "test-stable-addresses.c");
assert_eq!(info.direct.1.line, Some(8));
Expand All @@ -324,7 +300,7 @@ mod tests {
obj_file_name: false,
sym_type: SymType::Function,
};
let resolver = DwarfResolver::open(test_dwarf.as_ref(), true, true).unwrap();
let resolver = DwarfResolver::open(test_dwarf.as_ref(), true).unwrap();

let symbols = resolver.find_addr("factorial", &opts).unwrap();
assert_eq!(symbols.len(), 1);
Expand All @@ -345,7 +321,7 @@ mod tests {
obj_file_name: false,
sym_type: SymType::Variable,
};
let resolver = DwarfResolver::open(test_dwarf.as_ref(), true, true).unwrap();
let resolver = DwarfResolver::open(test_dwarf.as_ref(), true).unwrap();

let err = resolver.find_addr("factorial", &opts).unwrap_err();
assert_eq!(err.kind(), ErrorKind::Unsupported);
Expand Down
3 changes: 1 addition & 2 deletions src/inspect/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ impl Inspector {
#[cfg(feature = "dwarf")]
let backend = if debug_info {
let debug_line_info = true;
let debug_info_symbols = true;
let dwarf = DwarfResolver::from_parser(parser, debug_line_info, debug_info_symbols)?;
let dwarf = DwarfResolver::from_parser(parser, debug_line_info)?;
let backend = ElfBackend::Dwarf(Rc::new(dwarf));
backend
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/symbolize/symbolizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,11 @@ impl Symbolizer {
parser: Rc<ElfParser>,
) -> Result<Rc<ElfResolver>> {
#[cfg(feature = "dwarf")]
let backend = ElfBackend::Dwarf(Rc::new(DwarfResolver::from_parser(
parser,
self.code_info,
self.debug_syms,
)?));
let backend = if self.debug_syms {
ElfBackend::Dwarf(Rc::new(DwarfResolver::from_parser(parser, self.code_info)?))
} else {
ElfBackend::Elf(parser)
};

#[cfg(not(feature = "dwarf"))]
let backend = ElfBackend::Elf(parser);
Expand Down