Show diff color when symbols differ

This commit is contained in:
Luke Street 2024-10-31 17:26:28 -06:00
parent 2fd655850a
commit c5da7f7dd5
4 changed files with 28 additions and 13 deletions

View File

@ -844,11 +844,15 @@ impl FunctionDiffUi {
base_color = COLOR_ROTATION[diff.idx % COLOR_ROTATION.len()] base_color = COLOR_ROTATION[diff.idx % COLOR_ROTATION.len()]
} }
} }
DiffText::Symbol(sym) => { DiffText::Symbol(sym, diff) => {
let name = sym.demangled_name.as_ref().unwrap_or(&sym.name); let name = sym.demangled_name.as_ref().unwrap_or(&sym.name);
label_text = name.clone(); label_text = name.clone();
if let Some(diff) = diff {
base_color = COLOR_ROTATION[diff.idx % COLOR_ROTATION.len()]
} else {
base_color = Color::White; base_color = Color::White;
} }
}
DiffText::Spacing(n) => { DiffText::Spacing(n) => {
line.spans.push(Span::raw(" ".repeat(n))); line.spans.push(Span::raw(" ".repeat(n)));
sx += n as u16; sx += n as u16;

View File

@ -330,8 +330,11 @@ fn compare_ins(
let a_str = match a { let a_str = match a {
ObjInsArg::PlainText(arg) => arg.to_string(), ObjInsArg::PlainText(arg) => arg.to_string(),
ObjInsArg::Arg(arg) => arg.to_string(), ObjInsArg::Arg(arg) => arg.to_string(),
ObjInsArg::Reloc => String::new(), ObjInsArg::Reloc => left_ins
ObjInsArg::BranchDest(arg) => format!("{arg}"), .reloc
.as_ref()
.map_or_else(|| "<unknown>".to_string(), |r| r.target.name.clone()),
ObjInsArg::BranchDest(arg) => arg.to_string(),
}; };
let a_diff = if let Some(idx) = state.left_args_idx.get(&a_str) { let a_diff = if let Some(idx) = state.left_args_idx.get(&a_str) {
ObjInsArgDiff { idx: *idx } ObjInsArgDiff { idx: *idx }
@ -344,8 +347,11 @@ fn compare_ins(
let b_str = match b { let b_str = match b {
ObjInsArg::PlainText(arg) => arg.to_string(), ObjInsArg::PlainText(arg) => arg.to_string(),
ObjInsArg::Arg(arg) => arg.to_string(), ObjInsArg::Arg(arg) => arg.to_string(),
ObjInsArg::Reloc => String::new(), ObjInsArg::Reloc => right_ins
ObjInsArg::BranchDest(arg) => format!("{arg}"), .reloc
.as_ref()
.map_or_else(|| "<unknown>".to_string(), |r| r.target.name.clone()),
ObjInsArg::BranchDest(arg) => arg.to_string(),
}; };
let b_diff = if let Some(idx) = state.right_args_idx.get(&b_str) { let b_diff = if let Some(idx) = state.right_args_idx.get(&b_str) {
ObjInsArgDiff { idx: *idx } ObjInsArgDiff { idx: *idx }

View File

@ -22,7 +22,7 @@ pub enum DiffText<'a> {
/// Branch destination /// Branch destination
BranchDest(u64, Option<&'a ObjInsArgDiff>), BranchDest(u64, Option<&'a ObjInsArgDiff>),
/// Symbol name /// Symbol name
Symbol(&'a ObjSymbol), Symbol(&'a ObjSymbol, Option<&'a ObjInsArgDiff>),
/// Number of spaces /// Number of spaces
Spacing(usize), Spacing(usize),
/// End of line /// End of line
@ -71,7 +71,7 @@ pub fn display_diff<E>(
cb(DiffText::Argument(v, diff))?; cb(DiffText::Argument(v, diff))?;
} }
ObjInsArg::Reloc => { ObjInsArg::Reloc => {
display_reloc_name(ins.reloc.as_ref().unwrap(), &mut cb)?; display_reloc_name(ins.reloc.as_ref().unwrap(), &mut cb, diff)?;
} }
ObjInsArg::BranchDest(dest) => { ObjInsArg::BranchDest(dest) => {
if let Some(dest) = dest.checked_sub(base_addr) { if let Some(dest) = dest.checked_sub(base_addr) {
@ -92,8 +92,9 @@ pub fn display_diff<E>(
fn display_reloc_name<E>( fn display_reloc_name<E>(
reloc: &ObjReloc, reloc: &ObjReloc,
mut cb: impl FnMut(DiffText) -> Result<(), E>, mut cb: impl FnMut(DiffText) -> Result<(), E>,
diff: Option<&ObjInsArgDiff>,
) -> Result<(), E> { ) -> Result<(), E> {
cb(DiffText::Symbol(&reloc.target))?; cb(DiffText::Symbol(&reloc.target, diff))?;
match reloc.addend.cmp(&0i64) { match reloc.addend.cmp(&0i64) {
Ordering::Greater => cb(DiffText::Basic(&format!("+{:#x}", reloc.addend))), Ordering::Greater => cb(DiffText::Basic(&format!("+{:#x}", reloc.addend))),
Ordering::Less => cb(DiffText::Basic(&format!("-{:#x}", -reloc.addend))), Ordering::Less => cb(DiffText::Basic(&format!("-{:#x}", -reloc.addend))),
@ -106,7 +107,7 @@ impl PartialEq<DiffText<'_>> for HighlightKind {
match (self, other) { match (self, other) {
(HighlightKind::Opcode(a), DiffText::Opcode(_, b)) => a == b, (HighlightKind::Opcode(a), DiffText::Opcode(_, b)) => a == b,
(HighlightKind::Arg(a), DiffText::Argument(b, _)) => a.loose_eq(b), (HighlightKind::Arg(a), DiffText::Argument(b, _)) => a.loose_eq(b),
(HighlightKind::Symbol(a), DiffText::Symbol(b)) => a == &b.name, (HighlightKind::Symbol(a), DiffText::Symbol(b, _)) => a == &b.name,
(HighlightKind::Address(a), DiffText::Address(b) | DiffText::BranchDest(b, _)) => { (HighlightKind::Address(a), DiffText::Address(b) | DiffText::BranchDest(b, _)) => {
a == b a == b
} }
@ -124,7 +125,7 @@ impl From<DiffText<'_>> for HighlightKind {
match value { match value {
DiffText::Opcode(_, op) => HighlightKind::Opcode(op), DiffText::Opcode(_, op) => HighlightKind::Opcode(op),
DiffText::Argument(arg, _) => HighlightKind::Arg(arg.clone()), DiffText::Argument(arg, _) => HighlightKind::Arg(arg.clone()),
DiffText::Symbol(sym) => HighlightKind::Symbol(sym.name.to_string()), DiffText::Symbol(sym, _) => HighlightKind::Symbol(sym.name.to_string()),
DiffText::Address(addr) | DiffText::BranchDest(addr, _) => HighlightKind::Address(addr), DiffText::Address(addr) | DiffText::BranchDest(addr, _) => HighlightKind::Address(addr),
_ => HighlightKind::None, _ => HighlightKind::None,
} }

View File

@ -292,11 +292,15 @@ fn diff_text_ui(
base_color = appearance.diff_colors[diff.idx % appearance.diff_colors.len()] base_color = appearance.diff_colors[diff.idx % appearance.diff_colors.len()]
} }
} }
DiffText::Symbol(sym) => { DiffText::Symbol(sym, diff) => {
let name = sym.demangled_name.as_ref().unwrap_or(&sym.name); let name = sym.demangled_name.as_ref().unwrap_or(&sym.name);
label_text = name.clone(); label_text = name.clone();
if let Some(diff) = diff {
base_color = appearance.diff_colors[diff.idx % appearance.diff_colors.len()]
} else {
base_color = appearance.emphasized_text_color; base_color = appearance.emphasized_text_color;
} }
}
DiffText::Spacing(n) => { DiffText::Spacing(n) => {
ui.add_space(n as f32 * space_width); ui.add_space(n as f32 * space_width);
return ret; return ret;