diff --git a/objdiff-cli/src/cmd/diff.rs b/objdiff-cli/src/cmd/diff.rs index 4c87666..fca7e16 100644 --- a/objdiff-cli/src/cmd/diff.rs +++ b/objdiff-cli/src/cmd/diff.rs @@ -750,8 +750,11 @@ impl FunctionDiffUi { base_color = COLOR_ROTATION[diff.idx % COLOR_ROTATION.len()] } } - DiffText::BranchDest(addr) => { + DiffText::BranchDest(addr, diff) => { label_text = format!("{addr:x}"); + if let Some(diff) = diff { + base_color = COLOR_ROTATION[diff.idx % COLOR_ROTATION.len()] + } } DiffText::Symbol(sym) => { let name = sym.demangled_name.as_ref().unwrap_or(&sym.name); diff --git a/objdiff-core/src/diff/display.rs b/objdiff-core/src/diff/display.rs index 95d7a38..6f007bd 100644 --- a/objdiff-core/src/diff/display.rs +++ b/objdiff-core/src/diff/display.rs @@ -20,7 +20,7 @@ pub enum DiffText<'a> { /// Instruction argument Argument(&'a ObjInsArgValue, Option<&'a ObjInsArgDiff>), /// Branch destination - BranchDest(u64), + BranchDest(u64, Option<&'a ObjInsArgDiff>), /// Symbol name Symbol(&'a ObjSymbol), /// Number of spaces @@ -62,12 +62,12 @@ pub fn display_diff( if i == 0 { cb(DiffText::Spacing(1))?; } + let diff = ins_diff.arg_diff.get(i).and_then(|o| o.as_ref()); match arg { ObjInsArg::PlainText(s) => { cb(DiffText::Basic(s))?; } ObjInsArg::Arg(v) => { - let diff = ins_diff.arg_diff.get(i).and_then(|o| o.as_ref()); cb(DiffText::Argument(v, diff))?; } ObjInsArg::Reloc => { @@ -75,7 +75,7 @@ pub fn display_diff( } ObjInsArg::BranchDest(dest) => { if let Some(dest) = dest.checked_sub(base_addr) { - cb(DiffText::BranchDest(dest))?; + cb(DiffText::BranchDest(dest, diff))?; } else { cb(DiffText::Basic(""))?; } @@ -107,7 +107,9 @@ impl PartialEq> for HighlightKind { (HighlightKind::Opcode(a), DiffText::Opcode(_, b)) => a == b, (HighlightKind::Arg(a), DiffText::Argument(b, _)) => a.loose_eq(b), (HighlightKind::Symbol(a), DiffText::Symbol(b)) => a == &b.name, - (HighlightKind::Address(a), DiffText::Address(b) | DiffText::BranchDest(b)) => a == b, + (HighlightKind::Address(a), DiffText::Address(b) | DiffText::BranchDest(b, _)) => { + a == b + } _ => false, } } @@ -123,7 +125,7 @@ impl From> for HighlightKind { DiffText::Opcode(_, op) => HighlightKind::Opcode(op), DiffText::Argument(arg, _) => HighlightKind::Arg(arg.clone()), 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, } } diff --git a/objdiff-gui/src/views/function_diff.rs b/objdiff-gui/src/views/function_diff.rs index b1d3b88..d9c5575 100644 --- a/objdiff-gui/src/views/function_diff.rs +++ b/objdiff-gui/src/views/function_diff.rs @@ -216,8 +216,11 @@ fn diff_text_ui( base_color = appearance.diff_colors[diff.idx % appearance.diff_colors.len()] } } - DiffText::BranchDest(addr) => { + DiffText::BranchDest(addr, diff) => { label_text = format!("{addr:x}"); + if let Some(diff) = diff { + base_color = appearance.diff_colors[diff.idx % appearance.diff_colors.len()] + } } DiffText::Symbol(sym) => { let name = sym.demangled_name.as_ref().unwrap_or(&sym.name);