Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions objdiff-gui/src/hotkeys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,9 @@ const CHANGE_BASE_SHORTCUT: KeyboardShortcut = KeyboardShortcut::new(Modifiers::
pub fn consume_change_base_shortcut(ctx: &Context) -> bool {
ctx.input_mut(|i| i.consume_shortcut(&CHANGE_BASE_SHORTCUT))
}

const GO_TO_SHORTCUT: KeyboardShortcut = KeyboardShortcut::new(Modifiers::CTRL, Key::G);

pub fn consume_go_to_shortcut(ctx: &Context) -> bool {
ctx.input_mut(|i| i.consume_shortcut(&GO_TO_SHORTCUT))
}
55 changes: 55 additions & 0 deletions objdiff-gui/src/views/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,28 @@ fn get_asm_text(
asm_text
}

fn try_scroll_to_line_number(
scroll_to_line_number: Option<u32>,
obj: &Object,
diff: &ObjectDiff,
symbol_idx: usize,
) -> Option<DiffViewAction> {
let target_line = scroll_to_line_number?;
let symbol = obj.symbols.get(symbol_idx)?;
let section_index = symbol.section?;
let section = &obj.sections[section_index];
for (ins_idx, ins_row) in diff.symbols[symbol_idx].instruction_rows.iter().enumerate() {
if let Some(ins_ref) = ins_row.ins_ref
&& let Some(current_line) =
section.line_info.range(..=ins_ref.address).last().map(|(_, &b)| b)
&& current_line == target_line
{
return Some(DiffViewAction::ScrollToRow(ins_idx));
}
}
None
}

#[must_use]
pub fn diff_view_ui(
ui: &mut Ui,
Expand Down Expand Up @@ -450,6 +472,23 @@ pub fn diff_view_ui(
{
ret = Some(DiffViewAction::SelectingRight(symbol_ref.clone()));
}
needs_separator = true;
}
if state.current_view == View::FunctionDiff {
if needs_separator {
ui.separator();
}
let mut goto_line_text = state.function_state.go_to_line_text.clone();
let response = TextEdit::singleline(&mut goto_line_text)
.hint_text("Go to line number")
.desired_width(100.0)
.ui(ui);
if hotkeys::consume_go_to_shortcut(ui.ctx()) {
response.request_focus();
}
if response.changed() {
ret = Some(DiffViewAction::SetGoToText(goto_line_text));
}
}
} else if right_ctx.status.success && !right_ctx.has_symbol() {
let mut search = state.search.clone();
Expand Down Expand Up @@ -492,6 +531,14 @@ pub fn diff_view_ui(
ui.label("Instruction count mismatch");
return;
}
if let Some(action) = try_scroll_to_line_number(
state.function_state.scroll_to_line_number,
right_obj,
right_diff,
right_symbol_idx,
) {
ret = Some(action);
}
let instructions_len = left_symbol_diff.instruction_rows.len();
render_table(
ui,
Expand Down Expand Up @@ -711,6 +758,14 @@ fn diff_col_ui(
},
);
} else {
if let Some(action) = try_scroll_to_line_number(
state.function_state.scroll_to_line_number,
obj,
diff,
symbol_idx,
) {
ret = Some(action);
}
render_table(
ui,
available_width / 2.0,
Expand Down
2 changes: 2 additions & 0 deletions objdiff-gui/src/views/function_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub struct FunctionViewState {
left_highlight: HighlightKind,
right_highlight: HighlightKind,
pub scroll_to_row: Option<usize>,
pub scroll_to_line_number: Option<u32>,
pub go_to_line_text: String,
}

impl FunctionViewState {
Expand Down
9 changes: 9 additions & 0 deletions objdiff-gui/src/views/symbol_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ pub enum DiffViewAction {
SetShowDataFlow(bool),
// Scrolls a row of the function view table into view.
ScrollToRow(usize),
/// Sets the text of the line number jump field and try to scroll that line into view.
SetGoToText(String),
}

#[derive(Debug, Clone, Default, Eq, PartialEq)]
Expand Down Expand Up @@ -198,6 +200,7 @@ impl DiffViewState {
// Clear the scroll flags to prevent it from scrolling continuously.
self.symbol_state.autoscroll_to_highlighted_symbols = false;
self.function_state.scroll_to_row = None;
self.function_state.scroll_to_line_number = None;

let Some(action) = action else {
return;
Expand Down Expand Up @@ -368,6 +371,12 @@ impl DiffViewState {
DiffViewAction::ScrollToRow(row) => {
self.function_state.scroll_to_row = Some(row);
}
DiffViewAction::SetGoToText(text) => {
if let Ok(line_num) = text.trim().parse::<u32>() {
self.function_state.scroll_to_line_number = Some(line_num);
}
self.function_state.go_to_line_text = text;
}
}
}

Expand Down
Loading