Skip to content

Commit

Permalink
Add option to disable func data value diffing
Browse files Browse the repository at this point in the history
  • Loading branch information
LagoLunatic committed Jan 8, 2025
1 parent b6a3f1f commit c716a81
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
12 changes: 8 additions & 4 deletions objdiff-cli/src/views/function_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crossterm::event::{Event, KeyCode, KeyEventKind, KeyModifiers, MouseButton,
use objdiff_core::{
diff::{
display::{display_diff, DiffText, HighlightKind},
ObjDiff, ObjInsDiffKind, ObjSymbolDiff,
FunctionDataDiffs, ObjDiff, ObjInsDiffKind, ObjSymbolDiff,
},
obj::{ObjInfo, ObjSectionKind, ObjSymbol, SymbolRef},
};
Expand Down Expand Up @@ -375,10 +375,14 @@ impl UiView for FunctionDiffUi {
result.redraw = true;
return EventControlFlow::Reload;
}
// Toggle relax shifted data diffs
// Cycle through function data diff mode
KeyCode::Char('s') => {
state.diff_obj_config.relax_shifted_data_diffs =
!state.diff_obj_config.relax_shifted_data_diffs;
state.diff_obj_config.function_data_diffs =
match state.diff_obj_config.function_data_diffs {
FunctionDataDiffs::AddressOnly => FunctionDataDiffs::ValueOnly,
FunctionDataDiffs::ValueOnly => FunctionDataDiffs::All,
FunctionDataDiffs::All => FunctionDataDiffs::AddressOnly,
};
result.redraw = true;
return EventControlFlow::Reload;
}
Expand Down
26 changes: 20 additions & 6 deletions objdiff-core/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,25 @@
"description": "Ignores differences in relocation targets. (Address, name, etc)"
},
{
"id": "relaxShiftedDataDiffs",
"type": "boolean",
"default": false,
"name": "Relax shifted data diffs",
"description": "Ignores differences in addresses for symbols with matching data."
"id": "functionDataDiffs",
"type": "choice",
"default": "address_only",
"name": "Function data diffs",
"description": "How data relocations will be diffed in the function view.",
"items": [
{
"value": "address_only",
"name": "Address only"
},
{
"value": "value_only",
"name": "Value only"
},
{
"value": "all",
"name": "Value and address"
}
]
},
{
"id": "spaceBetweenArgs",
Expand Down Expand Up @@ -201,7 +215,7 @@
"name": "General",
"properties": [
"relaxRelocDiffs",
"relaxShiftedDataDiffs",
"functionDataDiffs",
"spaceBetweenArgs",
"combineDataSections"
]
Expand Down
6 changes: 4 additions & 2 deletions objdiff-core/src/diff/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{cmp::max, collections::BTreeMap};
use anyhow::{anyhow, Result};
use similar::{capture_diff_slices_deadline, Algorithm};

use super::FunctionDataDiffs;
use crate::{
arch::ProcessCodeResult,
diff::{
Expand Down Expand Up @@ -241,8 +242,9 @@ fn reloc_eq(
section_name_eq(left_obj, right_obj, *sl, *sr)
&& (symbol_name_matches
|| address_eq(left, right)
|| config.relax_shifted_data_diffs)
&& (left.target.kind != ObjSymbolKind::Object
|| config.function_data_diffs == FunctionDataDiffs::ValueOnly)
&& (config.function_data_diffs == FunctionDataDiffs::AddressOnly
|| left.target.kind != ObjSymbolKind::Object
|| left_obj.arch.display_ins_data(left_ins)
== left_obj.arch.display_ins_data(right_ins))
}
Expand Down

0 comments on commit c716a81

Please sign in to comment.