Version 0.2.3

- Fix regression when diffing symbols
  across mismatched section indexes
This commit is contained in:
Luke Street 2022-12-10 20:28:01 -05:00
parent 7219e72acf
commit 613e84ecf2
4 changed files with 21 additions and 14 deletions

View File

@ -81,7 +81,7 @@ impl Default for ViewConfig {
pub struct SymbolReference {
pub symbol_name: String,
pub section_index: usize,
pub section_name: String,
}
#[derive(serde::Deserialize, serde::Serialize)]

View File

@ -14,7 +14,9 @@ use crate::{
const BYTES_PER_ROW: usize = 16;
fn find_section<'a>(obj: &'a ObjInfo, selected_symbol: &SymbolReference) -> Option<&'a ObjSection> {
obj.sections.get(selected_symbol.section_index)
obj.sections.iter().find(|section| {
section.symbols.iter().any(|symbol| symbol.name == selected_symbol.symbol_name)
})
}
fn data_row_ui(ui: &mut egui::Ui, address: usize, diffs: &[ObjDataDiff], config: &ViewConfig) {

View File

@ -241,8 +241,9 @@ fn ins_context_menu(ui: &mut egui::Ui, ins: &ObjIns) {
}
fn find_symbol<'a>(obj: &'a ObjInfo, selected_symbol: &SymbolReference) -> Option<&'a ObjSymbol> {
let section = obj.sections.get(selected_symbol.section_index)?;
section.symbols.iter().find(|s| s.name == selected_symbol.symbol_name)
obj.sections.iter().find_map(|section| {
section.symbols.iter().find(|symbol| symbol.name == selected_symbol.symbol_name)
})
}
fn asm_row_ui(ui: &mut egui::Ui, ins_diff: &ObjInsDiff, symbol: &ObjSymbol, config: &ViewConfig) {

View File

@ -56,7 +56,7 @@ fn symbol_hover_ui(ui: &mut Ui, symbol: &ObjSymbol) {
fn symbol_ui(
ui: &mut Ui,
symbol: &ObjSymbol,
section: Option<(usize, &ObjSection)>,
section: Option<&ObjSection>,
highlighted_symbol: &mut Option<String>,
selected_symbol: &mut Option<SymbolReference>,
current_view: &mut View,
@ -97,14 +97,18 @@ fn symbol_ui(
.context_menu(|ui| symbol_context_menu_ui(ui, symbol))
.on_hover_ui_at_pointer(|ui| symbol_hover_ui(ui, symbol));
if response.clicked() {
if let Some((section_index, section)) = section {
if let Some(section) = section {
if section.kind == ObjSectionKind::Code {
*selected_symbol =
Some(SymbolReference { symbol_name: symbol.name.clone(), section_index });
*selected_symbol = Some(SymbolReference {
symbol_name: symbol.name.clone(),
section_name: section.name.clone(),
});
*current_view = View::FunctionDiff;
} else if section.kind == ObjSectionKind::Data {
*selected_symbol =
Some(SymbolReference { symbol_name: section.name.clone(), section_index });
*selected_symbol = Some(SymbolReference {
symbol_name: section.name.clone(),
section_name: section.name.clone(),
});
*current_view = View::DataDiff;
}
}
@ -158,11 +162,11 @@ fn symbol_list_ui(
});
}
for (section_index, section) in obj.sections.iter().enumerate() {
for section in &obj.sections {
CollapsingHeader::new(format!("{} ({:x})", section.name, section.size))
.default_open(true)
.show(ui, |ui| {
if section.name == ".text" && reverse_function_order {
if section.kind == ObjSectionKind::Code && reverse_function_order {
for symbol in section.symbols.iter().rev() {
if !symbol_matches_search(symbol, &lower_search) {
continue;
@ -170,7 +174,7 @@ fn symbol_list_ui(
symbol_ui(
ui,
symbol,
Some((section_index, section)),
Some(section),
highlighted_symbol,
selected_symbol,
current_view,
@ -185,7 +189,7 @@ fn symbol_list_ui(
symbol_ui(
ui,
symbol,
Some((section_index, section)),
Some(section),
highlighted_symbol,
selected_symbol,
current_view,