mirror of
https://github.com/encounter/objdiff.git
synced 2025-06-05 14:13:45 +00:00
Ignore extern symbols with symbol name lookups
When searching for a symbol by name, only look at symbols that are defined within the object, ignoring extern symbols (symbols without section). Fixes #180 Fixes #181
This commit is contained in:
parent
8e8ab6bef8
commit
07ef93f16a
@ -450,11 +450,11 @@ impl UiView for FunctionDiffUi {
|
||||
|
||||
fn reload(&mut self, state: &AppState) -> Result<()> {
|
||||
let left_sym =
|
||||
state.left_obj.as_ref().and_then(|(o, _)| find_function(o, &self.symbol_name));
|
||||
state.left_obj.as_ref().and_then(|(o, _)| o.symbol_by_name(&self.symbol_name));
|
||||
let right_sym =
|
||||
state.right_obj.as_ref().and_then(|(o, _)| find_function(o, &self.symbol_name));
|
||||
state.right_obj.as_ref().and_then(|(o, _)| o.symbol_by_name(&self.symbol_name));
|
||||
let prev_sym =
|
||||
state.prev_obj.as_ref().and_then(|(o, _)| find_function(o, &self.symbol_name));
|
||||
state.prev_obj.as_ref().and_then(|(o, _)| o.symbol_by_name(&self.symbol_name));
|
||||
self.num_rows = match (
|
||||
get_symbol(state.left_obj.as_ref(), left_sym),
|
||||
get_symbol(state.right_obj.as_ref(), right_sym),
|
||||
@ -650,12 +650,3 @@ fn get_symbol(
|
||||
let sym = sym?;
|
||||
Some((obj, sym, &diff.symbols[sym]))
|
||||
}
|
||||
|
||||
fn find_function(obj: &Object, name: &str) -> Option<usize> {
|
||||
for (symbol_idx, symbol) in obj.symbols.iter().enumerate() {
|
||||
if symbol.name == name {
|
||||
return Some(symbol_idx);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
@ -391,7 +391,7 @@ fn generate_mapping_symbols(
|
||||
MappingSymbol::Left(name) => (left_obj, name, right_obj),
|
||||
MappingSymbol::Right(name) => (right_obj, name, left_obj),
|
||||
};
|
||||
let Some(base_symbol_ref) = symbol_ref_by_name(base_obj, base_name) else {
|
||||
let Some(base_symbol_ref) = base_obj.symbol_by_name(base_name) else {
|
||||
return Ok(());
|
||||
};
|
||||
let base_section_kind = symbol_section_kind(base_obj, &base_obj.symbols[base_symbol_ref]);
|
||||
@ -457,10 +457,6 @@ pub struct MappingConfig {
|
||||
pub selecting_right: Option<String>,
|
||||
}
|
||||
|
||||
fn symbol_ref_by_name(obj: &Object, name: &str) -> Option<usize> {
|
||||
obj.symbols.iter().position(|s| s.name == name)
|
||||
}
|
||||
|
||||
fn apply_symbol_mappings(
|
||||
left: &Object,
|
||||
right: &Object,
|
||||
@ -472,25 +468,25 @@ fn apply_symbol_mappings(
|
||||
// If we're selecting a symbol to use as a comparison, mark it as used
|
||||
// This ensures that we don't match it to another symbol at any point
|
||||
if let Some(left_name) = &mapping_config.selecting_left {
|
||||
if let Some(left_symbol) = symbol_ref_by_name(left, left_name) {
|
||||
if let Some(left_symbol) = left.symbol_by_name(left_name) {
|
||||
left_used.insert(left_symbol);
|
||||
}
|
||||
}
|
||||
if let Some(right_name) = &mapping_config.selecting_right {
|
||||
if let Some(right_symbol) = symbol_ref_by_name(right, right_name) {
|
||||
if let Some(right_symbol) = right.symbol_by_name(right_name) {
|
||||
right_used.insert(right_symbol);
|
||||
}
|
||||
}
|
||||
|
||||
// Apply manual symbol mappings
|
||||
for (left_name, right_name) in &mapping_config.mappings {
|
||||
let Some(left_symbol_index) = symbol_ref_by_name(left, left_name) else {
|
||||
let Some(left_symbol_index) = left.symbol_by_name(left_name) else {
|
||||
continue;
|
||||
};
|
||||
if left_used.contains(&left_symbol_index) {
|
||||
continue;
|
||||
}
|
||||
let Some(right_symbol_index) = symbol_ref_by_name(right, right_name) else {
|
||||
let Some(right_symbol_index) = right.symbol_by_name(right_name) else {
|
||||
continue;
|
||||
};
|
||||
if right_used.contains(&right_symbol_index) {
|
||||
|
@ -308,6 +308,10 @@ impl Object {
|
||||
let offset = symbol.address.checked_sub(section.address)?;
|
||||
section.data.get(offset as usize..offset as usize + symbol.size as usize)
|
||||
}
|
||||
|
||||
pub fn symbol_by_name(&self, name: &str) -> Option<usize> {
|
||||
self.symbols.iter().position(|symbol| symbol.section.is_some() && symbol.name == name)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
|
||||
|
@ -49,7 +49,9 @@ impl<'a> DiffColumnContext<'a> {
|
||||
let selected_symbol = match view {
|
||||
View::SymbolDiff => None,
|
||||
View::FunctionDiff | View::ExtabDiff => match (obj, selected_symbol) {
|
||||
(Some(obj), Some(s)) => find_symbol(&obj.0, s).map(SelectedSymbol::Symbol),
|
||||
(Some(obj), Some(s)) => {
|
||||
obj.0.symbol_by_name(&s.symbol_name).map(SelectedSymbol::Symbol)
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
View::DataDiff => match (obj, selected_symbol) {
|
||||
@ -779,10 +781,6 @@ fn missing_obj_ui(ui: &mut Ui, appearance: &Appearance) {
|
||||
});
|
||||
}
|
||||
|
||||
fn find_symbol(obj: &Object, selected_symbol: &SymbolRefByName) -> Option<usize> {
|
||||
obj.symbols.iter().position(|symbol| symbol.name == selected_symbol.symbol_name)
|
||||
}
|
||||
|
||||
fn find_section(obj: &Object, section_name: &str) -> Option<usize> {
|
||||
obj.sections.iter().position(|section| section.name == section_name)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user