mirror of
https://github.com/encounter/objdiff.git
synced 2025-12-16 08:27:04 +00:00
Compare commits
23 Commits
a0371dd110
...
v0.3.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 319b1c35c0 | |||
| 634e007cbc | |||
| 6ee11ca640 | |||
| 8278d5d207 | |||
| 09bbc534bd | |||
| fa28352e08 | |||
| 2ab519d361 | |||
|
|
3406c76973 | ||
|
|
6afc535fad | ||
|
|
ec062bf5ca | ||
| 500965aacb | |||
| a8c2514377 | |||
| 4b58f69461 | |||
| cd01b6254c | |||
| bea0a0007d | |||
| ba74d63a99 | |||
|
|
20dcc50695 | ||
| c7b6ec83d7 | |||
| e2fde3dbce | |||
| 613e84ecf2 | |||
| 7219e72acf | |||
| d1d6f1101b | |||
| bc7cce7226 |
12
.github/workflows/build.yaml
vendored
12
.github/workflows/build.yaml
vendored
@@ -20,7 +20,9 @@ jobs:
|
|||||||
RUSTFLAGS: -D warnings
|
RUSTFLAGS: -D warnings
|
||||||
steps:
|
steps:
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: sudo apt-get -y install libgtk-3-dev
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get -y install libgtk-3-dev
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
- name: Setup Rust toolchain
|
- name: Setup Rust toolchain
|
||||||
@@ -58,7 +60,9 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
if: matrix.platform == 'ubuntu-latest'
|
if: matrix.platform == 'ubuntu-latest'
|
||||||
run: sudo apt-get -y install libgtk-3-dev
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get -y install libgtk-3-dev
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
- name: Setup Rust toolchain
|
- name: Setup Rust toolchain
|
||||||
@@ -89,7 +93,9 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
if: matrix.packages != ''
|
if: matrix.packages != ''
|
||||||
run: sudo apt-get -y install ${{ matrix.packages }}
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get -y install ${{ matrix.packages }}
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
- name: Setup Rust toolchain
|
- name: Setup Rust toolchain
|
||||||
|
|||||||
1389
Cargo.lock
generated
1389
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
56
Cargo.toml
56
Cargo.toml
@@ -1,8 +1,8 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "objdiff"
|
name = "objdiff"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.62"
|
rust-version = "1.65"
|
||||||
authors = ["Luke Street <luke@street.dev>"]
|
authors = ["Luke Street <luke@street.dev>"]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
repository = "https://github.com/encounter/objdiff"
|
repository = "https://github.com/encounter/objdiff"
|
||||||
@@ -16,35 +16,53 @@ publish = false
|
|||||||
lto = "thin"
|
lto = "thin"
|
||||||
strip = "debuginfo"
|
strip = "debuginfo"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
wgpu = ["eframe/wgpu"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.66"
|
anyhow = "1.0.68"
|
||||||
|
bytes = "1.3.0"
|
||||||
cfg-if = "1.0.0"
|
cfg-if = "1.0.0"
|
||||||
const_format = "0.2.30"
|
const_format = "0.2.30"
|
||||||
cwdemangle = { git = "https://github.com/encounter/cwdemangle", rev = "286f3d1d29ee2457db89043782725631845c3e4c" }
|
cwdemangle = "0.1.4"
|
||||||
eframe = { version = "0.19.0", features = ["persistence"] } # , "wgpu"
|
eframe = { version = "0.20.1", features = ["persistence"] }
|
||||||
egui = "0.19.0"
|
egui = "0.20.1"
|
||||||
egui_extras = "0.19.0"
|
egui_extras = "0.20.0"
|
||||||
flagset = "0.4.3"
|
flagset = "0.4.3"
|
||||||
log = "0.4.17"
|
log = "0.4.17"
|
||||||
memmap2 = "0.5.8"
|
memmap2 = "0.5.8"
|
||||||
notify = "5.0.0"
|
notify = "5.0.0"
|
||||||
object = { version = "0.30.0", features = ["read_core", "std", "elf"], default-features = false }
|
object = { version = "0.30.2", features = ["read_core", "std", "elf"], default-features = false }
|
||||||
ppc750cl = { git = "https://github.com/encounter/ppc750cl", rev = "aa631a33de7882c679afca89350898b87cb3ba3f" }
|
png = "0.17.7"
|
||||||
rabbitizer = { git = "https://github.com/encounter/rabbitizer-rs", rev = "10c279b2ef251c62885b1dcdcfe740b0db8e9956" }
|
ppc750cl = { git = "https://github.com/terorie/ppc750cl", rev = "9ae36eef34aa6d74e00972c7671f547a2acfd0aa" }
|
||||||
rfd = { version = "0.10.0" } # , default-features = false, features = ['xdg-portal']
|
rabbitizer = "1.5.8"
|
||||||
self_update = "0.32.0"
|
rfd = { version = "0.10.0" } #, default-features = false, features = ['xdg-portal']
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
thiserror = "1.0.37"
|
|
||||||
time = { version = "0.3.17", features = ["formatting", "local-offset"] }
|
|
||||||
toml = "0.5.9"
|
|
||||||
twox-hash = "1.6.3"
|
|
||||||
tempfile = "3.3.0"
|
tempfile = "3.3.0"
|
||||||
reqwest = "0.11.13"
|
thiserror = "1.0.38"
|
||||||
|
time = { version = "0.3.17", features = ["formatting", "local-offset"] }
|
||||||
|
toml = "0.5.11"
|
||||||
|
twox-hash = "1.6.3"
|
||||||
|
byteorder = "1.4.3"
|
||||||
|
|
||||||
|
# For Linux static binaries, use rustls
|
||||||
|
[target.'cfg(target_os = "linux")'.dependencies]
|
||||||
|
reqwest = { version = "0.11.14", default-features = false, features = ["blocking", "json", "rustls"] }
|
||||||
|
self_update = { version = "0.34.0", default-features = false, features = ["rustls"] }
|
||||||
|
|
||||||
|
# For all other platforms, use native TLS
|
||||||
|
[target.'cfg(not(target_os = "linux"))'.dependencies]
|
||||||
|
reqwest = "0.11.14"
|
||||||
|
self_update = "0.34.0"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
path-slash = "0.2.1"
|
path-slash = "0.2.1"
|
||||||
winapi = "0.3.9"
|
winapi = "0.3.9"
|
||||||
|
|
||||||
|
[target.'cfg(windows)'.build-dependencies]
|
||||||
|
winres = "0.1.12"
|
||||||
|
|
||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
exec = "0.3.1"
|
exec = "0.3.1"
|
||||||
|
|
||||||
@@ -58,5 +76,5 @@ console_error_panic_hook = "0.1.7"
|
|||||||
tracing-wasm = "0.2"
|
tracing-wasm = "0.2"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
anyhow = "1.0.66"
|
anyhow = "1.0.68"
|
||||||
vergen = { version = "7.4.3", features = ["build", "cargo", "git"], default-features = false }
|
vergen = { version = "7.5.0", features = ["build", "cargo", "git"], default-features = false }
|
||||||
|
|||||||
BIN
assets/icon.ico
Normal file
BIN
assets/icon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 36 KiB |
BIN
assets/icon.png
Normal file
BIN
assets/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
BIN
assets/icon_64.png
Normal file
BIN
assets/icon_64.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.9 KiB |
8
build.rs
8
build.rs
@@ -1,4 +1,10 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use vergen::{vergen, Config};
|
use vergen::{vergen, Config};
|
||||||
|
|
||||||
fn main() -> Result<()> { vergen(Config::default()) }
|
fn main() -> Result<()> {
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
|
winres::WindowsResource::new().set_icon("assets/icon.ico").compile()?;
|
||||||
|
}
|
||||||
|
vergen(Config::default())
|
||||||
|
}
|
||||||
|
|||||||
21
deny.toml
21
deny.toml
@@ -48,7 +48,9 @@ notice = "warn"
|
|||||||
# A list of advisory IDs to ignore. Note that ignored advisories will still
|
# A list of advisory IDs to ignore. Note that ignored advisories will still
|
||||||
# output a note when they are encountered.
|
# output a note when they are encountered.
|
||||||
ignore = [
|
ignore = [
|
||||||
#"RUSTSEC-0000-0000",
|
# git2 (build dependency)
|
||||||
|
"RUSTSEC-2023-0002",
|
||||||
|
"RUSTSEC-2023-0003",
|
||||||
]
|
]
|
||||||
# Threshold for security vulnerabilities, any vulnerability with a CVSS score
|
# Threshold for security vulnerabilities, any vulnerability with a CVSS score
|
||||||
# lower than the range specified will be ignored. Note that ignored advisories
|
# lower than the range specified will be ignored. Note that ignored advisories
|
||||||
@@ -81,6 +83,9 @@ allow = [
|
|||||||
"Unicode-DFS-2016",
|
"Unicode-DFS-2016",
|
||||||
"Zlib",
|
"Zlib",
|
||||||
"0BSD",
|
"0BSD",
|
||||||
|
"OFL-1.1",
|
||||||
|
"LicenseRef-UFL-1.0",
|
||||||
|
"OpenSSL",
|
||||||
]
|
]
|
||||||
# List of explictly disallowed licenses
|
# List of explictly disallowed licenses
|
||||||
# See https://spdx.org/licenses/ for list of possible licenses
|
# See https://spdx.org/licenses/ for list of possible licenses
|
||||||
@@ -118,22 +123,22 @@ exceptions = [
|
|||||||
# Some crates don't have (easily) machine readable licensing information,
|
# Some crates don't have (easily) machine readable licensing information,
|
||||||
# adding a clarification entry for it allows you to manually specify the
|
# adding a clarification entry for it allows you to manually specify the
|
||||||
# licensing information
|
# licensing information
|
||||||
#[[licenses.clarify]]
|
[[licenses.clarify]]
|
||||||
# The name of the crate the clarification applies to
|
# The name of the crate the clarification applies to
|
||||||
#name = "ring"
|
name = "ring"
|
||||||
# The optional version constraint for the crate
|
# The optional version constraint for the crate
|
||||||
#version = "*"
|
version = "*"
|
||||||
# The SPDX expression for the license requirements of the crate
|
# The SPDX expression for the license requirements of the crate
|
||||||
#expression = "MIT AND ISC AND OpenSSL"
|
expression = "MIT AND ISC AND OpenSSL"
|
||||||
# One or more files in the crate's source used as the "source of truth" for
|
# One or more files in the crate's source used as the "source of truth" for
|
||||||
# the license expression. If the contents match, the clarification will be used
|
# the license expression. If the contents match, the clarification will be used
|
||||||
# when running the license check, otherwise the clarification will be ignored
|
# when running the license check, otherwise the clarification will be ignored
|
||||||
# and the crate will be checked normally, which may produce warnings or errors
|
# and the crate will be checked normally, which may produce warnings or errors
|
||||||
# depending on the rest of your configuration
|
# depending on the rest of your configuration
|
||||||
#license-files = [
|
license-files = [
|
||||||
# Each entry is a crate relative path, and the (opaque) hash of its contents
|
# Each entry is a crate relative path, and the (opaque) hash of its contents
|
||||||
#{ path = "LICENSE", hash = 0xbd0eed23 }
|
{ path = "LICENSE", hash = 0xbd0eed23 }
|
||||||
#]
|
]
|
||||||
|
|
||||||
[licenses.private]
|
[licenses.private]
|
||||||
# If true, ignores workspace crates that aren't published, or are only
|
# If true, ignores workspace crates that aren't published, or are only
|
||||||
|
|||||||
30
src/app.rs
30
src/app.rs
@@ -58,7 +58,7 @@ const DEFAULT_COLOR_ROTATION: [Color32; 9] = [
|
|||||||
Color32::from_rgb(255, 192, 203),
|
Color32::from_rgb(255, 192, 203),
|
||||||
Color32::from_rgb(0, 0, 255),
|
Color32::from_rgb(0, 0, 255),
|
||||||
Color32::from_rgb(0, 255, 0),
|
Color32::from_rgb(0, 255, 0),
|
||||||
Color32::from_rgb(128, 128, 128),
|
Color32::from_rgb(213, 138, 138),
|
||||||
];
|
];
|
||||||
|
|
||||||
#[derive(serde::Deserialize, serde::Serialize)]
|
#[derive(serde::Deserialize, serde::Serialize)]
|
||||||
@@ -67,18 +67,25 @@ pub struct ViewConfig {
|
|||||||
pub ui_font: FontId,
|
pub ui_font: FontId,
|
||||||
pub code_font: FontId,
|
pub code_font: FontId,
|
||||||
pub diff_colors: Vec<Color32>,
|
pub diff_colors: Vec<Color32>,
|
||||||
|
pub reverse_fn_order: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ViewConfig {
|
impl Default for ViewConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
ui_font: FontId { size: 14.0, family: FontFamily::Proportional },
|
ui_font: FontId { size: 12.0, family: FontFamily::Proportional },
|
||||||
code_font: FontId { size: 14.0, family: FontFamily::Monospace },
|
code_font: FontId { size: 14.0, family: FontFamily::Monospace },
|
||||||
diff_colors: DEFAULT_COLOR_ROTATION.to_vec(),
|
diff_colors: DEFAULT_COLOR_ROTATION.to_vec(),
|
||||||
|
reverse_fn_order: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct SymbolReference {
|
||||||
|
pub symbol_name: String,
|
||||||
|
pub section_name: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(serde::Deserialize, serde::Serialize)]
|
#[derive(serde::Deserialize, serde::Serialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct ViewState {
|
pub struct ViewState {
|
||||||
@@ -89,7 +96,7 @@ pub struct ViewState {
|
|||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub highlighted_symbol: Option<String>,
|
pub highlighted_symbol: Option<String>,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub selected_symbol: Option<String>,
|
pub selected_symbol: Option<SymbolReference>,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub current_view: View,
|
pub current_view: View,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
@@ -108,7 +115,6 @@ pub struct ViewState {
|
|||||||
pub check_update: Option<Box<CheckUpdateResult>>,
|
pub check_update: Option<Box<CheckUpdateResult>>,
|
||||||
// Config
|
// Config
|
||||||
pub diff_kind: DiffKind,
|
pub diff_kind: DiffKind,
|
||||||
pub reverse_fn_order: bool,
|
|
||||||
pub view_config: ViewConfig,
|
pub view_config: ViewConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +134,6 @@ impl Default for ViewState {
|
|||||||
utc_offset: UtcOffset::UTC,
|
utc_offset: UtcOffset::UTC,
|
||||||
check_update: None,
|
check_update: None,
|
||||||
diff_kind: Default::default(),
|
diff_kind: Default::default(),
|
||||||
reverse_fn_order: false,
|
|
||||||
view_config: Default::default(),
|
view_config: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -393,7 +398,9 @@ impl eframe::App for App {
|
|||||||
|
|
||||||
fn post_rendering(&mut self, _window_size_px: [u32; 2], _frame: &eframe::Frame) {
|
fn post_rendering(&mut self, _window_size_px: [u32; 2], _frame: &eframe::Frame) {
|
||||||
for job in &mut self.view_state.jobs {
|
for job in &mut self.view_state.jobs {
|
||||||
if let Some(handle) = &job.handle {
|
let Some(handle) = &job.handle else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
if !handle.is_finished() {
|
if !handle.is_finished() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -411,14 +418,8 @@ impl eframe::App for App {
|
|||||||
}
|
}
|
||||||
JobResult::BinDiff(state) => {
|
JobResult::BinDiff(state) => {
|
||||||
self.view_state.build = Some(Box::new(ObjDiffResult {
|
self.view_state.build = Some(Box::new(ObjDiffResult {
|
||||||
first_status: BuildStatus {
|
first_status: BuildStatus { success: true, log: "".to_string() },
|
||||||
success: true,
|
second_status: BuildStatus { success: true, log: "".to_string() },
|
||||||
log: "".to_string(),
|
|
||||||
},
|
|
||||||
second_status: BuildStatus {
|
|
||||||
success: true,
|
|
||||||
log: "".to_string(),
|
|
||||||
},
|
|
||||||
first_obj: Some(state.first_obj),
|
first_obj: Some(state.first_obj),
|
||||||
second_obj: Some(state.second_obj),
|
second_obj: Some(state.second_obj),
|
||||||
time: OffsetDateTime::now_utc(),
|
time: OffsetDateTime::now_utc(),
|
||||||
@@ -459,7 +460,6 @@ impl eframe::App for App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if self.view_state.jobs.iter().any(|v| v.should_remove) {
|
if self.view_state.jobs.iter().any(|v| v.should_remove) {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
while i < self.view_state.jobs.len() {
|
while i < self.view_state.jobs.len() {
|
||||||
|
|||||||
51
src/diff.rs
51
src/diff.rs
@@ -17,14 +17,19 @@ fn no_diff_code(
|
|||||||
data: &[u8],
|
data: &[u8],
|
||||||
symbol: &mut ObjSymbol,
|
symbol: &mut ObjSymbol,
|
||||||
relocs: &[ObjReloc],
|
relocs: &[ObjReloc],
|
||||||
|
line_info: &Option<BTreeMap<u32, u32>>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let code =
|
let code =
|
||||||
&data[symbol.section_address as usize..(symbol.section_address + symbol.size) as usize];
|
&data[symbol.section_address as usize..(symbol.section_address + symbol.size) as usize];
|
||||||
let (_, ins) = match arch {
|
let (_, ins) = match arch {
|
||||||
ObjArchitecture::PowerPc => ppc::process_code(code, symbol.address, relocs)?,
|
ObjArchitecture::PowerPc => ppc::process_code(code, symbol.address, relocs, line_info)?,
|
||||||
ObjArchitecture::Mips => {
|
ObjArchitecture::Mips => mips::process_code(
|
||||||
mips::process_code(code, symbol.address, symbol.address + symbol.size, relocs)?
|
code,
|
||||||
}
|
symbol.address,
|
||||||
|
symbol.address + symbol.size,
|
||||||
|
relocs,
|
||||||
|
line_info,
|
||||||
|
)?,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut diff = Vec::<ObjInsDiff>::new();
|
let mut diff = Vec::<ObjInsDiff>::new();
|
||||||
@@ -36,6 +41,7 @@ fn no_diff_code(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn diff_code(
|
pub fn diff_code(
|
||||||
arch: ObjArchitecture,
|
arch: ObjArchitecture,
|
||||||
left_data: &[u8],
|
left_data: &[u8],
|
||||||
@@ -44,6 +50,8 @@ pub fn diff_code(
|
|||||||
right_symbol: &mut ObjSymbol,
|
right_symbol: &mut ObjSymbol,
|
||||||
left_relocs: &[ObjReloc],
|
left_relocs: &[ObjReloc],
|
||||||
right_relocs: &[ObjReloc],
|
right_relocs: &[ObjReloc],
|
||||||
|
left_line_info: &Option<BTreeMap<u32, u32>>,
|
||||||
|
right_line_info: &Option<BTreeMap<u32, u32>>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let left_code = &left_data[left_symbol.section_address as usize
|
let left_code = &left_data[left_symbol.section_address as usize
|
||||||
..(left_symbol.section_address + left_symbol.size) as usize];
|
..(left_symbol.section_address + left_symbol.size) as usize];
|
||||||
@@ -51,8 +59,8 @@ pub fn diff_code(
|
|||||||
..(right_symbol.section_address + right_symbol.size) as usize];
|
..(right_symbol.section_address + right_symbol.size) as usize];
|
||||||
let ((left_ops, left_insts), (right_ops, right_insts)) = match arch {
|
let ((left_ops, left_insts), (right_ops, right_insts)) = match arch {
|
||||||
ObjArchitecture::PowerPc => (
|
ObjArchitecture::PowerPc => (
|
||||||
ppc::process_code(left_code, left_symbol.address, left_relocs)?,
|
ppc::process_code(left_code, left_symbol.address, left_relocs, left_line_info)?,
|
||||||
ppc::process_code(right_code, right_symbol.address, right_relocs)?,
|
ppc::process_code(right_code, right_symbol.address, right_relocs, right_line_info)?,
|
||||||
),
|
),
|
||||||
ObjArchitecture::Mips => (
|
ObjArchitecture::Mips => (
|
||||||
mips::process_code(
|
mips::process_code(
|
||||||
@@ -60,12 +68,14 @@ pub fn diff_code(
|
|||||||
left_symbol.address,
|
left_symbol.address,
|
||||||
left_symbol.address + left_symbol.size,
|
left_symbol.address + left_symbol.size,
|
||||||
left_relocs,
|
left_relocs,
|
||||||
|
left_line_info,
|
||||||
)?,
|
)?,
|
||||||
mips::process_code(
|
mips::process_code(
|
||||||
right_code,
|
right_code,
|
||||||
right_symbol.address,
|
right_symbol.address,
|
||||||
left_symbol.address + left_symbol.size,
|
left_symbol.address + left_symbol.size,
|
||||||
right_relocs,
|
right_relocs,
|
||||||
|
right_line_info,
|
||||||
)?,
|
)?,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
@@ -211,10 +221,13 @@ fn address_eq(left: &ObjSymbol, right: &ObjSymbol) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn reloc_eq(left_reloc: Option<&ObjReloc>, right_reloc: Option<&ObjReloc>) -> bool {
|
fn reloc_eq(left_reloc: Option<&ObjReloc>, right_reloc: Option<&ObjReloc>) -> bool {
|
||||||
if let (Some(left), Some(right)) = (left_reloc, right_reloc) {
|
let (Some(left), Some(right)) = (left_reloc, right_reloc) else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
if left.kind != right.kind {
|
if left.kind != right.kind {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let name_matches = left.target.name == right.target.name;
|
let name_matches = left.target.name == right.target.name;
|
||||||
match (&left.target_section, &right.target_section) {
|
match (&left.target_section, &right.target_section) {
|
||||||
(Some(sl), Some(sr)) => {
|
(Some(sl), Some(sr)) => {
|
||||||
@@ -228,9 +241,6 @@ fn reloc_eq(left_reloc: Option<&ObjReloc>, right_reloc: Option<&ObjReloc>) -> bo
|
|||||||
}
|
}
|
||||||
(None, None) => name_matches,
|
(None, None) => name_matches,
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn arg_eq(
|
fn arg_eq(
|
||||||
@@ -258,8 +268,8 @@ fn arg_eq(
|
|||||||
right_diff.ins.as_ref().and_then(|i| i.reloc.as_ref()),
|
right_diff.ins.as_ref().and_then(|i| i.reloc.as_ref()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
ObjInsArg::MipsArg(ls) => {
|
ObjInsArg::MipsArg(ls) | ObjInsArg::MipsArgWithBase(ls) => {
|
||||||
matches!(right, ObjInsArg::MipsArg(rs) if ls == rs)
|
matches!(right, ObjInsArg::MipsArg(rs) | ObjInsArg::MipsArgWithBase(rs) if ls == rs)
|
||||||
}
|
}
|
||||||
ObjInsArg::BranchOffset(_) => {
|
ObjInsArg::BranchOffset(_) => {
|
||||||
// Compare dest instruction idx after diffing
|
// Compare dest instruction idx after diffing
|
||||||
@@ -314,7 +324,7 @@ fn compare_ins(
|
|||||||
let a_str = match a {
|
let a_str = match a {
|
||||||
ObjInsArg::PpcArg(arg) => format!("{arg}"),
|
ObjInsArg::PpcArg(arg) => format!("{arg}"),
|
||||||
ObjInsArg::Reloc | ObjInsArg::RelocWithBase => String::new(),
|
ObjInsArg::Reloc | ObjInsArg::RelocWithBase => String::new(),
|
||||||
ObjInsArg::MipsArg(str) => str.clone(),
|
ObjInsArg::MipsArg(str) | ObjInsArg::MipsArgWithBase(str) => str.clone(),
|
||||||
ObjInsArg::BranchOffset(arg) => format!("{arg}"),
|
ObjInsArg::BranchOffset(arg) => format!("{arg}"),
|
||||||
};
|
};
|
||||||
let a_diff = if let Some(idx) = state.left_args_idx.get(&a_str) {
|
let a_diff = if let Some(idx) = state.left_args_idx.get(&a_str) {
|
||||||
@@ -328,7 +338,7 @@ fn compare_ins(
|
|||||||
let b_str = match b {
|
let b_str = match b {
|
||||||
ObjInsArg::PpcArg(arg) => format!("{arg}"),
|
ObjInsArg::PpcArg(arg) => format!("{arg}"),
|
||||||
ObjInsArg::Reloc | ObjInsArg::RelocWithBase => String::new(),
|
ObjInsArg::Reloc | ObjInsArg::RelocWithBase => String::new(),
|
||||||
ObjInsArg::MipsArg(str) => str.clone(),
|
ObjInsArg::MipsArg(str) | ObjInsArg::MipsArgWithBase(str) => str.clone(),
|
||||||
ObjInsArg::BranchOffset(arg) => format!("{arg}"),
|
ObjInsArg::BranchOffset(arg) => format!("{arg}"),
|
||||||
};
|
};
|
||||||
let b_diff = if let Some(idx) = state.right_args_idx.get(&b_str) {
|
let b_diff = if let Some(idx) = state.right_args_idx.get(&b_str) {
|
||||||
@@ -353,17 +363,15 @@ fn compare_ins(
|
|||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_section<'a>(obj: &'a mut ObjInfo, name: &str) -> Option<&'a mut ObjSection> {
|
|
||||||
obj.sections.iter_mut().find(|s| s.name == name)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_symbol<'a>(symbols: &'a mut [ObjSymbol], name: &str) -> Option<&'a mut ObjSymbol> {
|
fn find_symbol<'a>(symbols: &'a mut [ObjSymbol], name: &str) -> Option<&'a mut ObjSymbol> {
|
||||||
symbols.iter_mut().find(|s| s.name == name)
|
symbols.iter_mut().find(|s| s.name == name)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn diff_objs(left: &mut ObjInfo, right: &mut ObjInfo, _diff_config: &DiffConfig) -> Result<()> {
|
pub fn diff_objs(left: &mut ObjInfo, right: &mut ObjInfo, _diff_config: &DiffConfig) -> Result<()> {
|
||||||
for left_section in &mut left.sections {
|
for left_section in &mut left.sections {
|
||||||
if let Some(right_section) = find_section(right, &left_section.name) {
|
let Some(right_section) = right.sections.iter_mut().find(|s| s.name == left_section.name) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
if left_section.kind == ObjSectionKind::Code {
|
if left_section.kind == ObjSectionKind::Code {
|
||||||
for left_symbol in &mut left_section.symbols {
|
for left_symbol in &mut left_section.symbols {
|
||||||
if let Some(right_symbol) =
|
if let Some(right_symbol) =
|
||||||
@@ -379,6 +387,8 @@ pub fn diff_objs(left: &mut ObjInfo, right: &mut ObjInfo, _diff_config: &DiffCon
|
|||||||
right_symbol,
|
right_symbol,
|
||||||
&left_section.relocations,
|
&left_section.relocations,
|
||||||
&right_section.relocations,
|
&right_section.relocations,
|
||||||
|
&left.line_info,
|
||||||
|
&right.line_info,
|
||||||
)?;
|
)?;
|
||||||
} else {
|
} else {
|
||||||
no_diff_code(
|
no_diff_code(
|
||||||
@@ -386,6 +396,7 @@ pub fn diff_objs(left: &mut ObjInfo, right: &mut ObjInfo, _diff_config: &DiffCon
|
|||||||
&left_section.data,
|
&left_section.data,
|
||||||
left_symbol,
|
left_symbol,
|
||||||
&left_section.relocations,
|
&left_section.relocations,
|
||||||
|
&left.line_info,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -396,6 +407,7 @@ pub fn diff_objs(left: &mut ObjInfo, right: &mut ObjInfo, _diff_config: &DiffCon
|
|||||||
&right_section.data,
|
&right_section.data,
|
||||||
right_symbol,
|
right_symbol,
|
||||||
&right_section.relocations,
|
&right_section.relocations,
|
||||||
|
&left.line_info,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -406,7 +418,6 @@ pub fn diff_objs(left: &mut ObjInfo, right: &mut ObjInfo, _diff_config: &DiffCon
|
|||||||
diff_bss_symbols(&mut left_section.symbols, &mut right_section.symbols)?;
|
diff_bss_symbols(&mut left_section.symbols, &mut right_section.symbols)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
diff_bss_symbols(&mut left.common, &mut right.common)?;
|
diff_bss_symbols(&mut left.common, &mut right.common)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,25 +40,15 @@ pub struct LevEditOp {
|
|||||||
pub second_start: usize, /* destination position */
|
pub second_start: usize, /* destination position */
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
|
||||||
pub struct LevMatchingBlock {
|
|
||||||
pub first_start: usize,
|
|
||||||
pub second_start: usize,
|
|
||||||
pub len: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn editops_find<T>(query: &[T], choice: &[T]) -> Vec<LevEditOp>
|
pub fn editops_find<T>(query: &[T], choice: &[T]) -> Vec<LevEditOp>
|
||||||
where T: PartialEq {
|
where T: PartialEq {
|
||||||
let string_affix = Affix::find(query, choice);
|
let Affix { prefix_len, suffix_len } = Affix::find(query, choice);
|
||||||
|
|
||||||
let first_string_len = string_affix.first_string_len;
|
let first_string = &query[prefix_len..query.len() - suffix_len];
|
||||||
let second_string_len = string_affix.second_string_len;
|
let second_string = &choice[prefix_len..choice.len() - suffix_len];
|
||||||
let prefix_len = string_affix.prefix_len;
|
|
||||||
let first_string = &query[prefix_len..prefix_len + first_string_len];
|
|
||||||
let second_string = &choice[prefix_len..prefix_len + second_string_len];
|
|
||||||
|
|
||||||
let matrix_columns = first_string_len + 1;
|
let matrix_columns = first_string.len() + 1;
|
||||||
let matrix_rows = second_string_len + 1;
|
let matrix_rows = second_string.len() + 1;
|
||||||
|
|
||||||
// TODO maybe use an actual matrix for readability
|
// TODO maybe use an actual matrix for readability
|
||||||
let mut cache_matrix: Vec<usize> = vec![0; matrix_rows * matrix_columns];
|
let mut cache_matrix: Vec<usize> = vec![0; matrix_rows * matrix_columns];
|
||||||
@@ -186,73 +176,20 @@ where
|
|||||||
|
|
||||||
pub struct Affix {
|
pub struct Affix {
|
||||||
pub prefix_len: usize,
|
pub prefix_len: usize,
|
||||||
pub first_string_len: usize,
|
pub suffix_len: usize,
|
||||||
pub second_string_len: usize,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Affix {
|
impl Affix {
|
||||||
pub fn find<T>(first_string: &[T], second_string: &[T]) -> Affix
|
pub fn find<T>(s1: &[T], s2: &[T]) -> Affix
|
||||||
where T: PartialEq {
|
where T: PartialEq {
|
||||||
// remove common prefix and suffix (linear vs square runtime for levensthein)
|
let prefix_len = s1.iter().zip(s2.iter()).take_while(|t| t.0 == t.1).count();
|
||||||
let mut first_iter = first_string.iter();
|
let suffix_len = s1[prefix_len..]
|
||||||
let mut second_iter = second_string.iter();
|
.iter()
|
||||||
|
.rev()
|
||||||
|
.zip(s2[prefix_len..].iter().rev())
|
||||||
|
.take_while(|t| t.0 == t.1)
|
||||||
|
.count();
|
||||||
|
|
||||||
let mut limit_start = 0;
|
Affix { prefix_len, suffix_len }
|
||||||
|
|
||||||
let mut first_iter_char = first_iter.next();
|
|
||||||
let mut second_iter_char = second_iter.next();
|
|
||||||
while first_iter_char.is_some() && first_iter_char == second_iter_char {
|
|
||||||
first_iter_char = first_iter.next();
|
|
||||||
second_iter_char = second_iter.next();
|
|
||||||
limit_start += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// save char since the iterator was already consumed
|
|
||||||
let first_iter_cache = first_iter_char;
|
|
||||||
let second_iter_cache = second_iter_char;
|
|
||||||
|
|
||||||
if second_iter_char.is_some() && first_iter_char.is_some() {
|
|
||||||
first_iter_char = first_iter.next_back();
|
|
||||||
second_iter_char = second_iter.next_back();
|
|
||||||
while first_iter_char.is_some() && first_iter_char == second_iter_char {
|
|
||||||
first_iter_char = first_iter.next_back();
|
|
||||||
second_iter_char = second_iter.next_back();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match (first_iter_char, second_iter_char) {
|
|
||||||
(None, None) => {
|
|
||||||
// characters might not match even though they were consumed
|
|
||||||
let remaining_char = (first_iter_cache != second_iter_cache) as usize;
|
|
||||||
Affix {
|
|
||||||
prefix_len: limit_start,
|
|
||||||
first_string_len: remaining_char,
|
|
||||||
second_string_len: remaining_char,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
(None, _) => {
|
|
||||||
let remaining_char =
|
|
||||||
(first_iter_cache.is_some() && first_iter_cache != second_iter_char) as usize;
|
|
||||||
Affix {
|
|
||||||
prefix_len: limit_start,
|
|
||||||
first_string_len: remaining_char,
|
|
||||||
second_string_len: second_iter.count() + 1 + remaining_char,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
(_, None) => {
|
|
||||||
let remaining_char =
|
|
||||||
(second_iter_cache.is_some() && second_iter_cache != first_iter_char) as usize;
|
|
||||||
Affix {
|
|
||||||
prefix_len: limit_start,
|
|
||||||
first_string_len: first_iter.count() + 1 + remaining_char,
|
|
||||||
second_string_len: remaining_char,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => Affix {
|
|
||||||
prefix_len: limit_start,
|
|
||||||
first_string_len: first_iter.count() + 2,
|
|
||||||
second_string_len: second_iter.count() + 2,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use std::{
|
use std::{
|
||||||
env::{current_dir, current_exe},
|
env::{current_dir, current_exe},
|
||||||
fs,
|
|
||||||
fs::File,
|
fs::File,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
sync::mpsc::Receiver,
|
sync::mpsc::Receiver,
|
||||||
@@ -44,7 +43,7 @@ fn run_update(status: &Status, cancel: Receiver<()>) -> Result<Box<UpdateResult>
|
|||||||
.to_dest(&target_file)?;
|
.to_dest(&target_file)?;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
use std::os::unix::fs::PermissionsExt;
|
use std::{fs, os::unix::fs::PermissionsExt};
|
||||||
let mut perms = fs::metadata(&target_file)?.permissions();
|
let mut perms = fs::metadata(&target_file)?.permissions();
|
||||||
perms.set_mode(0o755);
|
perms.set_mode(0o755);
|
||||||
fs::set_permissions(&target_file, perms)?;
|
fs::set_permissions(&target_file, perms)?;
|
||||||
|
|||||||
33
src/main.rs
33
src/main.rs
@@ -3,9 +3,27 @@
|
|||||||
|
|
||||||
use std::{path::PathBuf, rc::Rc, sync::Mutex};
|
use std::{path::PathBuf, rc::Rc, sync::Mutex};
|
||||||
|
|
||||||
|
use anyhow::{Error, Result};
|
||||||
use cfg_if::cfg_if;
|
use cfg_if::cfg_if;
|
||||||
|
use eframe::IconData;
|
||||||
use time::UtcOffset;
|
use time::UtcOffset;
|
||||||
|
|
||||||
|
fn load_icon() -> Result<IconData> {
|
||||||
|
use bytes::Buf;
|
||||||
|
let decoder = png::Decoder::new(include_bytes!("../assets/icon_64.png").reader());
|
||||||
|
let mut reader = decoder.read_info()?;
|
||||||
|
let mut buf = vec![0; reader.output_buffer_size()];
|
||||||
|
let info = reader.next_frame(&mut buf)?;
|
||||||
|
if info.bit_depth != png::BitDepth::Eight {
|
||||||
|
return Err(Error::msg("Invalid bit depth"));
|
||||||
|
}
|
||||||
|
if info.color_type != png::ColorType::Rgba {
|
||||||
|
return Err(Error::msg("Invalid color type"));
|
||||||
|
}
|
||||||
|
buf.truncate(info.buffer_size());
|
||||||
|
Ok(IconData { rgba: buf, width: info.width, height: info.height })
|
||||||
|
}
|
||||||
|
|
||||||
// When compiling natively:
|
// When compiling natively:
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
fn main() {
|
fn main() {
|
||||||
@@ -19,8 +37,19 @@ fn main() {
|
|||||||
|
|
||||||
let exec_path: Rc<Mutex<Option<PathBuf>>> = Rc::new(Mutex::new(None));
|
let exec_path: Rc<Mutex<Option<PathBuf>>> = Rc::new(Mutex::new(None));
|
||||||
let exec_path_clone = exec_path.clone();
|
let exec_path_clone = exec_path.clone();
|
||||||
let native_options = eframe::NativeOptions::default();
|
let mut native_options = eframe::NativeOptions::default();
|
||||||
// native_options.renderer = eframe::Renderer::Wgpu;
|
match load_icon() {
|
||||||
|
Ok(data) => {
|
||||||
|
native_options.icon_data = Some(data);
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
log::warn!("Failed to load application icon: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(feature = "wgpu")]
|
||||||
|
{
|
||||||
|
native_options.renderer = eframe::Renderer::Wgpu;
|
||||||
|
}
|
||||||
eframe::run_native(
|
eframe::run_native(
|
||||||
"objdiff",
|
"objdiff",
|
||||||
native_options,
|
native_options,
|
||||||
|
|||||||
133
src/obj/elf.rs
133
src/obj/elf.rs
@@ -1,15 +1,12 @@
|
|||||||
use std::{fs, path::Path};
|
use std::{collections::BTreeMap, fs, io::Cursor, path::Path};
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{anyhow, bail, Context, Result};
|
||||||
|
use byteorder::{BigEndian, ReadBytesExt};
|
||||||
use cwdemangle::demangle;
|
use cwdemangle::demangle;
|
||||||
use flagset::Flags;
|
use flagset::Flags;
|
||||||
use object::{
|
use object::{
|
||||||
elf::{
|
elf, Architecture, File, Object, ObjectSection, ObjectSymbol, RelocationKind, RelocationTarget,
|
||||||
R_MIPS_26, R_MIPS_HI16, R_MIPS_LO16, R_PPC_ADDR16_HA, R_PPC_ADDR16_HI, R_PPC_ADDR16_LO,
|
SectionIndex, SectionKind, Symbol, SymbolKind, SymbolSection,
|
||||||
R_PPC_EMB_SDA21, R_PPC_REL14, R_PPC_REL24,
|
|
||||||
},
|
|
||||||
Architecture, File, Object, ObjectSection, ObjectSymbol, RelocationKind, RelocationTarget,
|
|
||||||
SectionKind, Symbol, SymbolKind, SymbolSection,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::obj::{
|
use crate::obj::{
|
||||||
@@ -17,12 +14,12 @@ use crate::obj::{
|
|||||||
ObjSymbolFlagSet, ObjSymbolFlags,
|
ObjSymbolFlagSet, ObjSymbolFlags,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn to_obj_section_kind(kind: SectionKind) -> ObjSectionKind {
|
fn to_obj_section_kind(kind: SectionKind) -> Option<ObjSectionKind> {
|
||||||
match kind {
|
match kind {
|
||||||
SectionKind::Text => ObjSectionKind::Code,
|
SectionKind::Text => Some(ObjSectionKind::Code),
|
||||||
SectionKind::Data | SectionKind::ReadOnlyData => ObjSectionKind::Data,
|
SectionKind::Data | SectionKind::ReadOnlyData => Some(ObjSectionKind::Data),
|
||||||
SectionKind::UninitializedData => ObjSectionKind::Bss,
|
SectionKind::UninitializedData => Some(ObjSectionKind::Bss),
|
||||||
_ => panic!("Unhandled section kind {kind:?}"),
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,18 +70,14 @@ fn filter_sections(obj_file: &File<'_>) -> Result<Vec<ObjSection>> {
|
|||||||
if section.size() == 0 {
|
if section.size() == 0 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if section.kind() != SectionKind::Text
|
let Some(kind) = to_obj_section_kind(section.kind()) else {
|
||||||
&& section.kind() != SectionKind::Data
|
|
||||||
&& section.kind() != SectionKind::ReadOnlyData
|
|
||||||
&& section.kind() != SectionKind::UninitializedData
|
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
};
|
||||||
let name = section.name().context("Failed to process section name")?;
|
let name = section.name().context("Failed to process section name")?;
|
||||||
let data = section.uncompressed_data().context("Failed to read section data")?;
|
let data = section.uncompressed_data().context("Failed to read section data")?;
|
||||||
result.push(ObjSection {
|
result.push(ObjSection {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
kind: to_obj_section_kind(section.kind()),
|
kind,
|
||||||
address: section.address(),
|
address: section.address(),
|
||||||
size: section.size(),
|
size: section.size(),
|
||||||
data: data.to_vec(),
|
data: data.to_vec(),
|
||||||
@@ -192,9 +185,7 @@ fn relocations_by_section(
|
|||||||
obj_file: &File<'_>,
|
obj_file: &File<'_>,
|
||||||
section: &mut ObjSection,
|
section: &mut ObjSection,
|
||||||
) -> Result<Vec<ObjReloc>> {
|
) -> Result<Vec<ObjReloc>> {
|
||||||
let obj_section = obj_file
|
let obj_section = obj_file.section_by_index(SectionIndex(section.index))?;
|
||||||
.section_by_name(§ion.name)
|
|
||||||
.ok_or_else(|| anyhow::Error::msg("Failed to locate section"))?;
|
|
||||||
let mut relocations = Vec::<ObjReloc>::new();
|
let mut relocations = Vec::<ObjReloc>::new();
|
||||||
for (address, reloc) in obj_section.relocations() {
|
for (address, reloc) in obj_section.relocations() {
|
||||||
let symbol = match reloc.target() {
|
let symbol = match reloc.target() {
|
||||||
@@ -212,12 +203,12 @@ fn relocations_by_section(
|
|||||||
RelocationKind::Absolute => ObjRelocKind::Absolute,
|
RelocationKind::Absolute => ObjRelocKind::Absolute,
|
||||||
RelocationKind::Elf(kind) => match arch {
|
RelocationKind::Elf(kind) => match arch {
|
||||||
ObjArchitecture::PowerPc => match kind {
|
ObjArchitecture::PowerPc => match kind {
|
||||||
R_PPC_ADDR16_LO => ObjRelocKind::PpcAddr16Lo,
|
elf::R_PPC_ADDR16_LO => ObjRelocKind::PpcAddr16Lo,
|
||||||
R_PPC_ADDR16_HI => ObjRelocKind::PpcAddr16Hi,
|
elf::R_PPC_ADDR16_HI => ObjRelocKind::PpcAddr16Hi,
|
||||||
R_PPC_ADDR16_HA => ObjRelocKind::PpcAddr16Ha,
|
elf::R_PPC_ADDR16_HA => ObjRelocKind::PpcAddr16Ha,
|
||||||
R_PPC_REL24 => ObjRelocKind::PpcRel24,
|
elf::R_PPC_REL24 => ObjRelocKind::PpcRel24,
|
||||||
R_PPC_REL14 => ObjRelocKind::PpcRel14,
|
elf::R_PPC_REL14 => ObjRelocKind::PpcRel14,
|
||||||
R_PPC_EMB_SDA21 => ObjRelocKind::PpcEmbSda21,
|
elf::R_PPC_EMB_SDA21 => ObjRelocKind::PpcEmbSda21,
|
||||||
_ => {
|
_ => {
|
||||||
return Err(anyhow::Error::msg(format!(
|
return Err(anyhow::Error::msg(format!(
|
||||||
"Unhandled PPC relocation type: {kind}"
|
"Unhandled PPC relocation type: {kind}"
|
||||||
@@ -225,14 +216,14 @@ fn relocations_by_section(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
ObjArchitecture::Mips => match kind {
|
ObjArchitecture::Mips => match kind {
|
||||||
R_MIPS_26 => ObjRelocKind::Mips26,
|
elf::R_MIPS_26 => ObjRelocKind::Mips26,
|
||||||
R_MIPS_HI16 => ObjRelocKind::MipsHi16,
|
elf::R_MIPS_HI16 => ObjRelocKind::MipsHi16,
|
||||||
R_MIPS_LO16 => ObjRelocKind::MipsLo16,
|
elf::R_MIPS_LO16 => ObjRelocKind::MipsLo16,
|
||||||
_ => {
|
elf::R_MIPS_GOT16 => ObjRelocKind::MipsGot16,
|
||||||
return Err(anyhow::Error::msg(format!(
|
elf::R_MIPS_CALL16 => ObjRelocKind::MipsCall16,
|
||||||
"Unhandled MIPS relocation type: {kind}"
|
elf::R_MIPS_GPREL16 => ObjRelocKind::MipsGpRel16,
|
||||||
)))
|
elf::R_MIPS_GPREL32 => ObjRelocKind::MipsGpRel32,
|
||||||
}
|
_ => bail!("Unhandled MIPS relocation type: {kind}"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
@@ -249,43 +240,68 @@ fn relocations_by_section(
|
|||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
// println!("Reloc: {:?}, symbol: {:?}", reloc, symbol);
|
|
||||||
let target = match symbol.kind() {
|
|
||||||
SymbolKind::Text | SymbolKind::Data | SymbolKind::Unknown => {
|
|
||||||
to_obj_symbol(obj_file, &symbol, reloc.addend())
|
|
||||||
}
|
|
||||||
SymbolKind::Section => {
|
|
||||||
let addend = if reloc.has_implicit_addend() {
|
let addend = if reloc.has_implicit_addend() {
|
||||||
let addend = u32::from_be_bytes(
|
let addend = u32::from_be_bytes(
|
||||||
section.data[address as usize..address as usize + 4].try_into()?,
|
section.data[address as usize..address as usize + 4].try_into()?,
|
||||||
);
|
);
|
||||||
match kind {
|
match kind {
|
||||||
ObjRelocKind::Absolute => addend,
|
ObjRelocKind::Absolute => addend as i64,
|
||||||
ObjRelocKind::MipsHi16 | ObjRelocKind::MipsLo16 => addend & 0x0000FFFF,
|
ObjRelocKind::MipsHi16 => ((addend & 0x0000FFFF) << 16) as i32 as i64,
|
||||||
ObjRelocKind::Mips26 => (addend & 0x03FFFFFF) * 4,
|
ObjRelocKind::MipsLo16
|
||||||
_ => todo!(),
|
| ObjRelocKind::MipsGot16
|
||||||
|
| ObjRelocKind::MipsCall16
|
||||||
|
| ObjRelocKind::MipsGpRel16 => (addend & 0x0000FFFF) as i16 as i64,
|
||||||
|
ObjRelocKind::MipsGpRel32 => addend as i32 as i64,
|
||||||
|
ObjRelocKind::Mips26 => ((addend & 0x03FFFFFF) << 2) as i64,
|
||||||
|
_ => bail!("Unsupported implicit relocation {kind:?}"),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let addend = reloc.addend();
|
reloc.addend()
|
||||||
if addend < 0 {
|
|
||||||
return Err(anyhow::Error::msg(format!(
|
|
||||||
"Negative addend in section reloc: {addend}"
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
addend as u32
|
|
||||||
};
|
};
|
||||||
|
// println!("Reloc: {reloc:?}, symbol: {symbol:?}, addend: {addend:#X}");
|
||||||
|
let target = match symbol.kind() {
|
||||||
|
SymbolKind::Text | SymbolKind::Data | SymbolKind::Label | SymbolKind::Unknown => {
|
||||||
|
to_obj_symbol(obj_file, &symbol, addend)
|
||||||
|
}
|
||||||
|
SymbolKind::Section => {
|
||||||
|
if addend < 0 {
|
||||||
|
return Err(anyhow::Error::msg(format!("Negative addend in reloc: {addend}")));
|
||||||
|
}
|
||||||
find_section_symbol(obj_file, &symbol, addend as u64)
|
find_section_symbol(obj_file, &symbol, addend as u64)
|
||||||
}
|
}
|
||||||
_ => Err(anyhow::Error::msg(format!(
|
kind => Err(anyhow!("Unhandled relocation symbol type {kind:?}")),
|
||||||
"Unhandled relocation symbol type {:?}",
|
|
||||||
symbol.kind()
|
|
||||||
))),
|
|
||||||
}?;
|
}?;
|
||||||
relocations.push(ObjReloc { kind, address, target, target_section });
|
relocations.push(ObjReloc { kind, address, target, target_section });
|
||||||
}
|
}
|
||||||
Ok(relocations)
|
Ok(relocations)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn line_info(obj_file: &File<'_>) -> Result<Option<BTreeMap<u32, u32>>> {
|
||||||
|
if let Some(section) = obj_file.section_by_name(".line") {
|
||||||
|
if section.size() == 0 {
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
let data = section.uncompressed_data()?;
|
||||||
|
let mut reader = Cursor::new(data.as_ref());
|
||||||
|
|
||||||
|
let mut map = BTreeMap::new();
|
||||||
|
let size = reader.read_u32::<BigEndian>()?;
|
||||||
|
let base_address = reader.read_u32::<BigEndian>()?;
|
||||||
|
while reader.position() < size as u64 {
|
||||||
|
let line_number = reader.read_u32::<BigEndian>()?;
|
||||||
|
let statement_pos = reader.read_u16::<BigEndian>()?;
|
||||||
|
if statement_pos != 0xFFFF {
|
||||||
|
log::warn!("Unhandled statement pos {}", statement_pos);
|
||||||
|
}
|
||||||
|
let address_delta = reader.read_u32::<BigEndian>()?;
|
||||||
|
map.insert(base_address + address_delta, line_number);
|
||||||
|
}
|
||||||
|
println!("Line info: {map:#X?}");
|
||||||
|
return Ok(Some(map));
|
||||||
|
}
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn read(obj_path: &Path) -> Result<ObjInfo> {
|
pub fn read(obj_path: &Path) -> Result<ObjInfo> {
|
||||||
let data = {
|
let data = {
|
||||||
let file = fs::File::open(obj_path)?;
|
let file = fs::File::open(obj_path)?;
|
||||||
@@ -307,6 +323,7 @@ pub fn read(obj_path: &Path) -> Result<ObjInfo> {
|
|||||||
path: obj_path.to_owned(),
|
path: obj_path.to_owned(),
|
||||||
sections: filter_sections(&obj_file)?,
|
sections: filter_sections(&obj_file)?,
|
||||||
common: common_symbols(&obj_file)?,
|
common: common_symbols(&obj_file)?,
|
||||||
|
line_info: line_info(&obj_file)?,
|
||||||
};
|
};
|
||||||
for section in &mut result.sections {
|
for section in &mut result.sections {
|
||||||
section.symbols = symbols_by_section(&obj_file, section)?;
|
section.symbols = symbols_by_section(&obj_file, section)?;
|
||||||
|
|||||||
@@ -1,15 +1,24 @@
|
|||||||
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use rabbitizer::{config_set_register_fpr_abi_names, Abi, Instruction, SimpleOperandType};
|
use rabbitizer::{config, Abi, InstrCategory, Instruction, OperandType};
|
||||||
|
|
||||||
use crate::obj::{ObjIns, ObjInsArg, ObjReloc};
|
use crate::obj::{ObjIns, ObjInsArg, ObjReloc};
|
||||||
|
|
||||||
|
fn configure_rabbitizer() {
|
||||||
|
unsafe {
|
||||||
|
config::RabbitizerConfig_Cfg.reg_names.fpr_abi_names = Abi::O32;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn process_code(
|
pub fn process_code(
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
start_address: u64,
|
start_address: u64,
|
||||||
end_address: u64,
|
end_address: u64,
|
||||||
relocs: &[ObjReloc],
|
relocs: &[ObjReloc],
|
||||||
|
line_info: &Option<BTreeMap<u32, u32>>,
|
||||||
) -> Result<(Vec<u8>, Vec<ObjIns>)> {
|
) -> Result<(Vec<u8>, Vec<ObjIns>)> {
|
||||||
config_set_register_fpr_abi_names(Abi::RABBITIZER_ABI_O32);
|
configure_rabbitizer();
|
||||||
|
|
||||||
let ins_count = data.len() / 4;
|
let ins_count = data.len() / 4;
|
||||||
let mut ops = Vec::<u8>::with_capacity(ins_count);
|
let mut ops = Vec::<u8>::with_capacity(ins_count);
|
||||||
@@ -18,47 +27,61 @@ pub fn process_code(
|
|||||||
for chunk in data.chunks_exact(4) {
|
for chunk in data.chunks_exact(4) {
|
||||||
let reloc = relocs.iter().find(|r| (r.address as u32 & !3) == cur_addr);
|
let reloc = relocs.iter().find(|r| (r.address as u32 & !3) == cur_addr);
|
||||||
let code = u32::from_be_bytes(chunk.try_into()?);
|
let code = u32::from_be_bytes(chunk.try_into()?);
|
||||||
let mut instruction = Instruction::new(code, cur_addr);
|
let instruction = Instruction::new(code, cur_addr, InstrCategory::CPU);
|
||||||
|
|
||||||
let op = instruction.instr_id() as u8;
|
let op = instruction.unique_id as u8;
|
||||||
ops.push(op);
|
ops.push(op);
|
||||||
|
|
||||||
let mnemonic = instruction.instr_id().get_opcode_name().unwrap_or_default().to_string();
|
let mnemonic = instruction.opcode_name().to_string();
|
||||||
let is_branch = instruction.is_branch();
|
let is_branch = instruction.is_branch();
|
||||||
let branch_offset = instruction.branch_offset();
|
let branch_offset = instruction.branch_offset();
|
||||||
let branch_dest =
|
let branch_dest =
|
||||||
if is_branch { Some((cur_addr as i32 + branch_offset) as u32) } else { None };
|
if is_branch { Some((cur_addr as i32 + branch_offset) as u32) } else { None };
|
||||||
let args = instruction
|
|
||||||
.simple_operands()
|
let operands = instruction.get_operands_slice();
|
||||||
.iter()
|
let mut args = Vec::with_capacity(operands.len() + 1);
|
||||||
.map(|op| match op.kind {
|
for op in operands {
|
||||||
SimpleOperandType::Imm | SimpleOperandType::Label => {
|
match op {
|
||||||
|
OperandType::cpu_immediate
|
||||||
|
| OperandType::cpu_label
|
||||||
|
| OperandType::cpu_branch_target_label => {
|
||||||
if is_branch {
|
if is_branch {
|
||||||
ObjInsArg::BranchOffset(branch_offset)
|
args.push(ObjInsArg::BranchOffset(branch_offset));
|
||||||
} else if let Some(reloc) = reloc {
|
} else if let Some(reloc) = reloc {
|
||||||
if matches!(&reloc.target_section, Some(s) if s == ".text")
|
if matches!(&reloc.target_section, Some(s) if s == ".text")
|
||||||
&& reloc.target.address > start_address
|
&& reloc.target.address > start_address
|
||||||
&& reloc.target.address < end_address
|
&& reloc.target.address < end_address
|
||||||
{
|
{
|
||||||
// Inter-function reloc, convert to branch offset
|
// Inter-function reloc, convert to branch offset
|
||||||
ObjInsArg::BranchOffset(reloc.target.address as i32 - cur_addr as i32)
|
args.push(ObjInsArg::BranchOffset(
|
||||||
|
reloc.target.address as i32 - cur_addr as i32,
|
||||||
|
));
|
||||||
} else {
|
} else {
|
||||||
ObjInsArg::Reloc
|
args.push(ObjInsArg::Reloc);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ObjInsArg::MipsArg(op.disassembled.clone())
|
args.push(ObjInsArg::MipsArg(op.disassemble(&instruction, None)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SimpleOperandType::ImmBase => {
|
OperandType::cpu_immediate_base => {
|
||||||
if reloc.is_some() {
|
if reloc.is_some() {
|
||||||
ObjInsArg::RelocWithBase
|
args.push(ObjInsArg::RelocWithBase);
|
||||||
} else {
|
} else {
|
||||||
ObjInsArg::MipsArg(op.disassembled.clone())
|
args.push(ObjInsArg::MipsArgWithBase(
|
||||||
|
OperandType::cpu_immediate.disassemble(&instruction, None),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
args.push(ObjInsArg::MipsArg(
|
||||||
|
OperandType::cpu_rs.disassemble(&instruction, None),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
args.push(ObjInsArg::MipsArg(op.disassemble(&instruction, None)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => ObjInsArg::MipsArg(op.disassembled.clone()),
|
}
|
||||||
})
|
let line =
|
||||||
.collect();
|
line_info.as_ref().and_then(|map| map.range(..=cur_addr).last().map(|(_, &b)| b));
|
||||||
insts.push(ObjIns {
|
insts.push(ObjIns {
|
||||||
address: cur_addr,
|
address: cur_addr,
|
||||||
code,
|
code,
|
||||||
@@ -67,6 +90,7 @@ pub fn process_code(
|
|||||||
args,
|
args,
|
||||||
reloc: reloc.cloned(),
|
reloc: reloc.cloned(),
|
||||||
branch_dest,
|
branch_dest,
|
||||||
|
line,
|
||||||
});
|
});
|
||||||
cur_addr += 4;
|
cur_addr += 4;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ pub mod elf;
|
|||||||
pub mod mips;
|
pub mod mips;
|
||||||
pub mod ppc;
|
pub mod ppc;
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::{collections::BTreeMap, path::PathBuf};
|
||||||
|
|
||||||
use flagset::{flags, FlagSet};
|
use flagset::{flags, FlagSet};
|
||||||
|
|
||||||
@@ -41,6 +41,7 @@ pub struct ObjSection {
|
|||||||
pub enum ObjInsArg {
|
pub enum ObjInsArg {
|
||||||
PpcArg(ppc750cl::Argument),
|
PpcArg(ppc750cl::Argument),
|
||||||
MipsArg(String),
|
MipsArg(String),
|
||||||
|
MipsArgWithBase(String),
|
||||||
Reloc,
|
Reloc,
|
||||||
RelocWithBase,
|
RelocWithBase,
|
||||||
BranchOffset(i32),
|
BranchOffset(i32),
|
||||||
@@ -83,6 +84,8 @@ pub struct ObjIns {
|
|||||||
pub args: Vec<ObjInsArg>,
|
pub args: Vec<ObjInsArg>,
|
||||||
pub reloc: Option<ObjReloc>,
|
pub reloc: Option<ObjReloc>,
|
||||||
pub branch_dest: Option<u32>,
|
pub branch_dest: Option<u32>,
|
||||||
|
/// Line info
|
||||||
|
pub line: Option<u32>,
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct ObjInsDiff {
|
pub struct ObjInsDiff {
|
||||||
@@ -138,6 +141,7 @@ pub struct ObjInfo {
|
|||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
pub sections: Vec<ObjSection>,
|
pub sections: Vec<ObjSection>,
|
||||||
pub common: Vec<ObjSymbol>,
|
pub common: Vec<ObjSymbol>,
|
||||||
|
pub line_info: Option<BTreeMap<u32, u32>>,
|
||||||
}
|
}
|
||||||
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
||||||
pub enum ObjRelocKind {
|
pub enum ObjRelocKind {
|
||||||
@@ -155,6 +159,10 @@ pub enum ObjRelocKind {
|
|||||||
Mips26,
|
Mips26,
|
||||||
MipsHi16,
|
MipsHi16,
|
||||||
MipsLo16,
|
MipsLo16,
|
||||||
|
MipsGot16,
|
||||||
|
MipsCall16,
|
||||||
|
MipsGpRel16,
|
||||||
|
MipsGpRel32,
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ObjReloc {
|
pub struct ObjReloc {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use ppc750cl::{disasm_iter, Argument};
|
use ppc750cl::{disasm_iter, Argument};
|
||||||
|
|
||||||
@@ -19,6 +21,7 @@ pub fn process_code(
|
|||||||
data: &[u8],
|
data: &[u8],
|
||||||
address: u64,
|
address: u64,
|
||||||
relocs: &[ObjReloc],
|
relocs: &[ObjReloc],
|
||||||
|
line_info: &Option<BTreeMap<u32, u32>>,
|
||||||
) -> Result<(Vec<u8>, Vec<ObjIns>)> {
|
) -> Result<(Vec<u8>, Vec<ObjIns>)> {
|
||||||
let ins_count = data.len() / 4;
|
let ins_count = data.len() / 4;
|
||||||
let mut ops = Vec::<u8>::with_capacity(ins_count);
|
let mut ops = Vec::<u8>::with_capacity(ins_count);
|
||||||
@@ -74,6 +77,9 @@ pub fn process_code(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ops.push(simplified.ins.op as u8);
|
ops.push(simplified.ins.op as u8);
|
||||||
|
let line = line_info
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|map| map.range(..=simplified.ins.addr).last().map(|(_, &b)| b));
|
||||||
insts.push(ObjIns {
|
insts.push(ObjIns {
|
||||||
address: simplified.ins.addr,
|
address: simplified.ins.addr,
|
||||||
code: simplified.ins.code,
|
code: simplified.ins.code,
|
||||||
@@ -82,6 +88,7 @@ pub fn process_code(
|
|||||||
reloc: reloc.cloned(),
|
reloc: reloc.cloned(),
|
||||||
op: 0,
|
op: 0,
|
||||||
branch_dest: None,
|
branch_dest: None,
|
||||||
|
line,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Ok((ops, insts))
|
Ok((ops, insts))
|
||||||
|
|||||||
@@ -81,12 +81,14 @@ pub fn config_ui(ui: &mut egui::Ui, config: &Arc<RwLock<AppConfig>>, view_state:
|
|||||||
if state.update_available {
|
if state.update_available {
|
||||||
ui.colored_label(Color32::LIGHT_GREEN, "Update available");
|
ui.colored_label(Color32::LIGHT_GREEN, "Update available");
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if state.found_binary && ui
|
if state.found_binary
|
||||||
|
&& ui
|
||||||
.button("Automatic")
|
.button("Automatic")
|
||||||
.on_hover_text_at_pointer(
|
.on_hover_text_at_pointer(
|
||||||
"Automatically download and replace the current build",
|
"Automatically download and replace the current build",
|
||||||
)
|
)
|
||||||
.clicked() {
|
.clicked()
|
||||||
|
{
|
||||||
view_state.jobs.push(queue_update());
|
view_state.jobs.push(queue_update());
|
||||||
}
|
}
|
||||||
if ui
|
if ui
|
||||||
@@ -183,21 +185,19 @@ pub fn config_ui(ui: &mut egui::Ui, config: &Arc<RwLock<AppConfig>>, view_state:
|
|||||||
ui.separator();
|
ui.separator();
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(base_dir) = base_obj_dir {
|
if let (Some(base_dir), Some(target_dir)) = (base_obj_dir, target_obj_dir) {
|
||||||
if ui.button("Select obj").clicked() {
|
if ui.button("Select obj").clicked() {
|
||||||
if let Some(path) = rfd::FileDialog::new()
|
if let Some(path) = rfd::FileDialog::new()
|
||||||
.set_directory(&base_dir)
|
.set_directory(&target_dir)
|
||||||
.add_filter("Object file", &["o", "elf"])
|
.add_filter("Object file", &["o", "elf"])
|
||||||
.pick_file()
|
.pick_file()
|
||||||
{
|
{
|
||||||
let mut new_build_obj: Option<String> = None;
|
let mut new_build_obj: Option<String> = None;
|
||||||
if let Ok(obj_path) = path.strip_prefix(&base_dir) {
|
if let Ok(obj_path) = path.strip_prefix(&base_dir) {
|
||||||
new_build_obj = Some(obj_path.display().to_string());
|
new_build_obj = Some(obj_path.display().to_string());
|
||||||
} else if let Some(build_asm_dir) = target_obj_dir {
|
} else if let Ok(obj_path) = path.strip_prefix(&target_dir) {
|
||||||
if let Ok(obj_path) = path.strip_prefix(&build_asm_dir) {
|
|
||||||
new_build_obj = Some(obj_path.display().to_string());
|
new_build_obj = Some(obj_path.display().to_string());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if let Some(new_build_obj) = new_build_obj {
|
if let Some(new_build_obj) = new_build_obj {
|
||||||
*obj_path = Some(new_build_obj);
|
*obj_path = Some(new_build_obj);
|
||||||
view_state
|
view_state
|
||||||
@@ -247,6 +247,6 @@ pub fn config_ui(ui: &mut egui::Ui, config: &Arc<RwLock<AppConfig>>, view_state:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.checkbox(&mut view_state.reverse_fn_order, "Reverse function order (deferred)");
|
ui.checkbox(&mut view_state.view_config.reverse_fn_order, "Reverse function order (deferred)");
|
||||||
ui.separator();
|
ui.separator();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use std::{cmp::min, default::Default, mem::take};
|
use std::{cmp::min, default::Default, mem::take};
|
||||||
|
|
||||||
use egui::{text::LayoutJob, Color32, Label, Sense};
|
use egui::{text::LayoutJob, Align, Color32, Label, Layout, Sense, Vec2};
|
||||||
use egui_extras::{Size, StripBuilder, TableBuilder};
|
use egui_extras::{Column, TableBuilder};
|
||||||
use time::format_description;
|
use time::format_description;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
app::{View, ViewConfig, ViewState},
|
app::{SymbolReference, View, ViewConfig, ViewState},
|
||||||
jobs::Job,
|
jobs::Job,
|
||||||
obj::{ObjDataDiff, ObjDataDiffKind, ObjInfo, ObjSection},
|
obj::{ObjDataDiff, ObjDataDiffKind, ObjInfo, ObjSection},
|
||||||
views::{write_text, COLOR_RED},
|
views::{write_text, COLOR_RED},
|
||||||
@@ -13,8 +13,8 @@ use crate::{
|
|||||||
|
|
||||||
const BYTES_PER_ROW: usize = 16;
|
const BYTES_PER_ROW: usize = 16;
|
||||||
|
|
||||||
fn find_section<'a>(obj: &'a ObjInfo, section_name: &str) -> Option<&'a ObjSection> {
|
fn find_section<'a>(obj: &'a ObjInfo, selected_symbol: &SymbolReference) -> Option<&'a ObjSection> {
|
||||||
obj.sections.iter().find(|s| s.name == section_name)
|
obj.sections.iter().find(|section| section.name == selected_symbol.section_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn data_row_ui(ui: &mut egui::Ui, address: usize, diffs: &[ObjDataDiff], config: &ViewConfig) {
|
fn data_row_ui(ui: &mut egui::Ui, address: usize, diffs: &[ObjDataDiff], config: &ViewConfig) {
|
||||||
@@ -132,11 +132,11 @@ fn data_table_ui(
|
|||||||
table: TableBuilder<'_>,
|
table: TableBuilder<'_>,
|
||||||
left_obj: &ObjInfo,
|
left_obj: &ObjInfo,
|
||||||
right_obj: &ObjInfo,
|
right_obj: &ObjInfo,
|
||||||
section_name: &str,
|
selected_symbol: &SymbolReference,
|
||||||
config: &ViewConfig,
|
config: &ViewConfig,
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
let left_section = find_section(left_obj, section_name)?;
|
let left_section = find_section(left_obj, selected_symbol)?;
|
||||||
let right_section = find_section(right_obj, section_name)?;
|
let right_section = find_section(right_obj, selected_symbol)?;
|
||||||
|
|
||||||
let total_bytes = left_section.data_diff.iter().fold(0usize, |accum, item| accum + item.len);
|
let total_bytes = left_section.data_diff.iter().fold(0usize, |accum, item| accum + item.len);
|
||||||
if total_bytes == 0 {
|
if total_bytes == 0 {
|
||||||
@@ -163,42 +163,57 @@ fn data_table_ui(
|
|||||||
|
|
||||||
pub fn data_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
|
pub fn data_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
|
||||||
let mut rebuild = false;
|
let mut rebuild = false;
|
||||||
if let (Some(result), Some(selected_symbol)) = (&view_state.build, &view_state.selected_symbol)
|
let (Some(result), Some(selected_symbol)) = (&view_state.build, &view_state.selected_symbol) else {
|
||||||
{
|
return rebuild;
|
||||||
StripBuilder::new(ui)
|
};
|
||||||
.size(Size::exact(20.0))
|
|
||||||
.size(Size::exact(40.0))
|
// Header
|
||||||
.size(Size::remainder())
|
let available_width = ui.available_width();
|
||||||
.vertical(|mut strip| {
|
let column_width = available_width / 2.0;
|
||||||
strip.strip(|builder| {
|
ui.allocate_ui_with_layout(
|
||||||
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| {
|
Vec2 { x: available_width, y: 100.0 },
|
||||||
strip.cell(|ui| {
|
Layout::left_to_right(Align::Min),
|
||||||
ui.horizontal(|ui| {
|
|ui| {
|
||||||
|
// Left column
|
||||||
|
ui.allocate_ui_with_layout(
|
||||||
|
Vec2 { x: column_width, y: 100.0 },
|
||||||
|
Layout::top_down(Align::Min),
|
||||||
|
|ui| {
|
||||||
|
ui.set_width(column_width);
|
||||||
|
|
||||||
if ui.button("Back").clicked() {
|
if ui.button("Back").clicked() {
|
||||||
view_state.current_view = View::SymbolDiff;
|
view_state.current_view = View::SymbolDiff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui.scope(|ui| {
|
||||||
|
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
|
||||||
|
ui.style_mut().wrap = Some(false);
|
||||||
|
ui.colored_label(Color32::WHITE, &selected_symbol.symbol_name);
|
||||||
|
ui.label("Diff target:");
|
||||||
});
|
});
|
||||||
});
|
},
|
||||||
strip.cell(|ui| {
|
);
|
||||||
|
|
||||||
|
// Right column
|
||||||
|
ui.allocate_ui_with_layout(
|
||||||
|
Vec2 { x: column_width, y: 100.0 },
|
||||||
|
Layout::top_down(Align::Min),
|
||||||
|
|ui| {
|
||||||
|
ui.set_width(column_width);
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if ui.button("Build").clicked() {
|
if ui.button("Build").clicked() {
|
||||||
rebuild = true;
|
rebuild = true;
|
||||||
}
|
}
|
||||||
ui.scope(|ui| {
|
ui.scope(|ui| {
|
||||||
ui.style_mut().override_text_style =
|
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
|
||||||
Some(egui::TextStyle::Monospace);
|
|
||||||
ui.style_mut().wrap = Some(false);
|
ui.style_mut().wrap = Some(false);
|
||||||
if view_state
|
if view_state.jobs.iter().any(|job| job.job_type == Job::ObjDiff) {
|
||||||
.jobs
|
|
||||||
.iter()
|
|
||||||
.any(|job| job.job_type == Job::ObjDiff)
|
|
||||||
{
|
|
||||||
ui.label("Building...");
|
ui.label("Building...");
|
||||||
} else {
|
} else {
|
||||||
ui.label("Last built:");
|
ui.label("Last built:");
|
||||||
let format =
|
let format =
|
||||||
format_description::parse("[hour]:[minute]:[second]")
|
format_description::parse("[hour]:[minute]:[second]").unwrap();
|
||||||
.unwrap();
|
|
||||||
ui.label(
|
ui.label(
|
||||||
result
|
result
|
||||||
.time
|
.time
|
||||||
@@ -209,53 +224,31 @@ pub fn data_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
strip.strip(|builder| {
|
|
||||||
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| {
|
|
||||||
strip.cell(|ui| {
|
|
||||||
ui.scope(|ui| {
|
ui.scope(|ui| {
|
||||||
ui.style_mut().override_text_style =
|
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
|
||||||
Some(egui::TextStyle::Monospace);
|
|
||||||
ui.style_mut().wrap = Some(false);
|
|
||||||
ui.colored_label(Color32::WHITE, selected_symbol);
|
|
||||||
ui.label("Diff target:");
|
|
||||||
ui.separator();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
strip.cell(|ui| {
|
|
||||||
ui.scope(|ui| {
|
|
||||||
ui.style_mut().override_text_style =
|
|
||||||
Some(egui::TextStyle::Monospace);
|
|
||||||
ui.style_mut().wrap = Some(false);
|
ui.style_mut().wrap = Some(false);
|
||||||
ui.label("");
|
ui.label("");
|
||||||
ui.label("Diff base:");
|
ui.label("Diff base:");
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
ui.separator();
|
ui.separator();
|
||||||
});
|
|
||||||
});
|
// Table
|
||||||
});
|
if let (Some(left_obj), Some(right_obj)) = (&result.first_obj, &result.second_obj) {
|
||||||
});
|
let available_height = ui.available_height();
|
||||||
strip.cell(|ui| {
|
|
||||||
if let (Some(left_obj), Some(right_obj)) =
|
|
||||||
(&result.first_obj, &result.second_obj)
|
|
||||||
{
|
|
||||||
let table = TableBuilder::new(ui)
|
let table = TableBuilder::new(ui)
|
||||||
.striped(false)
|
.striped(false)
|
||||||
.cell_layout(egui::Layout::left_to_right(egui::Align::Min))
|
.cell_layout(Layout::left_to_right(Align::Min))
|
||||||
.column(Size::relative(0.5))
|
.columns(Column::exact(column_width).clip(true), 2)
|
||||||
.column(Size::relative(0.5))
|
.resizable(false)
|
||||||
.resizable(false);
|
.auto_shrink([false, false])
|
||||||
data_table_ui(
|
.min_scrolled_height(available_height);
|
||||||
table,
|
data_table_ui(table, left_obj, right_obj, selected_symbol, &view_state.view_config);
|
||||||
left_obj,
|
|
||||||
right_obj,
|
|
||||||
selected_symbol,
|
|
||||||
&view_state.view_config,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rebuild
|
rebuild
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
use std::default::Default;
|
use std::{cmp::Ordering, default::Default};
|
||||||
|
|
||||||
use cwdemangle::demangle;
|
use cwdemangle::demangle;
|
||||||
use egui::{text::LayoutJob, Color32, FontId, Label, Sense};
|
use eframe::emath::Align;
|
||||||
use egui_extras::{Size, StripBuilder, TableBuilder};
|
use egui::{text::LayoutJob, Color32, FontId, Label, Layout, Sense, Vec2};
|
||||||
|
use egui_extras::{Column, TableBuilder};
|
||||||
use ppc750cl::Argument;
|
use ppc750cl::Argument;
|
||||||
use time::format_description;
|
use time::format_description;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
app::{View, ViewConfig, ViewState},
|
app::{SymbolReference, View, ViewConfig, ViewState},
|
||||||
jobs::Job,
|
jobs::Job,
|
||||||
obj::{
|
obj::{
|
||||||
ObjInfo, ObjIns, ObjInsArg, ObjInsArgDiff, ObjInsDiff, ObjInsDiffKind, ObjReloc,
|
ObjInfo, ObjIns, ObjInsArg, ObjInsArgDiff, ObjInsDiff, ObjInsDiffKind, ObjReloc,
|
||||||
@@ -19,8 +20,14 @@ use crate::{
|
|||||||
fn write_reloc_name(reloc: &ObjReloc, color: Color32, job: &mut LayoutJob, font_id: FontId) {
|
fn write_reloc_name(reloc: &ObjReloc, color: Color32, job: &mut LayoutJob, font_id: FontId) {
|
||||||
let name = reloc.target.demangled_name.as_ref().unwrap_or(&reloc.target.name);
|
let name = reloc.target.demangled_name.as_ref().unwrap_or(&reloc.target.name);
|
||||||
write_text(name, Color32::LIGHT_GRAY, job, font_id.clone());
|
write_text(name, Color32::LIGHT_GRAY, job, font_id.clone());
|
||||||
if reloc.target.addend != 0 {
|
match reloc.target.addend.cmp(&0i64) {
|
||||||
write_text(&format!("+{:X}", reloc.target.addend), color, job, font_id);
|
Ordering::Greater => {
|
||||||
|
write_text(&format!("+{:#X}", reloc.target.addend), color, job, font_id)
|
||||||
|
}
|
||||||
|
Ordering::Less => {
|
||||||
|
write_text(&format!("-{:#X}", -reloc.target.addend), color, job, font_id);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,12 +59,27 @@ fn write_reloc(reloc: &ObjReloc, color: Color32, job: &mut LayoutJob, font_id: F
|
|||||||
write_reloc_name(reloc, color, job, font_id.clone());
|
write_reloc_name(reloc, color, job, font_id.clone());
|
||||||
write_text(")", color, job, font_id);
|
write_text(")", color, job, font_id);
|
||||||
}
|
}
|
||||||
ObjRelocKind::Absolute
|
ObjRelocKind::MipsGot16 => {
|
||||||
| ObjRelocKind::PpcRel24
|
write_text("%got(", color, job, font_id.clone());
|
||||||
| ObjRelocKind::PpcRel14
|
write_reloc_name(reloc, color, job, font_id.clone());
|
||||||
| ObjRelocKind::Mips26 => {
|
write_text(")", color, job, font_id);
|
||||||
|
}
|
||||||
|
ObjRelocKind::MipsCall16 => {
|
||||||
|
write_text("%call16(", color, job, font_id.clone());
|
||||||
|
write_reloc_name(reloc, color, job, font_id.clone());
|
||||||
|
write_text(")", color, job, font_id);
|
||||||
|
}
|
||||||
|
ObjRelocKind::MipsGpRel16 => {
|
||||||
|
write_text("%gp_rel(", color, job, font_id.clone());
|
||||||
|
write_reloc_name(reloc, color, job, font_id.clone());
|
||||||
|
write_text(")", color, job, font_id);
|
||||||
|
}
|
||||||
|
ObjRelocKind::PpcRel24 | ObjRelocKind::PpcRel14 | ObjRelocKind::Mips26 => {
|
||||||
write_reloc_name(reloc, color, job, font_id);
|
write_reloc_name(reloc, color, job, font_id);
|
||||||
}
|
}
|
||||||
|
ObjRelocKind::Absolute | ObjRelocKind::MipsGpRel32 => {
|
||||||
|
write_text("[INVALID]", color, job, font_id);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,6 +153,17 @@ fn write_ins(
|
|||||||
config.code_font.clone(),
|
config.code_font.clone(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
ObjInsArg::MipsArgWithBase(str) => {
|
||||||
|
write_text(
|
||||||
|
str.strip_prefix('$').unwrap_or(str),
|
||||||
|
color,
|
||||||
|
job,
|
||||||
|
config.code_font.clone(),
|
||||||
|
);
|
||||||
|
write_text("(", base_color, job, config.code_font.clone());
|
||||||
|
writing_offset = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
ObjInsArg::BranchOffset(offset) => {
|
ObjInsArg::BranchOffset(offset) => {
|
||||||
let addr = offset + ins.address as i32 - base_addr as i32;
|
let addr = offset + ins.address as i32 - base_addr as i32;
|
||||||
write_text(&format!("{addr:x}"), color, job, config.code_font.clone());
|
write_text(&format!("{addr:x}"), color, job, config.code_font.clone());
|
||||||
@@ -240,9 +273,10 @@ fn ins_context_menu(ui: &mut egui::Ui, ins: &ObjIns) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_symbol<'a>(obj: &'a ObjInfo, section_name: &str, name: &str) -> Option<&'a ObjSymbol> {
|
fn find_symbol<'a>(obj: &'a ObjInfo, selected_symbol: &SymbolReference) -> Option<&'a ObjSymbol> {
|
||||||
let section = obj.sections.iter().find(|s| s.name == section_name)?;
|
obj.sections.iter().find_map(|section| {
|
||||||
section.symbols.iter().find(|s| s.name == name)
|
section.symbols.iter().find(|symbol| symbol.name == selected_symbol.symbol_name)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn asm_row_ui(ui: &mut egui::Ui, ins_diff: &ObjInsDiff, symbol: &ObjSymbol, config: &ViewConfig) {
|
fn asm_row_ui(ui: &mut egui::Ui, ins_diff: &ObjInsDiff, symbol: &ObjSymbol, config: &ViewConfig) {
|
||||||
@@ -250,7 +284,11 @@ fn asm_row_ui(ui: &mut egui::Ui, ins_diff: &ObjInsDiff, symbol: &ObjSymbol, conf
|
|||||||
ui.painter().rect_filled(ui.available_rect_before_wrap(), 0.0, ui.visuals().faint_bg_color);
|
ui.painter().rect_filled(ui.available_rect_before_wrap(), 0.0, ui.visuals().faint_bg_color);
|
||||||
}
|
}
|
||||||
let mut job = LayoutJob::default();
|
let mut job = LayoutJob::default();
|
||||||
if let Some(ins) = &ins_diff.ins {
|
let Some(ins) = &ins_diff.ins else {
|
||||||
|
ui.label("");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
let base_color = match ins_diff.kind {
|
let base_color = match ins_diff.kind {
|
||||||
ObjInsDiffKind::None | ObjInsDiffKind::OpMismatch | ObjInsDiffKind::ArgMismatch => {
|
ObjInsDiffKind::None | ObjInsDiffKind::OpMismatch | ObjInsDiffKind::ArgMismatch => {
|
||||||
Color32::GRAY
|
Color32::GRAY
|
||||||
@@ -259,8 +297,14 @@ fn asm_row_ui(ui: &mut egui::Ui, ins_diff: &ObjInsDiff, symbol: &ObjSymbol, conf
|
|||||||
ObjInsDiffKind::Delete => COLOR_RED,
|
ObjInsDiffKind::Delete => COLOR_RED,
|
||||||
ObjInsDiffKind::Insert => Color32::GREEN,
|
ObjInsDiffKind::Insert => Color32::GREEN,
|
||||||
};
|
};
|
||||||
|
let mut pad = 6;
|
||||||
|
if let Some(line) = ins.line {
|
||||||
|
let line_str = format!("{line} ");
|
||||||
|
write_text(&line_str, Color32::DARK_GRAY, &mut job, config.code_font.clone());
|
||||||
|
pad = 12 - line_str.len();
|
||||||
|
}
|
||||||
write_text(
|
write_text(
|
||||||
&format!("{:<6}", format!("{:x}:", ins.address - symbol.address as u32)),
|
&format!("{:<1$}", format!("{:x}: ", ins.address - symbol.address as u32), pad),
|
||||||
base_color,
|
base_color,
|
||||||
&mut job,
|
&mut job,
|
||||||
config.code_font.clone(),
|
config.code_font.clone(),
|
||||||
@@ -287,20 +331,17 @@ fn asm_row_ui(ui: &mut egui::Ui, ins_diff: &ObjInsDiff, symbol: &ObjSymbol, conf
|
|||||||
ui.add(Label::new(job).sense(Sense::click()))
|
ui.add(Label::new(job).sense(Sense::click()))
|
||||||
.on_hover_ui_at_pointer(|ui| ins_hover_ui(ui, ins))
|
.on_hover_ui_at_pointer(|ui| ins_hover_ui(ui, ins))
|
||||||
.context_menu(|ui| ins_context_menu(ui, ins));
|
.context_menu(|ui| ins_context_menu(ui, ins));
|
||||||
} else {
|
|
||||||
ui.label("");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn asm_table_ui(
|
fn asm_table_ui(
|
||||||
table: TableBuilder<'_>,
|
table: TableBuilder<'_>,
|
||||||
left_obj: &ObjInfo,
|
left_obj: &ObjInfo,
|
||||||
right_obj: &ObjInfo,
|
right_obj: &ObjInfo,
|
||||||
fn_name: &str,
|
selected_symbol: &SymbolReference,
|
||||||
config: &ViewConfig,
|
config: &ViewConfig,
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
let left_symbol = find_symbol(left_obj, ".text", fn_name);
|
let left_symbol = find_symbol(left_obj, selected_symbol);
|
||||||
let right_symbol = find_symbol(right_obj, ".text", fn_name);
|
let right_symbol = find_symbol(right_obj, selected_symbol);
|
||||||
let instructions_len = left_symbol.or(right_symbol).map(|s| s.instructions.len())?;
|
let instructions_len = left_symbol.or(right_symbol).map(|s| s.instructions.len())?;
|
||||||
table.body(|body| {
|
table.body(|body| {
|
||||||
body.rows(config.code_font.size, instructions_len, |row_index, mut row| {
|
body.rows(config.code_font.size, instructions_len, |row_index, mut row| {
|
||||||
@@ -321,42 +362,67 @@ fn asm_table_ui(
|
|||||||
|
|
||||||
pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
|
pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
|
||||||
let mut rebuild = false;
|
let mut rebuild = false;
|
||||||
if let (Some(result), Some(selected_symbol)) = (&view_state.build, &view_state.selected_symbol)
|
let (Some(result), Some(selected_symbol)) = (&view_state.build, &view_state.selected_symbol) else {
|
||||||
{
|
return rebuild;
|
||||||
StripBuilder::new(ui)
|
};
|
||||||
.size(Size::exact(20.0))
|
|
||||||
.size(Size::exact(40.0))
|
// Header
|
||||||
.size(Size::remainder())
|
let available_width = ui.available_width();
|
||||||
.vertical(|mut strip| {
|
let column_width = available_width / 2.0;
|
||||||
strip.strip(|builder| {
|
ui.allocate_ui_with_layout(
|
||||||
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| {
|
Vec2 { x: available_width, y: 100.0 },
|
||||||
strip.cell(|ui| {
|
Layout::left_to_right(Align::Min),
|
||||||
ui.horizontal(|ui| {
|
|ui| {
|
||||||
|
// Left column
|
||||||
|
ui.allocate_ui_with_layout(
|
||||||
|
Vec2 { x: column_width, y: 100.0 },
|
||||||
|
Layout::top_down(Align::Min),
|
||||||
|
|ui| {
|
||||||
|
ui.set_width(column_width);
|
||||||
|
|
||||||
if ui.button("Back").clicked() {
|
if ui.button("Back").clicked() {
|
||||||
view_state.current_view = View::SymbolDiff;
|
view_state.current_view = View::SymbolDiff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let demangled = demangle(&selected_symbol.symbol_name, &Default::default());
|
||||||
|
let name = demangled.as_deref().unwrap_or(&selected_symbol.symbol_name);
|
||||||
|
let mut job = LayoutJob::simple(
|
||||||
|
name.to_string(),
|
||||||
|
view_state.view_config.code_font.clone(),
|
||||||
|
Color32::WHITE,
|
||||||
|
column_width,
|
||||||
|
);
|
||||||
|
job.wrap.break_anywhere = true;
|
||||||
|
job.wrap.max_rows = 1;
|
||||||
|
ui.label(job);
|
||||||
|
|
||||||
|
ui.scope(|ui| {
|
||||||
|
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
|
||||||
|
ui.label("Diff target:");
|
||||||
});
|
});
|
||||||
});
|
},
|
||||||
strip.cell(|ui| {
|
);
|
||||||
|
|
||||||
|
// Right column
|
||||||
|
ui.allocate_ui_with_layout(
|
||||||
|
Vec2 { x: column_width, y: 100.0 },
|
||||||
|
Layout::top_down(Align::Min),
|
||||||
|
|ui| {
|
||||||
|
ui.set_width(column_width);
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if ui.button("Build").clicked() {
|
if ui.button("Build").clicked() {
|
||||||
rebuild = true;
|
rebuild = true;
|
||||||
}
|
}
|
||||||
ui.scope(|ui| {
|
ui.scope(|ui| {
|
||||||
ui.style_mut().override_text_style =
|
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
|
||||||
Some(egui::TextStyle::Monospace);
|
|
||||||
ui.style_mut().wrap = Some(false);
|
ui.style_mut().wrap = Some(false);
|
||||||
if view_state
|
if view_state.jobs.iter().any(|job| job.job_type == Job::ObjDiff) {
|
||||||
.jobs
|
|
||||||
.iter()
|
|
||||||
.any(|job| job.job_type == Job::ObjDiff)
|
|
||||||
{
|
|
||||||
ui.label("Building...");
|
ui.label("Building...");
|
||||||
} else {
|
} else {
|
||||||
ui.label("Last built:");
|
ui.label("Last built:");
|
||||||
let format =
|
let format =
|
||||||
format_description::parse("[hour]:[minute]:[second]")
|
format_description::parse("[hour]:[minute]:[second]").unwrap();
|
||||||
.unwrap();
|
|
||||||
ui.label(
|
ui.label(
|
||||||
result
|
result
|
||||||
.time
|
.time
|
||||||
@@ -367,67 +433,41 @@ pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
strip.strip(|builder| {
|
|
||||||
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| {
|
|
||||||
let demangled = demangle(selected_symbol, &Default::default());
|
|
||||||
strip.cell(|ui| {
|
|
||||||
ui.scope(|ui| {
|
ui.scope(|ui| {
|
||||||
ui.style_mut().override_text_style =
|
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
|
||||||
Some(egui::TextStyle::Monospace);
|
|
||||||
ui.style_mut().wrap = Some(false);
|
|
||||||
ui.colored_label(
|
|
||||||
Color32::WHITE,
|
|
||||||
demangled.as_ref().unwrap_or(selected_symbol),
|
|
||||||
);
|
|
||||||
ui.label("Diff target:");
|
|
||||||
ui.separator();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
strip.cell(|ui| {
|
|
||||||
ui.scope(|ui| {
|
|
||||||
ui.style_mut().override_text_style =
|
|
||||||
Some(egui::TextStyle::Monospace);
|
|
||||||
ui.style_mut().wrap = Some(false);
|
|
||||||
if let Some(match_percent) = result
|
if let Some(match_percent) = result
|
||||||
.second_obj
|
.second_obj
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|obj| find_symbol(obj, ".text", selected_symbol))
|
.and_then(|obj| find_symbol(obj, selected_symbol))
|
||||||
.and_then(|symbol| symbol.match_percent)
|
.and_then(|symbol| symbol.match_percent)
|
||||||
{
|
{
|
||||||
ui.colored_label(
|
ui.colored_label(
|
||||||
match_color_for_symbol(match_percent),
|
match_color_for_symbol(match_percent),
|
||||||
&format!("{match_percent:.0}%"),
|
&format!("{match_percent:.0}%"),
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
ui.label("");
|
||||||
}
|
}
|
||||||
ui.label("Diff base:");
|
ui.label("Diff base:");
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
ui.separator();
|
ui.separator();
|
||||||
});
|
|
||||||
});
|
// Table
|
||||||
});
|
if let (Some(left_obj), Some(right_obj)) = (&result.first_obj, &result.second_obj) {
|
||||||
});
|
let available_height = ui.available_height();
|
||||||
strip.cell(|ui| {
|
|
||||||
if let (Some(left_obj), Some(right_obj)) =
|
|
||||||
(&result.first_obj, &result.second_obj)
|
|
||||||
{
|
|
||||||
let table = TableBuilder::new(ui)
|
let table = TableBuilder::new(ui)
|
||||||
.striped(false)
|
.striped(false)
|
||||||
.cell_layout(egui::Layout::left_to_right(egui::Align::Min))
|
.cell_layout(Layout::left_to_right(Align::Min))
|
||||||
.column(Size::relative(0.5))
|
.columns(Column::exact(column_width).clip(true), 2)
|
||||||
.column(Size::relative(0.5))
|
.resizable(false)
|
||||||
.resizable(false);
|
.auto_shrink([false, false])
|
||||||
asm_table_ui(
|
.min_scrolled_height(available_height);
|
||||||
table,
|
asm_table_ui(table, left_obj, right_obj, selected_symbol, &view_state.view_config);
|
||||||
left_obj,
|
|
||||||
right_obj,
|
|
||||||
selected_symbol,
|
|
||||||
&view_state.view_config,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
rebuild
|
rebuild
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ pub fn jobs_ui(ui: &mut egui::Ui, view_state: &mut ViewState) {
|
|||||||
|
|
||||||
let mut remove_job: Option<usize> = None;
|
let mut remove_job: Option<usize> = None;
|
||||||
for (idx, job) in view_state.jobs.iter_mut().enumerate() {
|
for (idx, job) in view_state.jobs.iter_mut().enumerate() {
|
||||||
if let Ok(status) = job.status.read() {
|
let Ok(status) = job.status.read() else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
ui.group(|ui| {
|
ui.group(|ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label(&status.title);
|
ui.label(&status.title);
|
||||||
@@ -47,7 +49,6 @@ pub fn jobs_ui(ui: &mut egui::Ui, view_state: &mut ViewState) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(idx) = remove_job {
|
if let Some(idx) = remove_job {
|
||||||
view_state.jobs.remove(idx);
|
view_state.jobs.remove(idx);
|
||||||
|
|||||||
@@ -9,5 +9,5 @@ pub(crate) mod symbol_diff;
|
|||||||
const COLOR_RED: Color32 = Color32::from_rgb(200, 40, 41);
|
const COLOR_RED: Color32 = Color32::from_rgb(200, 40, 41);
|
||||||
|
|
||||||
fn write_text(str: &str, color: Color32, job: &mut LayoutJob, font_id: FontId) {
|
fn write_text(str: &str, color: Color32, job: &mut LayoutJob, font_id: FontId) {
|
||||||
job.append(str, 0.0, TextFormat { font_id, color, ..Default::default() });
|
job.append(str, 0.0, TextFormat::simple(font_id, color));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
use egui::{
|
use egui::{
|
||||||
text::LayoutJob, CollapsingHeader, Color32, Rgba, ScrollArea, SelectableLabel, Ui, Widget,
|
text::LayoutJob, Align, CollapsingHeader, Color32, Layout, Rgba, ScrollArea, SelectableLabel,
|
||||||
|
TextEdit, Ui, Vec2, Widget,
|
||||||
};
|
};
|
||||||
use egui_extras::{Size, StripBuilder};
|
use egui_extras::{Size, StripBuilder};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
app::{View, ViewConfig, ViewState},
|
app::{SymbolReference, View, ViewConfig, ViewState},
|
||||||
jobs::objdiff::BuildStatus,
|
jobs::objdiff::BuildStatus,
|
||||||
obj::{ObjInfo, ObjSection, ObjSectionKind, ObjSymbol, ObjSymbolFlags},
|
obj::{ObjInfo, ObjSection, ObjSectionKind, ObjSymbol, ObjSymbolFlags},
|
||||||
views::write_text,
|
views::write_text,
|
||||||
@@ -58,7 +59,7 @@ fn symbol_ui(
|
|||||||
symbol: &ObjSymbol,
|
symbol: &ObjSymbol,
|
||||||
section: Option<&ObjSection>,
|
section: Option<&ObjSection>,
|
||||||
highlighted_symbol: &mut Option<String>,
|
highlighted_symbol: &mut Option<String>,
|
||||||
selected_symbol: &mut Option<String>,
|
selected_symbol: &mut Option<SymbolReference>,
|
||||||
current_view: &mut View,
|
current_view: &mut View,
|
||||||
config: &ViewConfig,
|
config: &ViewConfig,
|
||||||
) {
|
) {
|
||||||
@@ -99,10 +100,16 @@ fn symbol_ui(
|
|||||||
if response.clicked() {
|
if response.clicked() {
|
||||||
if let Some(section) = section {
|
if let Some(section) = section {
|
||||||
if section.kind == ObjSectionKind::Code {
|
if section.kind == ObjSectionKind::Code {
|
||||||
*selected_symbol = Some(symbol.name.clone());
|
*selected_symbol = Some(SymbolReference {
|
||||||
|
symbol_name: symbol.name.clone(),
|
||||||
|
section_name: section.name.clone(),
|
||||||
|
});
|
||||||
*current_view = View::FunctionDiff;
|
*current_view = View::FunctionDiff;
|
||||||
} else if section.kind == ObjSectionKind::Data {
|
} else if section.kind == ObjSectionKind::Data {
|
||||||
*selected_symbol = Some(section.name.clone());
|
*selected_symbol = Some(SymbolReference {
|
||||||
|
symbol_name: section.name.clone(),
|
||||||
|
section_name: section.name.clone(),
|
||||||
|
});
|
||||||
*current_view = View::DataDiff;
|
*current_view = View::DataDiff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -126,15 +133,11 @@ fn symbol_list_ui(
|
|||||||
ui: &mut Ui,
|
ui: &mut Ui,
|
||||||
obj: &ObjInfo,
|
obj: &ObjInfo,
|
||||||
highlighted_symbol: &mut Option<String>,
|
highlighted_symbol: &mut Option<String>,
|
||||||
selected_symbol: &mut Option<String>,
|
selected_symbol: &mut Option<SymbolReference>,
|
||||||
current_view: &mut View,
|
current_view: &mut View,
|
||||||
reverse_function_order: bool,
|
lower_search: &str,
|
||||||
search: &mut String,
|
|
||||||
config: &ViewConfig,
|
config: &ViewConfig,
|
||||||
) {
|
) {
|
||||||
ui.text_edit_singleline(search);
|
|
||||||
let lower_search = search.to_ascii_lowercase();
|
|
||||||
|
|
||||||
ScrollArea::both().auto_shrink([false, false]).show(ui, |ui| {
|
ScrollArea::both().auto_shrink([false, false]).show(ui, |ui| {
|
||||||
ui.scope(|ui| {
|
ui.scope(|ui| {
|
||||||
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
|
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
|
||||||
@@ -160,9 +163,9 @@ fn symbol_list_ui(
|
|||||||
CollapsingHeader::new(format!("{} ({:x})", section.name, section.size))
|
CollapsingHeader::new(format!("{} ({:x})", section.name, section.size))
|
||||||
.default_open(true)
|
.default_open(true)
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
if section.name == ".text" && reverse_function_order {
|
if section.kind == ObjSectionKind::Code && config.reverse_fn_order {
|
||||||
for symbol in section.symbols.iter().rev() {
|
for symbol in section.symbols.iter().rev() {
|
||||||
if !symbol_matches_search(symbol, &lower_search) {
|
if !symbol_matches_search(symbol, lower_search) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
symbol_ui(
|
symbol_ui(
|
||||||
@@ -177,7 +180,7 @@ fn symbol_list_ui(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for symbol in §ion.symbols {
|
for symbol in §ion.symbols {
|
||||||
if !symbol_matches_search(symbol, &lower_search) {
|
if !symbol_matches_search(symbol, lower_search) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
symbol_ui(
|
symbol_ui(
|
||||||
@@ -209,21 +212,32 @@ fn build_log_ui(ui: &mut Ui, status: &BuildStatus) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn symbol_diff_ui(ui: &mut Ui, view_state: &mut ViewState) {
|
pub fn symbol_diff_ui(ui: &mut Ui, view_state: &mut ViewState) {
|
||||||
if let (Some(result), highlighted_symbol, selected_symbol, current_view, search) = (
|
let (Some(result), highlighted_symbol, selected_symbol, current_view, search) = (
|
||||||
&view_state.build,
|
&view_state.build,
|
||||||
&mut view_state.highlighted_symbol,
|
&mut view_state.highlighted_symbol,
|
||||||
&mut view_state.selected_symbol,
|
&mut view_state.selected_symbol,
|
||||||
&mut view_state.current_view,
|
&mut view_state.current_view,
|
||||||
&mut view_state.search,
|
&mut view_state.search,
|
||||||
) {
|
) else {
|
||||||
StripBuilder::new(ui).size(Size::exact(40.0)).size(Size::remainder()).vertical(
|
return;
|
||||||
|mut strip| {
|
};
|
||||||
strip.strip(|builder| {
|
|
||||||
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| {
|
// Header
|
||||||
strip.cell(|ui| {
|
let available_width = ui.available_width();
|
||||||
|
let column_width = available_width / 2.0;
|
||||||
|
ui.allocate_ui_with_layout(
|
||||||
|
Vec2 { x: available_width, y: 100.0 },
|
||||||
|
Layout::left_to_right(Align::Min),
|
||||||
|
|ui| {
|
||||||
|
// Left column
|
||||||
|
ui.allocate_ui_with_layout(
|
||||||
|
Vec2 { x: column_width, y: 100.0 },
|
||||||
|
Layout::top_down(Align::Min),
|
||||||
|
|ui| {
|
||||||
|
ui.set_width(column_width);
|
||||||
|
|
||||||
ui.scope(|ui| {
|
ui.scope(|ui| {
|
||||||
ui.style_mut().override_text_style =
|
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
|
||||||
Some(egui::TextStyle::Monospace);
|
|
||||||
ui.style_mut().wrap = Some(false);
|
ui.style_mut().wrap = Some(false);
|
||||||
|
|
||||||
ui.label("Build target:");
|
ui.label("Build target:");
|
||||||
@@ -233,12 +247,20 @@ pub fn symbol_diff_ui(ui: &mut Ui, view_state: &mut ViewState) {
|
|||||||
ui.colored_label(Rgba::from_rgb(1.0, 0.0, 0.0), "Fail");
|
ui.colored_label(Rgba::from_rgb(1.0, 0.0, 0.0), "Fail");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ui.separator();
|
|
||||||
});
|
TextEdit::singleline(search).hint_text("Filter symbols").ui(ui);
|
||||||
strip.cell(|ui| {
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// Right column
|
||||||
|
ui.allocate_ui_with_layout(
|
||||||
|
Vec2 { x: column_width, y: 100.0 },
|
||||||
|
Layout::top_down(Align::Min),
|
||||||
|
|ui| {
|
||||||
|
ui.set_width(column_width);
|
||||||
|
|
||||||
ui.scope(|ui| {
|
ui.scope(|ui| {
|
||||||
ui.style_mut().override_text_style =
|
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
|
||||||
Some(egui::TextStyle::Monospace);
|
|
||||||
ui.style_mut().wrap = Some(false);
|
ui.style_mut().wrap = Some(false);
|
||||||
|
|
||||||
ui.label("Build base:");
|
ui.label("Build base:");
|
||||||
@@ -248,10 +270,15 @@ pub fn symbol_diff_ui(ui: &mut Ui, view_state: &mut ViewState) {
|
|||||||
ui.colored_label(Rgba::from_rgb(1.0, 0.0, 0.0), "Fail");
|
ui.colored_label(Rgba::from_rgb(1.0, 0.0, 0.0), "Fail");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
ui.separator();
|
ui.separator();
|
||||||
});
|
|
||||||
});
|
// Table
|
||||||
});
|
let lower_search = search.to_ascii_lowercase();
|
||||||
|
StripBuilder::new(ui).size(Size::remainder()).vertical(|mut strip| {
|
||||||
strip.strip(|builder| {
|
strip.strip(|builder| {
|
||||||
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| {
|
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| {
|
||||||
strip.cell(|ui| {
|
strip.cell(|ui| {
|
||||||
@@ -264,8 +291,7 @@ pub fn symbol_diff_ui(ui: &mut Ui, view_state: &mut ViewState) {
|
|||||||
highlighted_symbol,
|
highlighted_symbol,
|
||||||
selected_symbol,
|
selected_symbol,
|
||||||
current_view,
|
current_view,
|
||||||
view_state.reverse_fn_order,
|
&lower_search,
|
||||||
search,
|
|
||||||
&view_state.view_config,
|
&view_state.view_config,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -284,8 +310,7 @@ pub fn symbol_diff_ui(ui: &mut Ui, view_state: &mut ViewState) {
|
|||||||
highlighted_symbol,
|
highlighted_symbol,
|
||||||
selected_symbol,
|
selected_symbol,
|
||||||
current_view,
|
current_view,
|
||||||
view_state.reverse_fn_order,
|
&lower_search,
|
||||||
search,
|
|
||||||
&view_state.view_config,
|
&view_state.view_config,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -296,7 +321,5 @@ pub fn symbol_diff_ui(ui: &mut Ui, view_state: &mut ViewState) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
});
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user