|
|
@ -689,33 +689,36 @@ fn resolve_symbol(path: &Path, symbol: &str) -> Result<u64, ResolveSymbolError>
|
|
|
|
let data = fs::read(path)?;
|
|
|
|
let data = fs::read(path)?;
|
|
|
|
let obj = object::read::File::parse(&*data)?;
|
|
|
|
let obj = object::read::File::parse(&*data)?;
|
|
|
|
|
|
|
|
|
|
|
|
let mut debug_data = Vec::default();
|
|
|
|
if let Some(sym) = find_symbol_in_object(&obj, symbol) {
|
|
|
|
let mut debug_obj_keeper = None;
|
|
|
|
symbol_translated_address(&obj, sym, symbol)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
let sym = find_symbol_in_object(&obj, symbol).map_or_else(
|
|
|
|
// Only search in the debug object if the symbol was not found in the main object
|
|
|
|
|| {
|
|
|
|
let debug_path = find_debug_path_in_object(&obj, path, symbol)?;
|
|
|
|
// Only search in the debug object if the symbol was not found in the main object
|
|
|
|
let debug_data = fs::read(&debug_path).map_err(|e| {
|
|
|
|
let debug_path = find_debug_path_in_object(&obj, path, symbol)?;
|
|
|
|
ResolveSymbolError::DebuglinkAccessError(
|
|
|
|
debug_data = fs::read(&debug_path).map_err(|e| {
|
|
|
|
debug_path
|
|
|
|
ResolveSymbolError::DebuglinkAccessError(
|
|
|
|
.to_str()
|
|
|
|
debug_path
|
|
|
|
.unwrap_or("Debuglink path missing")
|
|
|
|
.to_str()
|
|
|
|
.to_string(),
|
|
|
|
.unwrap_or("Debuglink path missing")
|
|
|
|
e,
|
|
|
|
.to_string(),
|
|
|
|
)
|
|
|
|
e,
|
|
|
|
})?;
|
|
|
|
)
|
|
|
|
let debug_obj = object::read::File::parse(&*debug_data)?;
|
|
|
|
})?;
|
|
|
|
|
|
|
|
let debug_obj = object::read::File::parse(&*debug_data)?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verify_build_ids(&obj, &debug_obj, symbol)?;
|
|
|
|
verify_build_ids(&obj, &debug_obj, symbol)?;
|
|
|
|
|
|
|
|
|
|
|
|
debug_obj_keeper = Some(debug_obj);
|
|
|
|
let sym = find_symbol_in_object(&debug_obj, symbol)
|
|
|
|
find_symbol_in_object(debug_obj_keeper.as_ref().unwrap(), symbol)
|
|
|
|
.ok_or_else(|| ResolveSymbolError::Unknown(symbol.to_string()))?;
|
|
|
|
.ok_or_else(|| ResolveSymbolError::Unknown(symbol.to_string()))
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Ok,
|
|
|
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
symbol_translated_address(&debug_obj, sym, symbol)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn symbol_translated_address(
|
|
|
|
|
|
|
|
obj: &object::File<'_>,
|
|
|
|
|
|
|
|
sym: Symbol<'_, '_>,
|
|
|
|
|
|
|
|
symbol_name: &str,
|
|
|
|
|
|
|
|
) -> Result<u64, ResolveSymbolError> {
|
|
|
|
let needs_addr_translation = matches!(
|
|
|
|
let needs_addr_translation = matches!(
|
|
|
|
obj.kind(),
|
|
|
|
obj.kind(),
|
|
|
|
object::ObjectKind::Dynamic | object::ObjectKind::Executable
|
|
|
|
object::ObjectKind::Dynamic | object::ObjectKind::Executable
|
|
|
@ -725,11 +728,11 @@ fn resolve_symbol(path: &Path, symbol: &str) -> Result<u64, ResolveSymbolError>
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
let index = sym
|
|
|
|
let index = sym
|
|
|
|
.section_index()
|
|
|
|
.section_index()
|
|
|
|
.ok_or_else(|| ResolveSymbolError::NotInSection(symbol.to_string()))?;
|
|
|
|
.ok_or_else(|| ResolveSymbolError::NotInSection(symbol_name.to_string()))?;
|
|
|
|
let section = obj.section_by_index(index)?;
|
|
|
|
let section = obj.section_by_index(index)?;
|
|
|
|
let (offset, _size) = section.file_range().ok_or_else(|| {
|
|
|
|
let (offset, _size) = section.file_range().ok_or_else(|| {
|
|
|
|
ResolveSymbolError::SectionFileRangeNone(
|
|
|
|
ResolveSymbolError::SectionFileRangeNone(
|
|
|
|
symbol.to_string(),
|
|
|
|
symbol_name.to_string(),
|
|
|
|
section.name().map(str::to_owned),
|
|
|
|
section.name().map(str::to_owned),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
})?;
|
|
|
|
})?;
|
|
|
|