Skip to content

Commit e49da4d

Browse files
committed
Also highlight addend when reloc differs
1 parent bd2c5d2 commit e49da4d

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

objdiff-cli/src/views/function_diff.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::cmp::Ordering;
2+
13
use anyhow::{bail, Result};
24
use crossterm::event::{Event, KeyCode, KeyEventKind, KeyModifiers, MouseButton, MouseEventKind};
35
use objdiff_core::{
@@ -563,6 +565,18 @@ impl FunctionDiffUi {
563565
base_color = Color::White;
564566
}
565567
}
568+
DiffText::Addend(addend, diff) => {
569+
label_text = match addend.cmp(&0i64) {
570+
Ordering::Greater => format!("+{:#x}", addend),
571+
Ordering::Less => format!("-{:#x}", -addend),
572+
_ => "".to_string(),
573+
};
574+
if let Some(diff) = diff {
575+
base_color = COLOR_ROTATION[diff.idx % COLOR_ROTATION.len()]
576+
} else {
577+
base_color = Color::White;
578+
}
579+
}
566580
DiffText::Spacing(n) => {
567581
line.spans.push(Span::raw(" ".repeat(n)));
568582
sx += n as u16;

objdiff-core/src/diff/display.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::cmp::Ordering;
2-
31
use crate::{
42
diff::{ObjInsArgDiff, ObjInsDiff},
53
obj::{ObjInsArg, ObjInsArgValue, ObjReloc, ObjSymbol},
@@ -23,6 +21,8 @@ pub enum DiffText<'a> {
2321
BranchDest(u64, Option<&'a ObjInsArgDiff>),
2422
/// Symbol name
2523
Symbol(&'a ObjSymbol, Option<&'a ObjInsArgDiff>),
24+
/// Relocation addend
25+
Addend(i64, Option<&'a ObjInsArgDiff>),
2626
/// Number of spaces
2727
Spacing(usize),
2828
/// End of line
@@ -99,11 +99,7 @@ fn display_reloc_name<E>(
9999
diff: Option<&ObjInsArgDiff>,
100100
) -> Result<(), E> {
101101
cb(DiffText::Symbol(&reloc.target, diff))?;
102-
match reloc.addend.cmp(&0i64) {
103-
Ordering::Greater => cb(DiffText::Basic(&format!("+{:#x}", reloc.addend))),
104-
Ordering::Less => cb(DiffText::Basic(&format!("-{:#x}", -reloc.addend))),
105-
_ => Ok(()),
106-
}
102+
cb(DiffText::Addend(reloc.addend, diff))
107103
}
108104

109105
impl PartialEq<DiffText<'_>> for HighlightKind {

objdiff-gui/src/views/function_diff.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,18 @@ fn diff_text_ui(
312312
base_color = appearance.emphasized_text_color;
313313
}
314314
}
315+
DiffText::Addend(addend, diff) => {
316+
label_text = match addend.cmp(&0i64) {
317+
Ordering::Greater => format!("+{:#x}", addend),
318+
Ordering::Less => format!("-{:#x}", -addend),
319+
_ => "".to_string(),
320+
};
321+
if let Some(diff) = diff {
322+
base_color = appearance.diff_colors[diff.idx % appearance.diff_colors.len()]
323+
} else {
324+
base_color = appearance.emphasized_text_color;
325+
}
326+
}
315327
DiffText::Spacing(n) => {
316328
ui.add_space(n as f32 * space_width);
317329
return ret;

0 commit comments

Comments
 (0)