Compare commits

..

31 Commits

Author SHA1 Message Date
b02e32f2b7 Add dark/light theme toggle (light theme WIP) 2023-07-15 11:17:59 -04:00
c7a326b160 Update all dependencies (again) 2023-07-06 10:37:57 -04:00
100f8f8ac5 Update all dependencies 2023-05-11 02:47:57 -04:00
2f778932a4 Version 0.3.1 2023-02-06 17:40:42 -05:00
42601b4750 Update cwdemangle 2023-02-06 17:40:42 -05:00
636a8e00c5 Fix diffing across mismatched .text sections 2023-02-06 17:40:42 -05:00
Nick Condron
cd46be7726 Simplify common_symbols by using iterators (#28) 2023-01-26 00:19:20 -05:00
Nick Condron
019493f944 Remove LevEditType::Keep variant (#27) 2023-01-22 13:20:50 -05:00
319b1c35c0 Move reverse_fn_order into ViewConfig 2023-01-21 13:01:21 -05:00
634e007cbc Update default configuration 2023-01-21 12:59:46 -05:00
6ee11ca640 Add optional wgpu feature 2023-01-21 12:56:29 -05:00
8278d5d207 Support MIPS PIC relocations 2023-01-21 12:41:41 -05:00
09bbc534bd Remove debug print 2023-01-21 10:52:21 -05:00
fa28352e08 Fix MIPS operands with base 2023-01-21 10:49:47 -05:00
2ab519d361 Update rabbitizer, deny.toml 2023-01-21 01:36:32 -05:00
Nick Condron
3406c76973 Simplify Affix::find (#24)
* Rewrite Affix::find to be much simpler

* Rename Affix::find parameters to not be string

* Remove unused `LevMatchingBlock` struct

* Make `Affix` type simpler
2023-01-21 01:28:33 -05:00
Nick Condron
6afc535fad Replace panic! with Option (#25) 2023-01-21 01:27:37 -05:00
Anghelo Carvajal
ec062bf5ca User rabbitizer crate (#22)
* Start using rabbitizer crate

* Fix reference problem

* bump rabbitizer version
2023-01-21 01:27:09 -05:00
500965aacb Clippy fix 2023-01-21 01:14:16 -05:00
a8c2514377 Changes for egui/object upgrades 2023-01-21 01:13:20 -05:00
4b58f69461 Upgrade all dependencies 2023-01-21 00:54:54 -05:00
cd01b6254c Use rustls on Linux 2023-01-21 00:06:22 -05:00
bea0a0007d Initial support for line number info 2023-01-21 00:03:56 -05:00
ba74d63a99 Fix data diffing 2023-01-17 19:33:31 -05:00
Nick Condron
20dcc50695 Let-else reformatting (#23)
* Use let-else in App::post_rendering

* Use let-else in diff::reloc_eq

* Use let-else in diff::diff_objs

* Use let-else in views::data_diff::data_diff_ui

* Use let-else in views::function_diff::function_diff_ui

* Use let-else in views::function_diff::asm_row_ui

* Use let-else in views::jobs::jobs_ui

* Update rust-version in Cargo.toml
2023-01-16 16:51:40 -05:00
c7b6ec83d7 ci: Update before apt-get install 2023-01-16 10:55:26 -05:00
e2fde3dbce Actually increment the version number 2022-12-12 01:17:03 -05:00
613e84ecf2 Version 0.2.3
- Fix regression when diffing symbols
  across mismatched section indexes
2022-12-10 20:28:01 -05:00
7219e72acf Version 0.2.2
- Add application icon
- Fixes for objects containing multiple
  sections with the same name
2022-12-10 10:34:03 -05:00
d1d6f1101b Version 0.2.1 2022-12-08 01:51:32 -05:00
bc7cce7226 Open "Target" dir for "Select obj" 2022-12-08 01:49:21 -05:00
23 changed files with 3066 additions and 1889 deletions

View File

@@ -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

2933
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,8 +1,8 @@
[package] [package]
name = "objdiff" name = "objdiff"
version = "0.2.0" version = "0.3.4"
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"
@@ -11,40 +11,59 @@ description = """
A local diffing tool for decompilation projects. A local diffing tool for decompilation projects.
""" """
publish = false publish = false
build = "build.rs"
[profile.release] [profile.release]
lto = "thin" lto = "thin"
strip = "debuginfo" strip = "debuginfo"
[features]
default = []
wgpu = ["eframe/wgpu"]
[dependencies] [dependencies]
anyhow = "1.0.66" anyhow = "1.0.71"
bytes = "1.4.0"
cfg-if = "1.0.0" cfg-if = "1.0.0"
const_format = "0.2.30" const_format = "0.2.31"
cwdemangle = { git = "https://github.com/encounter/cwdemangle", rev = "286f3d1d29ee2457db89043782725631845c3e4c" } cwdemangle = "0.1.5"
eframe = { version = "0.19.0", features = ["persistence"] } # , "wgpu" eframe = { version = "0.22.0", features = ["persistence"] }
egui = "0.19.0" egui = "0.22.0"
egui_extras = "0.19.0" egui_extras = "0.22.0"
flagset = "0.4.3" flagset = "0.4.3"
log = "0.4.17" log = "0.4.19"
memmap2 = "0.5.8" memmap2 = "0.7.1"
notify = "5.0.0" notify = "6.0.1"
object = { version = "0.30.0", features = ["read_core", "std", "elf"], default-features = false } object = { version = "0.31.1", features = ["read_core", "std", "elf"], default-features = false }
ppc750cl = { git = "https://github.com/encounter/ppc750cl", rev = "aa631a33de7882c679afca89350898b87cb3ba3f" } png = "0.17.9"
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.7.4"
self_update = "0.32.0" rfd = { version = "0.11.4" } #, default-features = false, features = ['xdg-portal']
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
thiserror = "1.0.37" tempfile = "3.6.0"
time = { version = "0.3.17", features = ["formatting", "local-offset"] } thiserror = "1.0.41"
toml = "0.5.9" time = { version = "0.3.22", features = ["formatting", "local-offset"] }
toml = "0.7.6"
twox-hash = "1.6.3" twox-hash = "1.6.3"
tempfile = "3.3.0" byteorder = "1.4.3"
reqwest = "0.11.13"
# For Linux static binaries, use rustls
[target.'cfg(target_os = "linux")'.dependencies]
reqwest = { version = "0.11.18", default-features = false, features = ["blocking", "json", "rustls"] }
self_update = { version = "0.37.0", default-features = false, features = ["rustls"] }
# For all other platforms, use native TLS
[target.'cfg(not(target_os = "linux"))'.dependencies]
reqwest = "0.11.18"
self_update = "0.37.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 +77,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.71"
vergen = { version = "7.4.3", features = ["build", "cargo", "git"], default-features = false } vergen = { version = "8.2.4", features = ["build", "cargo", "git", "gitcl"] }

BIN
assets/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

BIN
assets/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
assets/icon_64.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

View File

@@ -1,4 +1,10 @@
use anyhow::Result; use anyhow::Result;
use vergen::{vergen, Config}; use vergen::EmitBuilder;
fn main() -> Result<()> { vergen(Config::default()) } fn main() -> Result<()> {
#[cfg(windows)]
{
winres::WindowsResource::new().set_icon("assets/icon.ico").compile()?;
}
EmitBuilder::builder().fail_on_error().all_build().all_cargo().all_git().emit()
}

View File

@@ -48,7 +48,11 @@ 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", "RUSTSEC-2023-0022",
"RUSTSEC-2023-0023",
"RUSTSEC-2023-0024",
"RUSTSEC-2023-0034",
"RUSTSEC-2023-0044",
] ]
# 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 +85,10 @@ allow = [
"Unicode-DFS-2016", "Unicode-DFS-2016",
"Zlib", "Zlib",
"0BSD", "0BSD",
"OFL-1.1",
"LicenseRef-UFL-1.0",
"OpenSSL",
"GPL-3.0",
] ]
# 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 +126,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

View File

@@ -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,48 @@ 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,
pub theme: eframe::Theme,
#[serde(skip)]
pub text_color: Color32, // GRAY
#[serde(skip)]
pub emphasized_text_color: Color32, // LIGHT_GRAY
#[serde(skip)]
pub deemphasized_text_color: Color32, // DARK_GRAY
#[serde(skip)]
pub highlight_color: Color32, // WHITE
#[serde(skip)]
pub replace_color: Color32, // LIGHT_BLUE
#[serde(skip)]
pub insert_color: Color32, // GREEN
#[serde(skip)]
pub delete_color: Color32, // RED
} }
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,
theme: eframe::Theme::Dark,
text_color: Color32::GRAY,
emphasized_text_color: Color32::LIGHT_GRAY,
deemphasized_text_color: Color32::DARK_GRAY,
highlight_color: Color32::WHITE,
replace_color: Color32::LIGHT_BLUE,
insert_color: Color32::GREEN,
delete_color: Color32::from_rgb(200, 40, 41),
} }
} }
} }
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 +119,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 +138,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 +157,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(),
} }
} }
@@ -244,7 +272,7 @@ impl eframe::App for App {
let Self { config, view_state, .. } = self; let Self { config, view_state, .. } = self;
{ {
let config = &view_state.view_config; let config = &mut view_state.view_config;
let mut style = (*ctx.style()).clone(); let mut style = (*ctx.style()).clone();
style.text_styles.insert(TextStyle::Body, FontId { style.text_styles.insert(TextStyle::Body, FontId {
size: (config.ui_font.size * 0.75).floor(), size: (config.ui_font.size * 0.75).floor(),
@@ -257,6 +285,28 @@ impl eframe::App for App {
family: config.ui_font.family.clone(), family: config.ui_font.family.clone(),
}); });
style.text_styles.insert(TextStyle::Monospace, config.code_font.clone()); style.text_styles.insert(TextStyle::Monospace, config.code_font.clone());
match config.theme {
eframe::Theme::Dark => {
style.visuals = egui::Visuals::dark();
config.text_color = Color32::GRAY;
config.emphasized_text_color = Color32::LIGHT_GRAY;
config.deemphasized_text_color = Color32::DARK_GRAY;
config.highlight_color = Color32::WHITE;
config.replace_color = Color32::LIGHT_BLUE;
config.insert_color = Color32::GREEN;
config.delete_color = Color32::from_rgb(200, 40, 41);
}
eframe::Theme::Light => {
style.visuals = egui::Visuals::light();
config.text_color = Color32::GRAY;
config.emphasized_text_color = Color32::DARK_GRAY;
config.deemphasized_text_color = Color32::LIGHT_GRAY;
config.highlight_color = Color32::BLACK;
config.replace_color = Color32::DARK_BLUE;
config.insert_color = Color32::DARK_GREEN;
config.delete_color = Color32::from_rgb(200, 40, 41);
}
}
ctx.set_style(style); ctx.set_style(style);
} }
@@ -318,6 +368,20 @@ impl eframe::App for App {
} }
egui::Window::new("Config").open(&mut view_state.show_config).show(ctx, |ui| { egui::Window::new("Config").open(&mut view_state.show_config).show(ctx, |ui| {
egui::ComboBox::from_label("Theme")
.selected_text(format!("{:?}", view_state.view_config.theme))
.show_ui(ui, |ui| {
ui.selectable_value(
&mut view_state.view_config.theme,
eframe::Theme::Dark,
"Dark",
);
ui.selectable_value(
&mut view_state.view_config.theme,
eframe::Theme::Light,
"Light",
);
});
ui.label("UI font:"); ui.label("UI font:");
egui::introspection::font_id_ui(ui, &mut view_state.view_config.ui_font); egui::introspection::font_id_ui(ui, &mut view_state.view_config.ui_font);
ui.separator(); ui.separator();
@@ -354,15 +418,15 @@ impl eframe::App for App {
{ {
ui.scope(|ui| { ui.scope(|ui| {
ui.style_mut().override_text_style = Some(TextStyle::Monospace); ui.style_mut().override_text_style = Some(TextStyle::Monospace);
ui.colored_label(Color32::LIGHT_BLUE, &demangled); ui.colored_label(view_state.view_config.replace_color, &demangled);
}); });
if ui.button("Copy").clicked() { if ui.button("Copy").clicked() {
ui.output().copied_text = demangled; ui.output_mut(|output| output.copied_text = demangled);
} }
} else { } else {
ui.scope(|ui| { ui.scope(|ui| {
ui.style_mut().override_text_style = Some(TextStyle::Monospace); ui.style_mut().override_text_style = Some(TextStyle::Monospace);
ui.colored_label(Color32::LIGHT_RED, "[invalid]"); ui.colored_label(view_state.view_config.replace_color, "[invalid]");
}); });
} }
}); });
@@ -393,69 +457,64 @@ 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 {
if !handle.is_finished() { continue;
continue; };
} if !handle.is_finished() {
match job.handle.take().unwrap().join() { continue;
Ok(result) => { }
log::info!("Job {} finished", job.id); match job.handle.take().unwrap().join() {
match result { Ok(result) => {
JobResult::None => { log::info!("Job {} finished", job.id);
if let Some(err) = &job.status.read().unwrap().error { match result {
log::error!("{:?}", err); JobResult::None => {
} if let Some(err) = &job.status.read().unwrap().error {
} log::error!("{:?}", err);
JobResult::ObjDiff(state) => {
self.view_state.build = Some(state);
}
JobResult::BinDiff(state) => {
self.view_state.build = Some(Box::new(ObjDiffResult {
first_status: BuildStatus {
success: true,
log: "".to_string(),
},
second_status: BuildStatus {
success: true,
log: "".to_string(),
},
first_obj: Some(state.first_obj),
second_obj: Some(state.second_obj),
time: OffsetDateTime::now_utc(),
}));
}
JobResult::CheckUpdate(state) => {
self.view_state.check_update = Some(state);
}
JobResult::Update(state) => {
if let Ok(mut guard) = self.relaunch_path.lock() {
*guard = Some(state.exe_path);
}
self.should_relaunch = true;
} }
} }
} JobResult::ObjDiff(state) => {
Err(err) => { self.view_state.build = Some(state);
let err = if let Some(msg) = err.downcast_ref::<&'static str>() { }
anyhow::Error::msg(*msg) JobResult::BinDiff(state) => {
} else if let Some(msg) = err.downcast_ref::<String>() { self.view_state.build = Some(Box::new(ObjDiffResult {
anyhow::Error::msg(msg.clone()) first_status: BuildStatus { success: true, log: "".to_string() },
} else { second_status: BuildStatus { success: true, log: "".to_string() },
anyhow::Error::msg("Thread panicked") first_obj: Some(state.first_obj),
}; second_obj: Some(state.second_obj),
let result = job.status.write(); time: OffsetDateTime::now_utc(),
if let Ok(mut guard) = result {
guard.error = Some(err);
} else {
drop(result);
job.status = Arc::new(RwLock::new(JobStatus {
title: "Error".to_string(),
progress_percent: 0.0,
progress_items: None,
status: "".to_string(),
error: Some(err),
})); }));
} }
JobResult::CheckUpdate(state) => {
self.view_state.check_update = Some(state);
}
JobResult::Update(state) => {
if let Ok(mut guard) = self.relaunch_path.lock() {
*guard = Some(state.exe_path);
}
self.should_relaunch = true;
}
}
}
Err(err) => {
let err = if let Some(msg) = err.downcast_ref::<&'static str>() {
anyhow::Error::msg(*msg)
} else if let Some(msg) = err.downcast_ref::<String>() {
anyhow::Error::msg(msg.clone())
} else {
anyhow::Error::msg("Thread panicked")
};
let result = job.status.write();
if let Ok(mut guard) = result {
guard.error = Some(err);
} else {
drop(result);
job.status = Arc::new(RwLock::new(JobStatus {
title: "Error".to_string(),
progress_percent: 0.0,
progress_items: None,
status: "".to_string(),
error: Some(err),
}));
} }
} }
} }
@@ -481,7 +540,7 @@ impl eframe::App for App {
if let Some(project_dir) = &config.project_dir { if let Some(project_dir) = &config.project_dir {
match create_watcher(self.modified.clone(), project_dir) { match create_watcher(self.modified.clone(), project_dir) {
Ok(watcher) => self.watcher = Some(watcher), Ok(watcher) => self.watcher = Some(watcher),
Err(e) => eprintln!("Failed to create watcher: {e}"), Err(e) => log::error!("Failed to create watcher: {e}"),
} }
config.project_dir_change = false; config.project_dir_change = false;
self.modified.store(true, Ordering::Relaxed); self.modified.store(true, Ordering::Relaxed);
@@ -532,7 +591,7 @@ fn create_watcher(
} }
} }
} }
Err(e) => println!("watch error: {e:?}"), Err(e) => log::error!("watch error: {e:?}"),
})?; })?;
watcher.watch(project_dir, RecursiveMode::Recursive)?; watcher.watch(project_dir, RecursiveMode::Recursive)?;
Ok(watcher) Ok(watcher)

View File

@@ -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,
)?, )?,
), ),
}; };
@@ -123,7 +133,6 @@ pub fn diff_code(
right_diff.push(ObjInsDiff::default()); right_diff.push(ObjInsDiff::default());
cur_left = left_iter.next(); cur_left = left_iter.next();
} }
LevEditType::Keep => unreachable!(),
} }
} else { } else {
break; break;
@@ -211,25 +220,25 @@ 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 {
if left.kind != right.kind { return false;
return false; };
if left.kind != right.kind {
return false;
}
let name_matches = left.target.name == right.target.name;
match (&left.target_section, &right.target_section) {
(Some(sl), Some(sr)) => {
// Match if section and name or address match
sl == sr && (name_matches || address_eq(&left.target, &right.target))
} }
let name_matches = left.target.name == right.target.name; (Some(_), None) => false,
match (&left.target_section, &right.target_section) { (None, Some(_)) => {
(Some(sl), Some(sr)) => { // Match if possibly stripped weak symbol
// Match if section and name or address match name_matches && right.target.flags.0.contains(ObjSymbolFlags::Weak)
sl == sr && (name_matches || address_eq(&left.target, &right.target))
}
(Some(_), None) => false,
(None, Some(_)) => {
// Match if possibly stripped weak symbol
name_matches && right.target.flags.0.contains(ObjSymbolFlags::Weak)
}
(None, None) => name_matches,
} }
} else { (None, None) => name_matches,
false
} }
} }
@@ -258,8 +267,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 +323,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 +337,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,53 +362,56 @@ fn compare_ins(
Ok(result) Ok(result)
} }
fn find_section<'a>(obj: &'a mut ObjInfo, name: &str) -> Option<&'a mut ObjSection> { fn find_section_and_symbol(obj: &ObjInfo, name: &str) -> Option<(usize, usize)> {
obj.sections.iter_mut().find(|s| s.name == name) for (section_idx, section) in obj.sections.iter().enumerate() {
} let symbol_idx = match section.symbols.iter().position(|symbol| symbol.name == name) {
Some(symbol_idx) => symbol_idx,
fn find_symbol<'a>(symbols: &'a mut [ObjSymbol], name: &str) -> Option<&'a mut ObjSymbol> { None => continue,
symbols.iter_mut().find(|s| s.name == name) };
return Some((section_idx, symbol_idx));
}
None
} }
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) { 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_section_idx, right_symbol_idx)) =
if let Some(right_symbol) = find_section_and_symbol(right, &left_symbol.name)
find_symbol(&mut right_section.symbols, &left_symbol.name) {
{ let right_section = &mut right.sections[right_section_idx];
left_symbol.diff_symbol = Some(right_symbol.name.clone()); let right_symbol = &mut right_section.symbols[right_symbol_idx];
right_symbol.diff_symbol = Some(left_symbol.name.clone()); left_symbol.diff_symbol = Some(right_symbol.name.clone());
diff_code( right_symbol.diff_symbol = Some(left_symbol.name.clone());
left.architecture, diff_code(
&left_section.data, left.architecture,
&right_section.data, &left_section.data,
left_symbol, &right_section.data,
right_symbol, left_symbol,
&left_section.relocations, right_symbol,
&right_section.relocations, &left_section.relocations,
)?; &right_section.relocations,
} else { &left.line_info,
no_diff_code( &right.line_info,
left.architecture, )?;
&left_section.data, } else {
left_symbol, no_diff_code(
&left_section.relocations, left.architecture,
)?; &left_section.data,
} left_symbol,
&left_section.relocations,
&left.line_info,
)?;
} }
for right_symbol in &mut right_section.symbols { }
if right_symbol.instructions.is_empty() { } else {
no_diff_code( let Some(right_section) =
left.architecture, right.sections.iter_mut().find(|s| s.name == left_section.name)
&right_section.data, else {
right_symbol, continue;
&right_section.relocations, };
)?; if left_section.kind == ObjSectionKind::Data {
}
}
} else if left_section.kind == ObjSectionKind::Data {
diff_data(left_section, right_section); diff_data(left_section, right_section);
// diff_data_symbols(left_section, right_section)?; // diff_data_symbols(left_section, right_section)?;
} else if left_section.kind == ObjSectionKind::Bss { } else if left_section.kind == ObjSectionKind::Bss {
@@ -407,13 +419,26 @@ pub fn diff_objs(left: &mut ObjInfo, right: &mut ObjInfo, _diff_config: &DiffCon
} }
} }
} }
for right_section in right.sections.iter_mut().filter(|s| s.kind == ObjSectionKind::Code) {
for right_symbol in &mut right_section.symbols {
if right_symbol.instructions.is_empty() {
no_diff_code(
right.architecture,
&right_section.data,
right_symbol,
&right_section.relocations,
&right.line_info,
)?;
}
}
}
diff_bss_symbols(&mut left.common, &mut right.common)?; diff_bss_symbols(&mut left.common, &mut right.common)?;
Ok(()) Ok(())
} }
fn diff_bss_symbols(left_symbols: &mut [ObjSymbol], right_symbols: &mut [ObjSymbol]) -> Result<()> { fn diff_bss_symbols(left_symbols: &mut [ObjSymbol], right_symbols: &mut [ObjSymbol]) -> Result<()> {
for left_symbol in left_symbols { for left_symbol in left_symbols {
if let Some(right_symbol) = find_symbol(right_symbols, &left_symbol.name) { if let Some(right_symbol) = right_symbols.iter_mut().find(|s| s.name == left_symbol.name) {
left_symbol.diff_symbol = Some(right_symbol.name.clone()); left_symbol.diff_symbol = Some(right_symbol.name.clone());
right_symbol.diff_symbol = Some(left_symbol.name.clone()); right_symbol.diff_symbol = Some(left_symbol.name.clone());
let percent = if left_symbol.size == right_symbol.size { 100.0 } else { 50.0 }; let percent = if left_symbol.size == right_symbol.size { 100.0 } else { 50.0 };
@@ -500,13 +525,12 @@ fn diff_data(left: &mut ObjSection, right: &mut ObjSection) {
let mut right_diff = Vec::<ObjDataDiff>::new(); let mut right_diff = Vec::<ObjDataDiff>::new();
let mut left_cur = 0usize; let mut left_cur = 0usize;
let mut right_cur = 0usize; let mut right_cur = 0usize;
let mut cur_op = LevEditType::Keep; let mut cur_op = LevEditType::Replace;
let mut cur_left_data = Vec::<u8>::new(); let mut cur_left_data = Vec::<u8>::new();
let mut cur_right_data = Vec::<u8>::new(); let mut cur_right_data = Vec::<u8>::new();
for op in edit_ops { for op in edit_ops {
if cur_op != op.op_type || left_cur < op.first_start || right_cur < op.second_start { if cur_op != op.op_type || left_cur < op.first_start || right_cur < op.second_start {
match cur_op { match cur_op {
LevEditType::Keep => {}
LevEditType::Replace => { LevEditType::Replace => {
let left_data = take(&mut cur_left_data); let left_data = take(&mut cur_left_data);
let right_data = take(&mut cur_right_data); let right_data = take(&mut cur_right_data);
@@ -592,7 +616,6 @@ fn diff_data(left: &mut ObjSection, right: &mut ObjSection) {
cur_left_data.push(left.data[left_cur]); cur_left_data.push(left.data[left_cur]);
left_cur += 1; left_cur += 1;
} }
LevEditType::Keep => unreachable!(),
} }
cur_op = op.op_type; cur_op = op.op_type;
} }
@@ -616,7 +639,6 @@ fn diff_data(left: &mut ObjSection, right: &mut ObjSection) {
// TODO: merge with above // TODO: merge with above
match cur_op { match cur_op {
LevEditType::Keep => {}
LevEditType::Replace => { LevEditType::Replace => {
let left_data = take(&mut cur_left_data); let left_data = take(&mut cur_left_data);
let right_data = take(&mut cur_right_data); let right_data = take(&mut cur_right_data);

View File

@@ -27,7 +27,6 @@
#[derive(Debug, PartialEq, Eq, Copy, Clone)] #[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum LevEditType { pub enum LevEditType {
Keep,
Replace, Replace,
Insert, Insert,
Delete, Delete,
@@ -40,25 +39,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];
@@ -87,98 +76,66 @@ where T: PartialEq {
cache_matrix[current + 1 + p] = x; cache_matrix[current + 1 + p] = x;
} }
} }
editops_from_cost_matrix( editops_from_cost_matrix(matrix_columns, matrix_rows, prefix_len, cache_matrix)
first_string,
second_string,
matrix_columns,
matrix_rows,
prefix_len,
cache_matrix,
)
} }
fn editops_from_cost_matrix<T>( fn editops_from_cost_matrix(
string1: &[T],
string2: &[T],
len1: usize, len1: usize,
len2: usize, len2: usize,
prefix_len: usize, prefix_len: usize,
cache_matrix: Vec<usize>, cache_matrix: Vec<usize>,
) -> Vec<LevEditOp> ) -> Vec<LevEditOp> {
where let mut ops = Vec::with_capacity(cache_matrix[len1 * len2 - 1]);
T: PartialEq,
{
let mut dir = 0; let mut dir = 0;
let mut ops: Vec<LevEditOp> = vec![];
ops.reserve(cache_matrix[len1 * len2 - 1]);
let mut i = len1 - 1; let mut i = len1 - 1;
let mut j = len2 - 1; let mut j = len2 - 1;
let mut p = len1 * len2 - 1; let mut p = len1 * len2 - 1;
// let string1_chars: Vec<char> = string1.chars().collect();
// let string2_chars: Vec<char> = string2.chars().collect();
//TODO this is still pretty ugly //TODO this is still pretty ugly
while i > 0 || j > 0 { while i > 0 || j > 0 {
let current_value = cache_matrix[p]; let current_value = cache_matrix[p];
let op_type; // More than one operation can be possible at a time. We use `dir` to
// decide when ambiguous.
let is_insert = j > 0 && current_value == cache_matrix[p - 1] + 1;
let is_delete = i > 0 && current_value == cache_matrix[p - len2] + 1;
let is_replace = i > 0 && j > 0 && current_value == cache_matrix[p - len2 - 1] + 1;
if dir == -1 && j > 0 && current_value == cache_matrix[p - 1] + 1 { let (op_type, new_dir) = match (dir, is_insert, is_delete, is_replace) {
op_type = LevEditType::Insert; (_, false, false, false) => (None, 0),
} else if dir == 1 && i > 0 && current_value == cache_matrix[p - len2] + 1 { (-1, true, _, _) => (Some(LevEditType::Insert), -1),
op_type = LevEditType::Delete; (1, _, true, _) => (Some(LevEditType::Delete), 1),
} else if i > 0 (_, _, _, true) => (Some(LevEditType::Replace), 0),
&& j > 0 (0, true, _, _) => (Some(LevEditType::Insert), -1),
&& current_value == cache_matrix[p - len2 - 1] (0, _, true, _) => (Some(LevEditType::Delete), 1),
&& string1[i - 1] == string2[j - 1] _ => panic!("something went terribly wrong"),
{
op_type = LevEditType::Keep;
} else if i > 0 && j > 0 && current_value == cache_matrix[p - len2 - 1] + 1 {
op_type = LevEditType::Replace;
}
/* we can't turn directly from -1 to 1, in this case it would be better
* to go diagonally, but check it (dir == 0) */
else if dir == 0 && j > 0 && current_value == cache_matrix[p - 1] + 1 {
op_type = LevEditType::Insert;
} else if dir == 0 && i > 0 && current_value == cache_matrix[p - len2] + 1 {
op_type = LevEditType::Delete;
} else {
panic!("something went terribly wrong");
}
match op_type {
LevEditType::Insert => {
j -= 1;
p -= 1;
dir = -1;
}
LevEditType::Delete => {
i -= 1;
p -= len2;
dir = 1;
}
LevEditType::Replace => {
i -= 1;
j -= 1;
p -= len2 + 1;
dir = 0;
}
LevEditType::Keep => {
i -= 1;
j -= 1;
p -= len2 + 1;
dir = 0;
/* LevEditKeep does not has to be stored */
continue;
}
}; };
let edit_op = match new_dir {
LevEditOp { op_type, first_start: i + prefix_len, second_start: j + prefix_len }; -1 => {
ops.insert(0, edit_op); j -= 1;
p -= 1;
}
1 => {
i -= 1;
p -= len2;
}
0 => {
i -= 1;
j -= 1;
p -= len2 + 1;
}
_ => panic!("something went terribly wrong"),
};
dir = new_dir;
if let Some(op_type) = op_type {
ops.insert(0, LevEditOp {
op_type,
first_start: i + prefix_len,
second_start: j + prefix_len,
});
}
} }
ops ops
@@ -186,73 +143,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,
},
}
} }
} }

View File

@@ -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)?;

View File

@@ -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,13 +37,26 @@ 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 =
// native_options.renderer = eframe::Renderer::Wgpu; eframe::NativeOptions { follow_system_theme: false, ..Default::default() };
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,
Box::new(move |cc| Box::new(objdiff::App::new(cc, utc_offset, exec_path_clone))), Box::new(move |cc| Box::new(objdiff::App::new(cc, utc_offset, exec_path_clone))),
); )
.expect("Failed to run eframe application");
// Attempt to relaunch application from the updated path // Attempt to relaunch application from the updated path
if let Ok(mut guard) = exec_path.lock() { if let Ok(mut guard) = exec_path.lock() {
@@ -35,7 +66,7 @@ fn main() {
let result = exec::Command::new(path) let result = exec::Command::new(path)
.args(&std::env::args().collect::<Vec<String>>()) .args(&std::env::args().collect::<Vec<String>>())
.exec(); .exec();
eprintln!("Failed to relaunch: {result:?}"); log::error!("Failed to relaunch: {result:?}");
} else { } else {
let result = std::process::Command::new(path) let result = std::process::Command::new(path)
.args(std::env::args()) .args(std::env::args())
@@ -43,7 +74,7 @@ fn main() {
.unwrap() .unwrap()
.wait(); .wait();
if let Err(e) = result { if let Err(e) = result {
eprintln!("Failed to relaunch: {:?}", e); log::error!("Failed to relaunch: {:?}", e);
} }
} }
} }

View File

@@ -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,19 +14,19 @@ 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,
} }
} }
fn to_obj_symbol(obj_file: &File<'_>, symbol: &Symbol<'_, '_>, addend: i64) -> Result<ObjSymbol> { fn to_obj_symbol(obj_file: &File<'_>, symbol: &Symbol<'_, '_>, addend: i64) -> Result<ObjSymbol> {
let mut name = symbol.name().context("Failed to process symbol name")?; let mut name = symbol.name().context("Failed to process symbol name")?;
if name.is_empty() { if name.is_empty() {
println!("Found empty sym: {symbol:?}"); log::warn!("Found empty sym: {symbol:?}");
name = "?"; name = "?";
} }
let mut flags = ObjSymbolFlagSet(ObjSymbolFlags::none()); let mut flags = ObjSymbolFlagSet(ObjSymbolFlags::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(),
@@ -133,13 +126,11 @@ fn symbols_by_section(obj_file: &File<'_>, section: &ObjSection) -> Result<Vec<O
} }
fn common_symbols(obj_file: &File<'_>) -> Result<Vec<ObjSymbol>> { fn common_symbols(obj_file: &File<'_>) -> Result<Vec<ObjSymbol>> {
let mut result = Vec::<ObjSymbol>::new(); obj_file
for symbol in obj_file.symbols() { .symbols()
if symbol.is_common() { .filter(Symbol::is_common)
result.push(to_obj_symbol(obj_file, &symbol, 0)?); .map(|symbol| to_obj_symbol(obj_file, &symbol, 0))
} .collect::<Result<Vec<ObjSymbol>>>()
}
Ok(result)
} }
fn find_section_symbol( fn find_section_symbol(
@@ -192,9 +183,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(&section.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 +201,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 +214,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 +238,68 @@ fn relocations_by_section(
} }
_ => None, _ => None,
}; };
// println!("Reloc: {:?}, symbol: {:?}", reloc, symbol); let addend = if reloc.has_implicit_addend() {
let addend = u32::from_be_bytes(
section.data[address as usize..address as usize + 4].try_into()?,
);
match kind {
ObjRelocKind::Absolute => addend as i64,
ObjRelocKind::MipsHi16 => ((addend & 0x0000FFFF) << 16) as i32 as i64,
ObjRelocKind::MipsLo16
| 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 {
reloc.addend()
};
// println!("Reloc: {reloc:?}, symbol: {symbol:?}, addend: {addend:#X}");
let target = match symbol.kind() { let target = match symbol.kind() {
SymbolKind::Text | SymbolKind::Data | SymbolKind::Unknown => { SymbolKind::Text | SymbolKind::Data | SymbolKind::Label | SymbolKind::Unknown => {
to_obj_symbol(obj_file, &symbol, reloc.addend()) to_obj_symbol(obj_file, &symbol, addend)
} }
SymbolKind::Section => { SymbolKind::Section => {
let addend = if reloc.has_implicit_addend() { if addend < 0 {
let addend = u32::from_be_bytes( return Err(anyhow::Error::msg(format!("Negative addend in reloc: {addend}")));
section.data[address as usize..address as usize + 4].try_into()?, }
);
match kind {
ObjRelocKind::Absolute => addend,
ObjRelocKind::MipsHi16 | ObjRelocKind::MipsLo16 => addend & 0x0000FFFF,
ObjRelocKind::Mips26 => (addend & 0x03FFFFFF) * 4,
_ => todo!(),
}
} else {
let addend = reloc.addend();
if addend < 0 {
return Err(anyhow::Error::msg(format!(
"Negative addend in section reloc: {addend}"
)));
}
addend as u32
};
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);
}
log::debug!("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 +321,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)?;

View File

@@ -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),
));
} }
_ => ObjInsArg::MipsArg(op.disassembled.clone()), _ => {
}) args.push(ObjInsArg::MipsArg(op.disassemble(&instruction, None)));
.collect(); }
}
}
let line =
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;
} }

View File

@@ -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 {

View File

@@ -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))

View File

@@ -5,7 +5,7 @@ use std::sync::{Arc, RwLock};
#[cfg(windows)] #[cfg(windows)]
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use const_format::formatcp; use const_format::formatcp;
use egui::{output::OpenUrl, Color32}; use egui::output::OpenUrl;
use self_update::cargo_crate_version; use self_update::cargo_crate_version;
use crate::{ use crate::{
@@ -74,19 +74,21 @@ pub fn config_ui(ui: &mut egui::Ui, config: &Arc<RwLock<AppConfig>>, view_state:
ui.label(formatcp!("Git branch: {}", env!("VERGEN_GIT_BRANCH"))); ui.label(formatcp!("Git branch: {}", env!("VERGEN_GIT_BRANCH")));
ui.label(formatcp!("Git commit: {}", env!("VERGEN_GIT_SHA"))); ui.label(formatcp!("Git commit: {}", env!("VERGEN_GIT_SHA")));
ui.label(formatcp!("Build target: {}", env!("VERGEN_CARGO_TARGET_TRIPLE"))); ui.label(formatcp!("Build target: {}", env!("VERGEN_CARGO_TARGET_TRIPLE")));
ui.label(formatcp!("Build type: {}", env!("VERGEN_CARGO_PROFILE"))); ui.label(formatcp!("Debug: {}", env!("VERGEN_CARGO_DEBUG")));
}); });
if let Some(state) = &view_state.check_update { if let Some(state) = &view_state.check_update {
ui.label(format!("Latest version: {}", state.latest_release.version)); ui.label(format!("Latest version: {}", state.latest_release.version));
if state.update_available { if state.update_available {
ui.colored_label(Color32::LIGHT_GREEN, "Update available"); ui.colored_label(view_state.view_config.insert_color, "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
@@ -94,8 +96,10 @@ pub fn config_ui(ui: &mut egui::Ui, config: &Arc<RwLock<AppConfig>>, view_state:
.on_hover_text_at_pointer("Open a link to the latest release on GitHub") .on_hover_text_at_pointer("Open a link to the latest release on GitHub")
.clicked() .clicked()
{ {
ui.output().open_url = ui.output_mut(|output| {
Some(OpenUrl { url: RELEASE_URL.to_string(), new_tab: true }); output.open_url =
Some(OpenUrl { url: RELEASE_URL.to_string(), new_tab: true })
});
} }
}); });
} }
@@ -183,20 +187,18 @@ 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);
@@ -247,6 +249,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();
} }

View File

@@ -1,20 +1,20 @@
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, 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,
}; };
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) {
@@ -24,17 +24,17 @@ fn data_row_ui(ui: &mut egui::Ui, address: usize, diffs: &[ObjDataDiff], config:
let mut job = LayoutJob::default(); let mut job = LayoutJob::default();
write_text( write_text(
format!("{address:08X}: ").as_str(), format!("{address:08X}: ").as_str(),
Color32::GRAY, config.text_color,
&mut job, &mut job,
config.code_font.clone(), config.code_font.clone(),
); );
let mut cur_addr = 0usize; let mut cur_addr = 0usize;
for diff in diffs { for diff in diffs {
let base_color = match diff.kind { let base_color = match diff.kind {
ObjDataDiffKind::None => Color32::GRAY, ObjDataDiffKind::None => config.text_color,
ObjDataDiffKind::Replace => Color32::LIGHT_BLUE, ObjDataDiffKind::Replace => config.replace_color,
ObjDataDiffKind::Delete => COLOR_RED, ObjDataDiffKind::Delete => config.delete_color,
ObjDataDiffKind::Insert => Color32::GREEN, ObjDataDiffKind::Insert => config.insert_color,
}; };
if diff.data.is_empty() { if diff.data.is_empty() {
let mut str = " ".repeat(diff.len); let mut str = " ".repeat(diff.len);
@@ -58,15 +58,15 @@ fn data_row_ui(ui: &mut egui::Ui, address: usize, diffs: &[ObjDataDiff], config:
let mut str = " ".to_string(); let mut str = " ".to_string();
str.push_str(" ".repeat(n).as_str()); str.push_str(" ".repeat(n).as_str());
str.push_str(" ".repeat(n / 8).as_str()); str.push_str(" ".repeat(n / 8).as_str());
write_text(str.as_str(), Color32::GRAY, &mut job, config.code_font.clone()); write_text(str.as_str(), config.text_color, &mut job, config.code_font.clone());
} }
write_text(" ", Color32::GRAY, &mut job, config.code_font.clone()); write_text(" ", config.text_color, &mut job, config.code_font.clone());
for diff in diffs { for diff in diffs {
let base_color = match diff.kind { let base_color = match diff.kind {
ObjDataDiffKind::None => Color32::GRAY, ObjDataDiffKind::None => config.text_color,
ObjDataDiffKind::Replace => Color32::LIGHT_BLUE, ObjDataDiffKind::Replace => config.replace_color,
ObjDataDiffKind::Delete => COLOR_RED, ObjDataDiffKind::Delete => config.delete_color,
ObjDataDiffKind::Insert => Color32::GREEN, ObjDataDiffKind::Insert => config.insert_color,
}; };
if diff.data.is_empty() { if diff.data.is_empty() {
write_text( write_text(
@@ -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,99 +163,96 @@ 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 {
StripBuilder::new(ui) return rebuild;
.size(Size::exact(20.0)) };
.size(Size::exact(40.0))
.size(Size::remainder()) // Header
.vertical(|mut strip| { let available_width = ui.available_width();
strip.strip(|builder| { let column_width = available_width / 2.0;
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| { ui.allocate_ui_with_layout(
strip.cell(|ui| { Vec2 { x: available_width, y: 100.0 },
ui.horizontal(|ui| { Layout::left_to_right(Align::Min),
if ui.button("Back").clicked() { |ui| {
view_state.current_view = View::SymbolDiff; // Left column
} ui.allocate_ui_with_layout(
}); Vec2 { x: column_width, y: 100.0 },
}); Layout::top_down(Align::Min),
strip.cell(|ui| { |ui| {
ui.horizontal(|ui| { ui.set_width(column_width);
if ui.button("Build").clicked() {
rebuild = true; if ui.button("Back").clicked() {
} 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);
if view_state
.jobs
.iter()
.any(|job| job.job_type == Job::ObjDiff)
{
ui.label("Building...");
} else {
ui.label("Last built:");
let format =
format_description::parse("[hour]:[minute]:[second]")
.unwrap();
ui.label(
result
.time
.to_offset(view_state.utc_offset)
.format(&format)
.unwrap(),
);
}
});
});
});
});
});
strip.strip(|builder| {
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| {
strip.cell(|ui| {
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);
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.label("");
ui.label("Diff base:");
ui.separator();
});
});
});
});
strip.cell(|ui| {
if let (Some(left_obj), Some(right_obj)) =
(&result.first_obj, &result.second_obj)
{
let table = TableBuilder::new(ui)
.striped(false)
.cell_layout(egui::Layout::left_to_right(egui::Align::Min))
.column(Size::relative(0.5))
.column(Size::relative(0.5))
.resizable(false);
data_table_ui(
table,
left_obj,
right_obj,
selected_symbol,
&view_state.view_config,
);
} }
});
}); ui.scope(|ui| {
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false);
ui.colored_label(
view_state.view_config.highlight_color,
&selected_symbol.symbol_name,
);
ui.label("Diff target:");
});
},
);
// 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| {
if ui.button("Build").clicked() {
rebuild = true;
}
ui.scope(|ui| {
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false);
if view_state.jobs.iter().any(|job| job.job_type == Job::ObjDiff) {
ui.label("Building...");
} else {
ui.label("Last built:");
let format =
format_description::parse("[hour]:[minute]:[second]").unwrap();
ui.label(
result
.time
.to_offset(view_state.utc_offset)
.format(&format)
.unwrap(),
);
}
});
});
ui.scope(|ui| {
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false);
ui.label("");
ui.label("Diff base:");
});
},
);
},
);
ui.separator();
// Table
if let (Some(left_obj), Some(right_obj)) = (&result.first_obj, &result.second_obj) {
let available_height = ui.available_height();
let table = TableBuilder::new(ui)
.striped(false)
.cell_layout(Layout::left_to_right(Align::Min))
.columns(Column::exact(column_width).clip(true), 2)
.resizable(false)
.auto_shrink([false, false])
.min_scrolled_height(available_height);
data_table_ui(table, left_obj, right_obj, selected_symbol, &view_state.view_config);
} }
rebuild rebuild
} }

View File

@@ -1,62 +1,96 @@
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,
ObjRelocKind, ObjSymbol, ObjRelocKind, ObjSymbol,
}, },
views::{symbol_diff::match_color_for_symbol, write_text, COLOR_RED}, views::{symbol_diff::match_color_for_symbol, write_text},
}; };
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,
config: &ViewConfig,
) {
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, config.emphasized_text_color, 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);
}
_ => {}
} }
} }
fn write_reloc(reloc: &ObjReloc, color: Color32, job: &mut LayoutJob, font_id: FontId) { fn write_reloc(
reloc: &ObjReloc,
color: Color32,
job: &mut LayoutJob,
font_id: FontId,
config: &ViewConfig,
) {
match reloc.kind { match reloc.kind {
ObjRelocKind::PpcAddr16Lo => { ObjRelocKind::PpcAddr16Lo => {
write_reloc_name(reloc, color, job, font_id.clone()); write_reloc_name(reloc, color, job, font_id.clone(), config);
write_text("@l", color, job, font_id); write_text("@l", color, job, font_id);
} }
ObjRelocKind::PpcAddr16Hi => { ObjRelocKind::PpcAddr16Hi => {
write_reloc_name(reloc, color, job, font_id.clone()); write_reloc_name(reloc, color, job, font_id.clone(), config);
write_text("@h", color, job, font_id); write_text("@h", color, job, font_id);
} }
ObjRelocKind::PpcAddr16Ha => { ObjRelocKind::PpcAddr16Ha => {
write_reloc_name(reloc, color, job, font_id.clone()); write_reloc_name(reloc, color, job, font_id.clone(), config);
write_text("@ha", color, job, font_id); write_text("@ha", color, job, font_id);
} }
ObjRelocKind::PpcEmbSda21 => { ObjRelocKind::PpcEmbSda21 => {
write_reloc_name(reloc, color, job, font_id.clone()); write_reloc_name(reloc, color, job, font_id.clone(), config);
write_text("@sda21", color, job, font_id); write_text("@sda21", color, job, font_id);
} }
ObjRelocKind::MipsHi16 => { ObjRelocKind::MipsHi16 => {
write_text("%hi(", color, job, font_id.clone()); write_text("%hi(", color, job, font_id.clone());
write_reloc_name(reloc, color, job, font_id.clone()); write_reloc_name(reloc, color, job, font_id.clone(), config);
write_text(")", color, job, font_id); write_text(")", color, job, font_id);
} }
ObjRelocKind::MipsLo16 => { ObjRelocKind::MipsLo16 => {
write_text("%lo(", color, job, font_id.clone()); write_text("%lo(", color, job, font_id.clone());
write_reloc_name(reloc, color, job, font_id.clone()); write_reloc_name(reloc, color, job, font_id.clone(), config);
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(), config);
| ObjRelocKind::Mips26 => { write_text(")", color, job, font_id);
write_reloc_name(reloc, color, job, font_id); }
ObjRelocKind::MipsCall16 => {
write_text("%call16(", color, job, font_id.clone());
write_reloc_name(reloc, color, job, font_id.clone(), config);
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(), config);
write_text(")", color, job, font_id);
}
ObjRelocKind::PpcRel24 | ObjRelocKind::PpcRel14 | ObjRelocKind::Mips26 => {
write_reloc_name(reloc, color, job, font_id, config);
}
ObjRelocKind::Absolute | ObjRelocKind::MipsGpRel32 => {
write_text("[INVALID]", color, job, font_id);
} }
}; };
} }
@@ -71,16 +105,16 @@ fn write_ins(
) { ) {
let base_color = match diff_kind { let base_color = match diff_kind {
ObjInsDiffKind::None | ObjInsDiffKind::OpMismatch | ObjInsDiffKind::ArgMismatch => { ObjInsDiffKind::None | ObjInsDiffKind::OpMismatch | ObjInsDiffKind::ArgMismatch => {
Color32::GRAY config.text_color
} }
ObjInsDiffKind::Replace => Color32::LIGHT_BLUE, ObjInsDiffKind::Replace => config.replace_color,
ObjInsDiffKind::Delete => COLOR_RED, ObjInsDiffKind::Delete => config.delete_color,
ObjInsDiffKind::Insert => Color32::GREEN, ObjInsDiffKind::Insert => config.insert_color,
}; };
write_text( write_text(
&format!("{:<11}", ins.mnemonic), &format!("{:<11}", ins.mnemonic),
match diff_kind { match diff_kind {
ObjInsDiffKind::OpMismatch => Color32::LIGHT_BLUE, ObjInsDiffKind::OpMismatch => config.replace_color,
_ => base_color, _ => base_color,
}, },
job, job,
@@ -115,10 +149,22 @@ fn write_ins(
} }
}, },
ObjInsArg::Reloc => { ObjInsArg::Reloc => {
write_reloc(ins.reloc.as_ref().unwrap(), base_color, job, config.code_font.clone()); write_reloc(
ins.reloc.as_ref().unwrap(),
base_color,
job,
config.code_font.clone(),
config,
);
} }
ObjInsArg::RelocWithBase => { ObjInsArg::RelocWithBase => {
write_reloc(ins.reloc.as_ref().unwrap(), base_color, job, config.code_font.clone()); write_reloc(
ins.reloc.as_ref().unwrap(),
base_color,
job,
config.code_font.clone(),
config,
);
write_text("(", base_color, job, config.code_font.clone()); write_text("(", base_color, job, config.code_font.clone());
writing_offset = true; writing_offset = true;
continue; continue;
@@ -131,6 +177,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());
@@ -143,7 +200,7 @@ fn write_ins(
} }
} }
fn ins_hover_ui(ui: &mut egui::Ui, ins: &ObjIns) { fn ins_hover_ui(ui: &mut egui::Ui, ins: &ObjIns, config: &ViewConfig) {
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);
ui.style_mut().wrap = Some(false); ui.style_mut().wrap = Some(false);
@@ -169,13 +226,16 @@ fn ins_hover_ui(ui: &mut egui::Ui, ins: &ObjIns) {
if let Some(reloc) = &ins.reloc { if let Some(reloc) = &ins.reloc {
ui.label(format!("Relocation type: {:?}", reloc.kind)); ui.label(format!("Relocation type: {:?}", reloc.kind));
ui.colored_label(Color32::WHITE, format!("Name: {}", reloc.target.name)); ui.colored_label(config.highlight_color, format!("Name: {}", reloc.target.name));
if let Some(section) = &reloc.target_section { if let Some(section) = &reloc.target_section {
ui.colored_label(Color32::WHITE, format!("Section: {section}")); ui.colored_label(config.highlight_color, format!("Section: {section}"));
ui.colored_label(Color32::WHITE, format!("Address: {:x}", reloc.target.address)); ui.colored_label(
ui.colored_label(Color32::WHITE, format!("Size: {:x}", reloc.target.size)); config.highlight_color,
format!("Address: {:x}", reloc.target.address),
);
ui.colored_label(config.highlight_color, format!("Size: {:x}", reloc.target.size));
} else { } else {
ui.colored_label(Color32::WHITE, "Extern".to_string()); ui.colored_label(config.highlight_color, "Extern".to_string());
} }
} }
}); });
@@ -193,31 +253,31 @@ fn ins_context_menu(ui: &mut egui::Ui, ins: &ObjIns) {
match arg { match arg {
Argument::Uimm(v) => { Argument::Uimm(v) => {
if ui.button(format!("Copy \"{v}\"")).clicked() { if ui.button(format!("Copy \"{v}\"")).clicked() {
ui.output().copied_text = format!("{v}"); ui.output_mut(|output| output.copied_text = format!("{v}"));
ui.close_menu(); ui.close_menu();
} }
if ui.button(format!("Copy \"{}\"", v.0)).clicked() { if ui.button(format!("Copy \"{}\"", v.0)).clicked() {
ui.output().copied_text = format!("{}", v.0); ui.output_mut(|output| output.copied_text = format!("{}", v.0));
ui.close_menu(); ui.close_menu();
} }
} }
Argument::Simm(v) => { Argument::Simm(v) => {
if ui.button(format!("Copy \"{v}\"")).clicked() { if ui.button(format!("Copy \"{v}\"")).clicked() {
ui.output().copied_text = format!("{v}"); ui.output_mut(|output| output.copied_text = format!("{v}"));
ui.close_menu(); ui.close_menu();
} }
if ui.button(format!("Copy \"{}\"", v.0)).clicked() { if ui.button(format!("Copy \"{}\"", v.0)).clicked() {
ui.output().copied_text = format!("{}", v.0); ui.output_mut(|output| output.copied_text = format!("{}", v.0));
ui.close_menu(); ui.close_menu();
} }
} }
Argument::Offset(v) => { Argument::Offset(v) => {
if ui.button(format!("Copy \"{v}\"")).clicked() { if ui.button(format!("Copy \"{v}\"")).clicked() {
ui.output().copied_text = format!("{v}"); ui.output_mut(|output| output.copied_text = format!("{v}"));
ui.close_menu(); ui.close_menu();
} }
if ui.button(format!("Copy \"{}\"", v.0)).clicked() { if ui.button(format!("Copy \"{}\"", v.0)).clicked() {
ui.output().copied_text = format!("{}", v.0); ui.output_mut(|output| output.copied_text = format!("{}", v.0));
ui.close_menu(); ui.close_menu();
} }
} }
@@ -228,21 +288,22 @@ fn ins_context_menu(ui: &mut egui::Ui, ins: &ObjIns) {
if let Some(reloc) = &ins.reloc { if let Some(reloc) = &ins.reloc {
if let Some(name) = &reloc.target.demangled_name { if let Some(name) = &reloc.target.demangled_name {
if ui.button(format!("Copy \"{name}\"")).clicked() { if ui.button(format!("Copy \"{name}\"")).clicked() {
ui.output().copied_text = name.clone(); ui.output_mut(|output| output.copied_text = name.clone());
ui.close_menu(); ui.close_menu();
} }
} }
if ui.button(format!("Copy \"{}\"", reloc.target.name)).clicked() { if ui.button(format!("Copy \"{}\"", reloc.target.name)).clicked() {
ui.output().copied_text = reloc.target.name.clone(); ui.output_mut(|output| output.copied_text = reloc.target.name.clone());
ui.close_menu(); ui.close_menu();
} }
} }
}); });
} }
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,57 +311,64 @@ 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 {
let base_color = match ins_diff.kind { ui.label("");
ObjInsDiffKind::None | ObjInsDiffKind::OpMismatch | ObjInsDiffKind::ArgMismatch => { return;
Color32::GRAY };
}
ObjInsDiffKind::Replace => Color32::LIGHT_BLUE, let base_color = match ins_diff.kind {
ObjInsDiffKind::Delete => COLOR_RED, ObjInsDiffKind::None | ObjInsDiffKind::OpMismatch | ObjInsDiffKind::ArgMismatch => {
ObjInsDiffKind::Insert => Color32::GREEN, config.text_color
}; }
ObjInsDiffKind::Replace => config.replace_color,
ObjInsDiffKind::Delete => config.delete_color,
ObjInsDiffKind::Insert => config.insert_color,
};
let mut pad = 6;
if let Some(line) = ins.line {
let line_str = format!("{line} ");
write_text(&line_str, config.deemphasized_text_color, &mut job, config.code_font.clone());
pad = 12 - line_str.len();
}
write_text(
&format!("{:<1$}", format!("{:x}: ", ins.address - symbol.address as u32), pad),
base_color,
&mut job,
config.code_font.clone(),
);
if let Some(branch) = &ins_diff.branch_from {
write_text( write_text(
&format!("{:<6}", format!("{:x}:", ins.address - symbol.address as u32)), "~> ",
base_color, config.diff_colors[branch.branch_idx % config.diff_colors.len()],
&mut job, &mut job,
config.code_font.clone(), config.code_font.clone(),
); );
if let Some(branch) = &ins_diff.branch_from {
write_text(
"~> ",
config.diff_colors[branch.branch_idx % config.diff_colors.len()],
&mut job,
config.code_font.clone(),
);
} else {
write_text(" ", base_color, &mut job, config.code_font.clone());
}
write_ins(ins, &ins_diff.kind, &ins_diff.arg_diff, symbol.address as u32, &mut job, config);
if let Some(branch) = &ins_diff.branch_to {
write_text(
" ~>",
config.diff_colors[branch.branch_idx % config.diff_colors.len()],
&mut job,
config.code_font.clone(),
);
}
ui.add(Label::new(job).sense(Sense::click()))
.on_hover_ui_at_pointer(|ui| ins_hover_ui(ui, ins))
.context_menu(|ui| ins_context_menu(ui, ins));
} else { } else {
ui.label(""); write_text(" ", base_color, &mut job, config.code_font.clone());
} }
write_ins(ins, &ins_diff.kind, &ins_diff.arg_diff, symbol.address as u32, &mut job, config);
if let Some(branch) = &ins_diff.branch_to {
write_text(
" ~>",
config.diff_colors[branch.branch_idx % config.diff_colors.len()],
&mut job,
config.code_font.clone(),
);
}
ui.add(Label::new(job).sense(Sense::click()))
.on_hover_ui_at_pointer(|ui| ins_hover_ui(ui, ins, config))
.context_menu(|ui| ins_context_menu(ui, ins));
} }
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,113 +389,113 @@ 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 {
StripBuilder::new(ui) return rebuild;
.size(Size::exact(20.0)) };
.size(Size::exact(40.0))
.size(Size::remainder()) // Header
.vertical(|mut strip| { let available_width = ui.available_width();
strip.strip(|builder| { let column_width = available_width / 2.0;
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| { ui.allocate_ui_with_layout(
strip.cell(|ui| { Vec2 { x: available_width, y: 100.0 },
ui.horizontal(|ui| { Layout::left_to_right(Align::Min),
if ui.button("Back").clicked() { |ui| {
view_state.current_view = View::SymbolDiff; // Left column
} ui.allocate_ui_with_layout(
}); Vec2 { x: column_width, y: 100.0 },
}); Layout::top_down(Align::Min),
strip.cell(|ui| { |ui| {
ui.horizontal(|ui| { ui.set_width(column_width);
if ui.button("Build").clicked() {
rebuild = true; if ui.button("Back").clicked() {
} 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);
if view_state
.jobs
.iter()
.any(|job| job.job_type == Job::ObjDiff)
{
ui.label("Building...");
} else {
ui.label("Last built:");
let format =
format_description::parse("[hour]:[minute]:[second]")
.unwrap();
ui.label(
result
.time
.to_offset(view_state.utc_offset)
.format(&format)
.unwrap(),
);
}
});
});
});
});
});
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.style_mut().override_text_style =
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
.second_obj
.as_ref()
.and_then(|obj| find_symbol(obj, ".text", selected_symbol))
.and_then(|symbol| symbol.match_percent)
{
ui.colored_label(
match_color_for_symbol(match_percent),
&format!("{match_percent:.0}%"),
);
}
ui.label("Diff base:");
ui.separator();
});
});
});
});
strip.cell(|ui| {
if let (Some(left_obj), Some(right_obj)) =
(&result.first_obj, &result.second_obj)
{
let table = TableBuilder::new(ui)
.striped(false)
.cell_layout(egui::Layout::left_to_right(egui::Align::Min))
.column(Size::relative(0.5))
.column(Size::relative(0.5))
.resizable(false);
asm_table_ui(
table,
left_obj,
right_obj,
selected_symbol,
&view_state.view_config,
);
} }
});
}); 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(),
view_state.view_config.highlight_color,
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:");
});
},
);
// 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| {
if ui.button("Build").clicked() {
rebuild = true;
}
ui.scope(|ui| {
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false);
if view_state.jobs.iter().any(|job| job.job_type == Job::ObjDiff) {
ui.label("Building...");
} else {
ui.label("Last built:");
let format =
format_description::parse("[hour]:[minute]:[second]").unwrap();
ui.label(
result
.time
.to_offset(view_state.utc_offset)
.format(&format)
.unwrap(),
);
}
});
});
ui.scope(|ui| {
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
if let Some(match_percent) = result
.second_obj
.as_ref()
.and_then(|obj| find_symbol(obj, selected_symbol))
.and_then(|symbol| symbol.match_percent)
{
ui.colored_label(
match_color_for_symbol(match_percent, &view_state.view_config),
&format!("{match_percent:.0}%"),
);
} else {
ui.label("");
}
ui.label("Diff base:");
});
},
);
},
);
ui.separator();
// Table
if let (Some(left_obj), Some(right_obj)) = (&result.first_obj, &result.second_obj) {
let available_height = ui.available_height();
let table = TableBuilder::new(ui)
.striped(false)
.cell_layout(Layout::left_to_right(Align::Min))
.columns(Column::exact(column_width).clip(true), 2)
.resizable(false)
.auto_shrink([false, false])
.min_scrolled_height(available_height);
asm_table_ui(table, left_obj, right_obj, selected_symbol, &view_state.view_config);
} }
rebuild rebuild
} }

View File

@@ -1,4 +1,4 @@
use egui::{Color32, ProgressBar, Widget}; use egui::{ProgressBar, Widget};
use crate::app::ViewState; use crate::app::ViewState;
@@ -7,46 +7,47 @@ 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 {
ui.group(|ui| { continue;
ui.horizontal(|ui| { };
ui.label(&status.title); ui.group(|ui| {
if ui.small_button("").clicked() { ui.horizontal(|ui| {
if job.handle.is_some() { ui.label(&status.title);
job.should_remove = true; if ui.small_button("").clicked() {
if let Err(e) = job.cancel.send(()) { if job.handle.is_some() {
eprintln!("Failed to cancel job: {e:?}"); job.should_remove = true;
} if let Err(e) = job.cancel.send(()) {
} else { log::error!("Failed to cancel job: {e:?}");
remove_job = Some(idx);
} }
}
});
let mut bar = ProgressBar::new(status.progress_percent);
if let Some(items) = &status.progress_items {
bar = bar.text(format!("{} / {}", items[0], items[1]));
}
bar.ui(ui);
const STATUS_LENGTH: usize = 80;
if let Some(err) = &status.error {
let err_string = err.to_string();
ui.colored_label(
Color32::from_rgb(255, 0, 0),
if err_string.len() > STATUS_LENGTH - 10 {
format!("Error: {}...", &err_string[0..STATUS_LENGTH - 10])
} else {
format!("Error: {:width$}", err_string, width = STATUS_LENGTH - 7)
},
);
} else {
ui.label(if status.status.len() > STATUS_LENGTH - 3 {
format!("{}...", &status.status[0..STATUS_LENGTH - 3])
} else { } else {
format!("{:width$}", &status.status, width = STATUS_LENGTH) remove_job = Some(idx);
}); }
} }
}); });
} let mut bar = ProgressBar::new(status.progress_percent);
if let Some(items) = &status.progress_items {
bar = bar.text(format!("{} / {}", items[0], items[1]));
}
bar.ui(ui);
const STATUS_LENGTH: usize = 80;
if let Some(err) = &status.error {
let err_string = err.to_string();
ui.colored_label(
view_state.view_config.delete_color,
if err_string.len() > STATUS_LENGTH - 10 {
format!("Error: {}...", &err_string[0..STATUS_LENGTH - 10])
} else {
format!("Error: {:width$}", err_string, width = STATUS_LENGTH - 7)
},
);
} else {
ui.label(if status.status.len() > STATUS_LENGTH - 3 {
format!("{}...", &status.status[0..STATUS_LENGTH - 3])
} else {
format!("{:width$}", &status.status, width = STATUS_LENGTH)
});
}
});
} }
if let Some(idx) = remove_job { if let Some(idx) = remove_job {

View File

@@ -6,8 +6,6 @@ pub(crate) mod function_diff;
pub(crate) mod jobs; pub(crate) mod jobs;
pub(crate) mod symbol_diff; pub(crate) mod symbol_diff;
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));
} }

View File

@@ -1,22 +1,23 @@
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,
}; };
pub fn match_color_for_symbol(match_percent: f32) -> Color32 { pub fn match_color_for_symbol(match_percent: f32, config: &ViewConfig) -> Color32 {
if match_percent == 100.0 { if match_percent == 100.0 {
Color32::GREEN config.insert_color
} else if match_percent >= 50.0 { } else if match_percent >= 50.0 {
Color32::LIGHT_BLUE config.replace_color
} else { } else {
Color32::RED config.delete_color
} }
} }
@@ -27,28 +28,28 @@ fn symbol_context_menu_ui(ui: &mut Ui, symbol: &ObjSymbol) {
if let Some(name) = &symbol.demangled_name { if let Some(name) = &symbol.demangled_name {
if ui.button(format!("Copy \"{name}\"")).clicked() { if ui.button(format!("Copy \"{name}\"")).clicked() {
ui.output().copied_text = name.clone(); ui.output_mut(|output| output.copied_text = name.clone());
ui.close_menu(); ui.close_menu();
} }
} }
if ui.button(format!("Copy \"{}\"", symbol.name)).clicked() { if ui.button(format!("Copy \"{}\"", symbol.name)).clicked() {
ui.output().copied_text = symbol.name.clone(); ui.output_mut(|output| output.copied_text = symbol.name.clone());
ui.close_menu(); ui.close_menu();
} }
}); });
} }
fn symbol_hover_ui(ui: &mut Ui, symbol: &ObjSymbol) { fn symbol_hover_ui(ui: &mut Ui, symbol: &ObjSymbol, config: &ViewConfig) {
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);
ui.style_mut().wrap = Some(false); ui.style_mut().wrap = Some(false);
ui.colored_label(Color32::WHITE, format!("Name: {}", symbol.name)); ui.colored_label(config.highlight_color, format!("Name: {}", symbol.name));
ui.colored_label(Color32::WHITE, format!("Address: {:x}", symbol.address)); ui.colored_label(config.highlight_color, format!("Address: {:x}", symbol.address));
if symbol.size_known { if symbol.size_known {
ui.colored_label(Color32::WHITE, format!("Size: {:x}", symbol.size)); ui.colored_label(config.highlight_color, format!("Size: {:x}", symbol.size));
} else { } else {
ui.colored_label(Color32::WHITE, format!("Size: {:x} (assumed)", symbol.size)); ui.colored_label(config.highlight_color, format!("Size: {:x} (assumed)", symbol.size));
} }
}); });
} }
@@ -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,
) { ) {
@@ -69,40 +70,51 @@ fn symbol_ui(
if let Some(sym) = highlighted_symbol { if let Some(sym) = highlighted_symbol {
selected = sym == &symbol.name; selected = sym == &symbol.name;
} }
write_text("[", Color32::GRAY, &mut job, config.code_font.clone()); write_text("[", config.text_color, &mut job, config.code_font.clone());
if symbol.flags.0.contains(ObjSymbolFlags::Common) { if symbol.flags.0.contains(ObjSymbolFlags::Common) {
write_text("c", Color32::from_rgb(0, 255, 255), &mut job, config.code_font.clone());
} else if symbol.flags.0.contains(ObjSymbolFlags::Global) {
write_text("g", Color32::GREEN, &mut job, config.code_font.clone());
} else if symbol.flags.0.contains(ObjSymbolFlags::Local) {
write_text("l", Color32::GRAY, &mut job, config.code_font.clone());
}
if symbol.flags.0.contains(ObjSymbolFlags::Weak) {
write_text("w", Color32::GRAY, &mut job, config.code_font.clone());
}
write_text("] ", Color32::GRAY, &mut job, config.code_font.clone());
if let Some(match_percent) = symbol.match_percent {
write_text("(", Color32::GRAY, &mut job, config.code_font.clone());
write_text( write_text(
&format!("{match_percent:.0}%"), "c",
match_color_for_symbol(match_percent), config.replace_color, /* Color32::from_rgb(0, 255, 255) */
&mut job, &mut job,
config.code_font.clone(), config.code_font.clone(),
); );
write_text(") ", Color32::GRAY, &mut job, config.code_font.clone()); } else if symbol.flags.0.contains(ObjSymbolFlags::Global) {
write_text("g", config.insert_color, &mut job, config.code_font.clone());
} else if symbol.flags.0.contains(ObjSymbolFlags::Local) {
write_text("l", config.text_color, &mut job, config.code_font.clone());
} }
write_text(name, Color32::WHITE, &mut job, config.code_font.clone()); if symbol.flags.0.contains(ObjSymbolFlags::Weak) {
write_text("w", config.text_color, &mut job, config.code_font.clone());
}
write_text("] ", config.text_color, &mut job, config.code_font.clone());
if let Some(match_percent) = symbol.match_percent {
write_text("(", config.text_color, &mut job, config.code_font.clone());
write_text(
&format!("{match_percent:.0}%"),
match_color_for_symbol(match_percent, config),
&mut job,
config.code_font.clone(),
);
write_text(") ", config.text_color, &mut job, config.code_font.clone());
}
write_text(name, config.highlight_color, &mut job, config.code_font.clone());
let response = SelectableLabel::new(selected, job) let response = SelectableLabel::new(selected, job)
.ui(ui) .ui(ui)
.context_menu(|ui| symbol_context_menu_ui(ui, symbol)) .context_menu(|ui| symbol_context_menu_ui(ui, symbol))
.on_hover_ui_at_pointer(|ui| symbol_hover_ui(ui, symbol)); .on_hover_ui_at_pointer(|ui| symbol_hover_ui(ui, symbol, config));
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 +138,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 +168,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 +185,7 @@ fn symbol_list_ui(
} }
} else { } else {
for symbol in &section.symbols { for symbol in &section.symbols {
if !symbol_matches_search(symbol, &lower_search) { if !symbol_matches_search(symbol, lower_search) {
continue; continue;
} }
symbol_ui( symbol_ui(
@@ -197,106 +205,126 @@ fn symbol_list_ui(
}); });
} }
fn build_log_ui(ui: &mut Ui, status: &BuildStatus) { fn build_log_ui(ui: &mut Ui, status: &BuildStatus, config: &ViewConfig) {
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);
ui.style_mut().wrap = Some(false); ui.style_mut().wrap = Some(false);
ui.colored_label(Color32::from_rgb(255, 0, 0), &status.log); ui.colored_label(config.replace_color, &status.log);
}); });
}); });
} }
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| {
strip.cell(|ui| {
ui.scope(|ui| {
ui.style_mut().override_text_style =
Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false);
ui.label("Build target:"); // Header
if result.first_status.success { let available_width = ui.available_width();
ui.label("OK"); let column_width = available_width / 2.0;
} else { ui.allocate_ui_with_layout(
ui.colored_label(Rgba::from_rgb(1.0, 0.0, 0.0), "Fail"); Vec2 { x: available_width, y: 100.0 },
} Layout::left_to_right(Align::Min),
}); |ui| {
ui.separator(); // Left column
}); ui.allocate_ui_with_layout(
strip.cell(|ui| { Vec2 { x: column_width, y: 100.0 },
ui.scope(|ui| { Layout::top_down(Align::Min),
ui.style_mut().override_text_style = |ui| {
Some(egui::TextStyle::Monospace); ui.set_width(column_width);
ui.style_mut().wrap = Some(false);
ui.label("Build base:"); ui.scope(|ui| {
if result.second_status.success { ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
ui.label("OK"); ui.style_mut().wrap = Some(false);
} else {
ui.colored_label(Rgba::from_rgb(1.0, 0.0, 0.0), "Fail"); ui.label("Build target:");
} if result.first_status.success {
}); ui.label("OK");
ui.separator(); } else {
}); ui.colored_label(Rgba::from_rgb(1.0, 0.0, 0.0), "Fail");
}
});
TextEdit::singleline(search).hint_text("Filter symbols").ui(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.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false);
ui.label("Build base:");
if result.second_status.success {
ui.label("OK");
} else {
ui.colored_label(Rgba::from_rgb(1.0, 0.0, 0.0), "Fail");
}
});
},
);
},
);
ui.separator();
// Table
let lower_search = search.to_ascii_lowercase();
StripBuilder::new(ui).size(Size::remainder()).vertical(|mut strip| {
strip.strip(|builder| {
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| {
strip.cell(|ui| {
ui.push_id("left", |ui| {
if result.first_status.success {
if let Some(obj) = &result.first_obj {
symbol_list_ui(
ui,
obj,
highlighted_symbol,
selected_symbol,
current_view,
&lower_search,
&view_state.view_config,
);
}
} else {
build_log_ui(ui, &result.first_status, &view_state.view_config);
}
}); });
}); });
strip.strip(|builder| { strip.cell(|ui| {
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| { ui.push_id("right", |ui| {
strip.cell(|ui| { if result.second_status.success {
if result.first_status.success { if let Some(obj) = &result.second_obj {
if let Some(obj) = &result.first_obj { symbol_list_ui(
ui.push_id("left", |ui| { ui,
symbol_list_ui( obj,
ui, highlighted_symbol,
obj, selected_symbol,
highlighted_symbol, current_view,
selected_symbol, &lower_search,
current_view, &view_state.view_config,
view_state.reverse_fn_order, );
search,
&view_state.view_config,
);
});
}
} else {
build_log_ui(ui, &result.first_status);
} }
}); } else {
strip.cell(|ui| { build_log_ui(ui, &result.second_status, &view_state.view_config);
if result.second_status.success { }
if let Some(obj) = &result.second_obj {
ui.push_id("right", |ui| {
symbol_list_ui(
ui,
obj,
highlighted_symbol,
selected_symbol,
current_view,
view_state.reverse_fn_order,
search,
&view_state.view_config,
);
});
}
} else {
build_log_ui(ui, &result.second_status);
}
});
}); });
}); });
}, });
); });
} });
} }