From ed5d092b1189b88152ad04ba1cc972749f994b32 Mon Sep 17 00:00:00 2001 From: Robin Avery Date: Sat, 2 Mar 2024 20:47:18 -0500 Subject: [PATCH 1/2] objdiff-cli diff: Support "Relax relocation diffs" (#50) Bound to the `-x` flag or the `x` key. --- objdiff-cli/src/cmd/diff.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/objdiff-cli/src/cmd/diff.rs b/objdiff-cli/src/cmd/diff.rs index ec15f35..15e3075 100644 --- a/objdiff-cli/src/cmd/diff.rs +++ b/objdiff-cli/src/cmd/diff.rs @@ -43,6 +43,9 @@ pub struct Args { #[argp(option, short = 'u')] /// Unit name within project unit: Option, + #[argp(switch, short = 'x')] + /// Relax relocation diffs + relax_reloc_diffs: bool, #[argp(positional)] /// Function symbol to diff symbol: String, @@ -144,6 +147,7 @@ pub fn run(args: Args) -> Result<()> { .context("Failed to parse time format")?; let mut state = Box::new(FunctionDiffUi { redraw: true, + relax_reloc_diffs: args.relax_reloc_diffs, click_xy: None, left_highlight: HighlightKind::None, right_highlight: HighlightKind::None, @@ -216,6 +220,7 @@ fn find_function(obj: &ObjInfo, name: &str) -> Option { #[allow(dead_code)] struct FunctionDiffUi { redraw: bool, + relax_reloc_diffs: bool, click_xy: Option<(u16, u16)>, left_highlight: HighlightKind, right_highlight: HighlightKind, @@ -472,6 +477,12 @@ impl FunctionDiffUi { self.scroll_x = self.scroll_x.saturating_sub(1); self.redraw = true; } + // Toggle relax relocation diffs + KeyCode::Char('x') => { + self.relax_reloc_diffs = !self.relax_reloc_diffs; + self.redraw = true; + return FunctionDiffResult::Reload; + } _ => {} } } @@ -630,7 +641,7 @@ impl FunctionDiffUi { .as_deref() .map(|p| obj::elf::read(p).with_context(|| format!("Loading {}", p.display()))) .transpose()?; - let config = diff::DiffObjConfig::default(); + let config = diff::DiffObjConfig { relax_reloc_diffs: self.relax_reloc_diffs }; diff::diff_objs(&config, target.as_mut(), base.as_mut())?; let left_sym = target.as_ref().and_then(|o| find_function(o, &self.symbol_name)); From 9f4a1e86cd6d59a92b0843511277b13d2f7f27d2 Mon Sep 17 00:00:00 2001 From: Robin Avery Date: Sat, 2 Mar 2024 20:47:54 -0500 Subject: [PATCH 2/2] objdiff-cli diff: Reduce duplicate key event code (#51) --- objdiff-cli/src/cmd/diff.rs | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/objdiff-cli/src/cmd/diff.rs b/objdiff-cli/src/cmd/diff.rs index 15e3075..3adee7d 100644 --- a/objdiff-cli/src/cmd/diff.rs +++ b/objdiff-cli/src/cmd/diff.rs @@ -408,39 +408,28 @@ impl FunctionDiffUi { // Quit KeyCode::Esc | KeyCode::Char('q') => return FunctionDiffResult::Break, // Page up - KeyCode::PageUp => { - self.scroll_y = self.scroll_y.saturating_sub(self.per_page); - self.redraw = true; - } + KeyCode::PageUp => self.page_up(false), // Page up (shift + space) KeyCode::Char(' ') if event.modifiers.contains(KeyModifiers::SHIFT) => { - self.scroll_y = self.scroll_y.saturating_sub(self.per_page); - self.redraw = true; + self.page_up(false) } // Page down - KeyCode::Char(' ') | KeyCode::PageDown => { - self.scroll_y += self.per_page; - self.redraw = true; - } + KeyCode::Char(' ') | KeyCode::PageDown => self.page_down(false), // Page down (ctrl + f) KeyCode::Char('f') if event.modifiers.contains(KeyModifiers::CONTROL) => { - self.scroll_y += self.per_page; - self.redraw = true; + self.page_down(false) } // Page up (ctrl + b) KeyCode::Char('b') if event.modifiers.contains(KeyModifiers::CONTROL) => { - self.scroll_y = self.scroll_y.saturating_sub(self.per_page); - self.redraw = true; + self.page_up(false) } // Half page down (ctrl + d) KeyCode::Char('d') if event.modifiers.contains(KeyModifiers::CONTROL) => { - self.scroll_y += self.per_page / 2; - self.redraw = true; + self.page_down(true) } // Half page up (ctrl + u) KeyCode::Char('u') if event.modifiers.contains(KeyModifiers::CONTROL) => { - self.scroll_y = self.scroll_y.saturating_sub(self.per_page / 2); - self.redraw = true; + self.page_up(true) } // Scroll down KeyCode::Down | KeyCode::Char('j') => { @@ -517,6 +506,16 @@ impl FunctionDiffUi { FunctionDiffResult::Continue } + fn page_up(&mut self, half: bool) { + self.scroll_y = self.scroll_y.saturating_sub(self.per_page / if half { 2 } else { 1 }); + self.redraw = true; + } + + fn page_down(&mut self, half: bool) { + self.scroll_y += self.per_page / if half { 2 } else { 1 }; + self.redraw = true; + } + fn print_sym( &self, out: &mut Text,