Compare commits

..

8 Commits

Author SHA1 Message Date
bb9ff4b928 Update all dependencies 2023-10-05 23:55:01 -04:00
57392daaeb Implement click-to-highlight
Highlights registers, instructions, arguments, symbols or addresses on click.

Resolves #7
2023-10-05 23:40:45 -04:00
2dd3dd60a8 Update webpki (advisory fix) 2023-10-05 00:01:09 -04:00
f4757b8d92 Version 0.4.4
Add `#[serde(default)]` to new AppConfig field
2023-10-04 23:52:00 -04:00
52f8c5d4f9 Add "Recent Projects" to file menu 2023-10-03 13:52:16 -04:00
711f40b591 I forgot to bump the Cargo.toml version, oops 2023-09-10 00:24:53 -04:00
26932b2e44 Support min_version field in objdiff.json 2023-09-09 23:54:25 -04:00
192a06bc0b Project configuration improvements
- Support `completed` field for objects in project config. In object tree, displays red for incomplete, green for complete.
- Add support for one-sided diffs. A project can include objects without an associated source file for viewing.
- Add versioning to AppConfig, supporting upgrades without losing user configuration.
2023-09-09 23:43:12 -04:00
15 changed files with 1320 additions and 666 deletions

866
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,8 +1,8 @@
[package]
name = "objdiff"
version = "0.4.1"
version = "0.5.0"
edition = "2021"
rust-version = "1.65"
rust-version = "1.70"
authors = ["Luke Street <luke@street.dev>"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/encounter/objdiff"
@@ -22,44 +22,46 @@ default = []
wgpu = ["eframe/wgpu"]
[dependencies]
anyhow = "1.0.71"
byteorder = "1.4.3"
bytes = "1.4.0"
anyhow = "1.0.75"
byteorder = "1.5.0"
bytes = "1.5.0"
cfg-if = "1.0.0"
const_format = "0.2.31"
cwdemangle = "0.1.6"
dirs = "5.0.1"
eframe = { version = "0.22.0", features = ["persistence"] }
egui = "0.22.0"
egui_extras = "0.22.0"
flagset = "0.4.3"
eframe = { version = "0.23.0", features = ["persistence"] }
egui = "0.23.0"
egui_extras = "0.23.0"
flagset = "0.4.4"
globset = { version = "0.4.13", features = ["serde1"] }
log = "0.4.19"
memmap2 = "0.7.1"
notify = "6.0.1"
object = { version = "0.31.1", features = ["read_core", "std", "elf"], default-features = false }
png = "0.17.9"
log = "0.4.20"
memmap2 = "0.9.0"
notify = "6.1.1"
object = { version = "0.32.1", features = ["read_core", "std", "elf"], default-features = false }
png = "0.17.10"
ppc750cl = { git = "https://github.com/terorie/ppc750cl", rev = "9ae36eef34aa6d74e00972c7671f547a2acfd0aa" }
rabbitizer = "1.7.4"
rfd = { version = "0.11.4" } #, default-features = false, features = ['xdg-portal']
rabbitizer = "1.7.10"
rfd = { version = "0.12.0" } #, default-features = false, features = ['xdg-portal']
ron = "0.8.1"
semver = "1.0.19"
serde = { version = "1", features = ["derive"] }
serde_json = "1.0.104"
serde_json = "1.0.107"
serde_yaml = "0.9.25"
tempfile = "3.6.0"
thiserror = "1.0.41"
time = { version = "0.3.22", features = ["formatting", "local-offset"] }
toml = "0.7.6"
tempfile = "3.8.0"
thiserror = "1.0.49"
time = { version = "0.3.29", features = ["formatting", "local-offset"] }
toml = "0.8.2"
twox-hash = "1.6.3"
# 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"] }
reqwest = { version = "0.11.22", default-features = false, features = ["blocking", "json", "rustls"] }
self_update = { version = "0.38.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"
reqwest = "0.11.22"
self_update = "0.38.0"
[target.'cfg(windows)'.dependencies]
path-slash = "0.2.1"
@@ -81,5 +83,5 @@ console_error_panic_hook = "0.1.7"
tracing-wasm = "0.2"
[build-dependencies]
anyhow = "1.0.71"
vergen = { version = "8.2.4", features = ["build", "cargo", "git", "gitcl"] }
anyhow = "1.0.75"
vergen = { version = "8.2.5", features = ["build", "cargo", "git", "gitcl"] }

View File

@@ -14,13 +14,14 @@ use notify::{RecursiveMode, Watcher};
use time::UtcOffset;
use crate::{
app_config::{deserialize_config, AppConfigVersion},
config::{
build_globset, load_project_config, ProjectObject, ProjectObjectNode, CONFIG_FILENAMES,
},
jobs::{objdiff::start_build, Job, JobQueue, JobResult, JobStatus},
views::{
appearance::{appearance_window, Appearance},
config::{config_ui, project_window, ConfigViewState},
config::{config_ui, project_window, ConfigViewState, DEFAULT_WATCH_PATTERNS},
data_diff::data_diff_ui,
demangle::{demangle_window, DemangleViewState},
function_diff::function_diff_ui,
@@ -44,27 +45,48 @@ pub struct ViewState {
#[derive(Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct ObjectConfig {
pub name: String,
pub target_path: PathBuf,
pub base_path: PathBuf,
pub target_path: Option<PathBuf>,
pub base_path: Option<PathBuf>,
pub reverse_fn_order: Option<bool>,
pub complete: Option<bool>,
}
#[inline]
fn bool_true() -> bool { true }
#[derive(Default, Clone, serde::Deserialize, serde::Serialize)]
#[inline]
fn default_watch_patterns() -> Vec<Glob> {
DEFAULT_WATCH_PATTERNS.iter().map(|s| Glob::new(s).unwrap()).collect()
}
#[derive(Clone, serde::Deserialize, serde::Serialize)]
pub struct AppConfig {
// TODO: https://github.com/ron-rs/ron/pull/455
// #[serde(flatten)]
// pub version: AppConfigVersion,
pub version: u32,
#[serde(default)]
pub custom_make: Option<String>,
#[serde(default)]
pub selected_wsl_distro: Option<String>,
#[serde(default)]
pub project_dir: Option<PathBuf>,
#[serde(default)]
pub target_obj_dir: Option<PathBuf>,
#[serde(default)]
pub base_obj_dir: Option<PathBuf>,
#[serde(default)]
pub selected_obj: Option<ObjectConfig>,
#[serde(default)]
pub build_target: bool,
#[serde(default = "bool_true")]
pub rebuild_on_changes: bool,
#[serde(default)]
pub auto_update_check: bool,
#[serde(default = "default_watch_patterns")]
pub watch_patterns: Vec<Glob>,
#[serde(default)]
pub recent_projects: Vec<PathBuf>,
#[serde(skip)]
pub objects: Vec<ProjectObject>,
@@ -82,8 +104,39 @@ pub struct AppConfig {
pub project_config_loaded: bool,
}
impl Default for AppConfig {
fn default() -> Self {
Self {
version: AppConfigVersion::default().version,
custom_make: None,
selected_wsl_distro: None,
project_dir: None,
target_obj_dir: None,
base_obj_dir: None,
selected_obj: None,
build_target: false,
rebuild_on_changes: true,
auto_update_check: true,
watch_patterns: DEFAULT_WATCH_PATTERNS.iter().map(|s| Glob::new(s).unwrap()).collect(),
recent_projects: vec![],
objects: vec![],
object_nodes: vec![],
watcher_change: false,
config_change: false,
obj_change: false,
queue_build: false,
project_config_loaded: false,
}
}
}
impl AppConfig {
pub fn set_project_dir(&mut self, path: PathBuf) {
self.recent_projects.retain(|p| p != &path);
if self.recent_projects.len() > 9 {
self.recent_projects.truncate(9);
}
self.recent_projects.insert(0, path.clone());
self.project_dir = Some(path);
self.target_obj_dir = None;
self.base_obj_dir = None;
@@ -133,8 +186,8 @@ pub struct App {
should_relaunch: bool,
}
const APPEARANCE_KEY: &str = "appearance";
const CONFIG_KEY: &str = "app_config";
pub const APPEARANCE_KEY: &str = "appearance";
pub const CONFIG_KEY: &str = "app_config";
impl App {
/// Called once before the first frame.
@@ -153,7 +206,7 @@ impl App {
if let Some(appearance) = eframe::get_value::<Appearance>(storage, APPEARANCE_KEY) {
app.appearance = appearance;
}
if let Some(mut config) = eframe::get_value::<AppConfig>(storage, CONFIG_KEY) {
if let Some(mut config) = deserialize_config(storage) {
if config.project_dir.is_some() {
config.config_change = true;
config.watcher_change = true;
@@ -320,6 +373,23 @@ impl eframe::App for App {
egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
egui::menu::bar(ui, |ui| {
ui.menu_button("File", |ui| {
let recent_projects = if let Ok(guard) = config.read() {
guard.recent_projects.clone()
} else {
vec![]
};
if recent_projects.is_empty() {
ui.add_enabled(false, egui::Button::new("Recent Projects…"));
} else {
ui.menu_button("Recent Projects…", |ui| {
for path in recent_projects {
if ui.button(format!("{}", path.display())).clicked() {
config.write().unwrap().set_project_dir(path);
ui.close_menu();
}
}
});
}
if ui.button("Appearance…").clicked() {
*show_appearance_config = !*show_appearance_config;
ui.close_menu();

96
src/app_config.rs Normal file
View File

@@ -0,0 +1,96 @@
use std::path::PathBuf;
use eframe::Storage;
use globset::Glob;
use crate::app::{AppConfig, ObjectConfig, CONFIG_KEY};
#[derive(Clone, serde::Deserialize, serde::Serialize)]
pub struct AppConfigVersion {
pub version: u32,
}
impl Default for AppConfigVersion {
fn default() -> Self { Self { version: 1 } }
}
/// Deserialize the AppConfig from storage, handling upgrades from older versions.
pub fn deserialize_config(storage: &dyn Storage) -> Option<AppConfig> {
let str = storage.get_string(CONFIG_KEY)?;
match ron::from_str::<AppConfigVersion>(&str) {
Ok(version) => match version.version {
1 => from_str::<AppConfig>(&str),
_ => {
log::warn!("Unknown config version: {}", version.version);
None
}
},
Err(e) => {
log::warn!("Failed to decode config version: {e}");
// Try to decode as v0
from_str::<AppConfigV0>(&str).map(|c| c.into_config())
}
}
}
fn from_str<T>(str: &str) -> Option<T>
where T: serde::de::DeserializeOwned {
match ron::from_str(str) {
Ok(config) => Some(config),
Err(err) => {
log::warn!("Failed to decode config: {err}");
None
}
}
}
#[derive(serde::Deserialize, serde::Serialize)]
pub struct ObjectConfigV0 {
pub name: String,
pub target_path: PathBuf,
pub base_path: PathBuf,
pub reverse_fn_order: Option<bool>,
}
impl ObjectConfigV0 {
fn into_config(self) -> ObjectConfig {
ObjectConfig {
name: self.name,
target_path: Some(self.target_path),
base_path: Some(self.base_path),
reverse_fn_order: self.reverse_fn_order,
complete: None,
}
}
}
#[derive(serde::Deserialize, serde::Serialize)]
pub struct AppConfigV0 {
pub custom_make: Option<String>,
pub selected_wsl_distro: Option<String>,
pub project_dir: Option<PathBuf>,
pub target_obj_dir: Option<PathBuf>,
pub base_obj_dir: Option<PathBuf>,
pub selected_obj: Option<ObjectConfigV0>,
pub build_target: bool,
pub auto_update_check: bool,
pub watch_patterns: Vec<Glob>,
}
impl AppConfigV0 {
fn into_config(self) -> AppConfig {
log::info!("Upgrading configuration from v0");
AppConfig {
custom_make: self.custom_make,
selected_wsl_distro: self.selected_wsl_distro,
project_dir: self.project_dir,
target_obj_dir: self.target_obj_dir,
base_obj_dir: self.base_obj_dir,
selected_obj: self.selected_obj.map(|obj| obj.into_config()),
build_target: self.build_target,
auto_update_check: self.auto_update_check,
watch_patterns: self.watch_patterns,
..Default::default()
}
}
}

View File

@@ -3,7 +3,7 @@ use std::{
path::{Component, Path, PathBuf},
};
use anyhow::{Context, Result};
use anyhow::{bail, Context, Result};
use globset::{Glob, GlobSet, GlobSetBuilder};
use crate::{app::AppConfig, views::config::DEFAULT_WATCH_PATTERNS};
@@ -11,6 +11,7 @@ use crate::{app::AppConfig, views::config::DEFAULT_WATCH_PATTERNS};
#[derive(Default, Clone, serde::Deserialize)]
#[serde(default)]
pub struct ProjectConfig {
pub min_version: Option<String>,
pub custom_make: Option<String>,
pub target_dir: Option<PathBuf>,
pub base_dir: Option<PathBuf>,
@@ -27,6 +28,7 @@ pub struct ProjectObject {
pub target_path: Option<PathBuf>,
pub base_path: Option<PathBuf>,
pub reverse_fn_order: Option<bool>,
pub complete: Option<bool>,
}
impl ProjectObject {
@@ -120,6 +122,14 @@ pub fn load_project_config(config: &mut AppConfig) -> Result<()> {
};
if let Some(result) = try_project_config(project_dir) {
let project_config = result?;
if let Some(min_version) = &project_config.min_version {
let version_str = env!("CARGO_PKG_VERSION");
let version = semver::Version::parse(version_str).unwrap();
let version_req = semver::VersionReq::parse(&format!(">={min_version}"))?;
if !version_req.matches(&version) {
bail!("Project requires objdiff version {} or higher", min_version);
}
}
config.custom_make = project_config.custom_make;
config.target_obj_dir = project_config.target_dir.map(|p| project_dir.join(p));
config.base_obj_dir = project_config.base_dir.map(|p| project_dir.join(p));

View File

@@ -372,66 +372,80 @@ fn find_section_and_symbol(obj: &ObjInfo, name: &str) -> Option<(usize, usize)>
None
}
pub fn diff_objs(left: &mut ObjInfo, right: &mut ObjInfo) -> Result<()> {
for left_section in &mut left.sections {
if left_section.kind == ObjSectionKind::Code {
for left_symbol in &mut left_section.symbols {
if let Some((right_section_idx, right_symbol_idx)) =
find_section_and_symbol(right, &left_symbol.name)
{
let right_section = &mut right.sections[right_section_idx];
let right_symbol = &mut right_section.symbols[right_symbol_idx];
left_symbol.diff_symbol = Some(right_symbol.name.clone());
right_symbol.diff_symbol = Some(left_symbol.name.clone());
diff_code(
left.architecture,
&left_section.data,
&right_section.data,
left_symbol,
right_symbol,
&left_section.relocations,
&right_section.relocations,
&left.line_info,
&right.line_info,
)?;
} else {
no_diff_code(
left.architecture,
&left_section.data,
left_symbol,
&left_section.relocations,
&left.line_info,
)?;
pub fn diff_objs(mut left: Option<&mut ObjInfo>, mut right: Option<&mut ObjInfo>) -> Result<()> {
if let Some(left) = left.as_mut() {
for left_section in &mut left.sections {
if left_section.kind == ObjSectionKind::Code {
for left_symbol in &mut left_section.symbols {
if let Some((right, (right_section_idx, right_symbol_idx))) =
right.as_mut().and_then(|obj| {
find_section_and_symbol(obj, &left_symbol.name).map(|s| (obj, s))
})
{
let right_section = &mut right.sections[right_section_idx];
let right_symbol = &mut right_section.symbols[right_symbol_idx];
left_symbol.diff_symbol = Some(right_symbol.name.clone());
right_symbol.diff_symbol = Some(left_symbol.name.clone());
diff_code(
left.architecture,
&left_section.data,
&right_section.data,
left_symbol,
right_symbol,
&left_section.relocations,
&right_section.relocations,
&left.line_info,
&right.line_info,
)?;
} else {
no_diff_code(
left.architecture,
&left_section.data,
left_symbol,
&left_section.relocations,
&left.line_info,
)?;
}
}
}
} else {
let Some(right_section) =
right.sections.iter_mut().find(|s| s.name == left_section.name)
else {
continue;
};
if left_section.kind == ObjSectionKind::Data {
diff_data(left_section, right_section);
// diff_data_symbols(left_section, right_section)?;
} else if left_section.kind == ObjSectionKind::Bss {
diff_bss_symbols(&mut left_section.symbols, &mut right_section.symbols)?;
} else if let Some(right_section) = right
.as_mut()
.and_then(|obj| obj.sections.iter_mut().find(|s| s.name == left_section.name))
{
if left_section.kind == ObjSectionKind::Data {
diff_data(left_section, right_section);
// diff_data_symbols(left_section, right_section)?;
} else if left_section.kind == ObjSectionKind::Bss {
diff_bss_symbols(&mut left_section.symbols, &mut right_section.symbols)?;
}
} else if left_section.kind == ObjSectionKind::Data {
no_diff_data(left_section);
}
}
}
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,
)?;
if let Some(right) = right.as_mut() {
for right_section in right.sections.iter_mut() {
if right_section.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,
)?;
}
}
} else if right_section.kind == ObjSectionKind::Data
&& right_section.data_diff.is_empty()
{
no_diff_data(right_section);
}
}
}
diff_bss_symbols(&mut left.common, &mut right.common)?;
if let (Some(left), Some(right)) = (left, right) {
diff_bss_symbols(&mut left.common, &mut right.common)?;
}
Ok(())
}
@@ -710,3 +724,12 @@ fn diff_data(left: &mut ObjSection, right: &mut ObjSection) {
left.data_diff = left_diff;
right.data_diff = right_diff;
}
fn no_diff_data(section: &mut ObjSection) {
section.data_diff = vec![ObjDataDiff {
data: section.data.clone(),
kind: ObjDataDiffKind::None,
len: section.data.len(),
symbol: String::new(),
}];
}

View File

@@ -79,56 +79,101 @@ fn run_build(
let obj_config = config.selected_obj.as_ref().ok_or_else(|| Error::msg("Missing obj path"))?;
let project_dir =
config.project_dir.as_ref().ok_or_else(|| Error::msg("Missing project dir"))?;
let target_path_rel = obj_config.target_path.strip_prefix(project_dir).map_err(|_| {
anyhow!(
"Target path '{}' doesn't begin with '{}'",
obj_config.target_path.display(),
project_dir.display()
)
})?;
let base_path_rel = obj_config.base_path.strip_prefix(project_dir).map_err(|_| {
anyhow!(
"Base path '{}' doesn't begin with '{}'",
obj_config.base_path.display(),
project_dir.display()
)
})?;
let target_path_rel = if let Some(target_path) = &obj_config.target_path {
Some(target_path.strip_prefix(project_dir).map_err(|_| {
anyhow!(
"Target path '{}' doesn't begin with '{}'",
target_path.display(),
project_dir.display()
)
})?)
} else {
None
};
let base_path_rel = if let Some(base_path) = &obj_config.base_path {
Some(base_path.strip_prefix(project_dir).map_err(|_| {
anyhow!(
"Base path '{}' doesn't begin with '{}'",
base_path.display(),
project_dir.display()
)
})?)
} else {
None
};
let total = if config.build_target { 5 } else { 4 };
let first_status = if config.build_target {
update_status(status, format!("Building target {}", target_path_rel.display()), 0, total, &cancel)?;
run_make(project_dir, target_path_rel, &config)
let mut total = 3;
if config.build_target && target_path_rel.is_some() {
total += 1;
}
if base_path_rel.is_some() {
total += 1;
}
let first_status = match target_path_rel {
Some(target_path_rel) if config.build_target => {
update_status(
status,
format!("Building target {}", target_path_rel.display()),
0,
total,
&cancel,
)?;
run_make(project_dir, target_path_rel, &config)
}
_ => BuildStatus { success: true, log: String::new() },
};
let second_status = if let Some(base_path_rel) = base_path_rel {
update_status(
status,
format!("Building base {}", base_path_rel.display()),
1,
total,
&cancel,
)?;
run_make(project_dir, base_path_rel, &config)
} else {
BuildStatus { success: true, log: String::new() }
};
update_status(status, format!("Building base {}", base_path_rel.display()), 1, total, &cancel)?;
let second_status = run_make(project_dir, base_path_rel, &config);
let time = OffsetDateTime::now_utc();
let mut first_obj = if first_status.success {
update_status(status, format!("Loading target {}", target_path_rel.display()), 2, total, &cancel)?;
Some(elf::read(&obj_config.target_path).with_context(|| {
format!("Failed to read object '{}'", obj_config.target_path.display())
})?)
} else {
None
let mut first_obj =
match &obj_config.target_path {
Some(target_path) if first_status.success => {
update_status(
status,
format!("Loading target {}", target_path_rel.unwrap().display()),
2,
total,
&cancel,
)?;
Some(elf::read(target_path).with_context(|| {
format!("Failed to read object '{}'", target_path.display())
})?)
}
_ => None,
};
let mut second_obj = match &obj_config.base_path {
Some(base_path) if second_status.success => {
update_status(
status,
format!("Loading base {}", base_path_rel.unwrap().display()),
3,
total,
&cancel,
)?;
Some(
elf::read(base_path)
.with_context(|| format!("Failed to read object '{}'", base_path.display()))?,
)
}
_ => None,
};
let mut second_obj = if second_status.success {
update_status(status, format!("Loading base {}", base_path_rel.display()), 3, total, &cancel)?;
Some(elf::read(&obj_config.base_path).with_context(|| {
format!("Failed to read object '{}'", obj_config.base_path.display())
})?)
} else {
None
};
if let (Some(first_obj), Some(second_obj)) = (&mut first_obj, &mut second_obj) {
update_status(status, "Performing diff".to_string(), 4, total, &cancel)?;
diff_objs(first_obj, second_obj)?;
}
update_status(status, "Performing diff".to_string(), 4, total, &cancel)?;
diff_objs(first_obj.as_mut(), second_obj.as_mut())?;
update_status(status, "Complete".to_string(), total, total, &cancel)?;
Ok(Box::new(ObjDiffResult { first_status, second_status, first_obj, second_obj, time }))

View File

@@ -3,6 +3,7 @@
pub use app::App;
mod app;
mod app_config;
mod config;
mod diff;
mod editops;

View File

@@ -91,6 +91,7 @@ pub fn process_code(
reloc: reloc.cloned(),
branch_dest,
line,
orig: None,
});
cur_addr += 4;
}

View File

@@ -37,6 +37,7 @@ pub struct ObjSection {
pub data_diff: Vec<ObjDataDiff>,
pub match_percent: f32,
}
#[derive(Debug, Clone)]
pub enum ObjInsArg {
PpcArg(ppc750cl::Argument),
@@ -46,6 +47,40 @@ pub enum ObjInsArg {
RelocWithBase,
BranchOffset(i32),
}
// TODO derive PartialEq on ppc750cl::Argument so this isn't necessary
impl PartialEq for ObjInsArg {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(ObjInsArg::PpcArg(a), ObjInsArg::PpcArg(b)) => {
use ppc750cl::Argument;
match (a, b) {
(Argument::GPR(a), Argument::GPR(b)) => a == b,
(Argument::FPR(a), Argument::FPR(b)) => a == b,
(Argument::SR(a), Argument::SR(b)) => a == b,
(Argument::SPR(a), Argument::SPR(b)) => a == b,
(Argument::CRField(a), Argument::CRField(b)) => a == b,
(Argument::CRBit(a), Argument::CRBit(b)) => a == b,
(Argument::GQR(a), Argument::GQR(b)) => a == b,
(Argument::Uimm(a), Argument::Uimm(b)) => a == b,
(Argument::Simm(a), Argument::Simm(b)) => a == b,
(Argument::Offset(a), Argument::Offset(b)) => a == b,
(Argument::BranchDest(a), Argument::BranchDest(b)) => a == b,
(Argument::Bit(a), Argument::Bit(b)) => a == b,
(Argument::OpaqueU(a), Argument::OpaqueU(b)) => a == b,
(_, _) => false,
}
}
(ObjInsArg::MipsArg(a), ObjInsArg::MipsArg(b)) => a == b,
(ObjInsArg::MipsArgWithBase(a), ObjInsArg::MipsArgWithBase(b)) => a == b,
(ObjInsArg::Reloc, ObjInsArg::Reloc) => true,
(ObjInsArg::RelocWithBase, ObjInsArg::RelocWithBase) => true,
(ObjInsArg::BranchOffset(a), ObjInsArg::BranchOffset(b)) => a == b,
(_, _) => false,
}
}
}
#[derive(Debug, Copy, Clone)]
pub struct ObjInsArgDiff {
/// Incrementing index for coloring
@@ -86,6 +121,8 @@ pub struct ObjIns {
pub branch_dest: Option<u32>,
/// Line info
pub line: Option<u32>,
/// Original (unsimplified) instruction
pub orig: Option<String>,
}
#[derive(Debug, Clone, Default)]
pub struct ObjInsDiff {

View File

@@ -1,7 +1,7 @@
use std::collections::BTreeMap;
use anyhow::Result;
use ppc750cl::{disasm_iter, Argument};
use ppc750cl::{disasm_iter, Argument, Ins, SimplifiedIns};
use crate::obj::{ObjIns, ObjInsArg, ObjReloc, ObjRelocKind};
@@ -40,7 +40,7 @@ pub fn process_code(
_ => ins.code,
};
}
let simplified = ins.simplified();
let simplified = ins.clone().simplified();
let mut args: Vec<ObjInsArg> = simplified
.args
.iter()
@@ -86,10 +86,21 @@ pub fn process_code(
mnemonic: format!("{}{}", simplified.mnemonic, simplified.suffix),
args,
reloc: reloc.cloned(),
op: 0,
op: ins.op as u8,
branch_dest: None,
line,
orig: Some(format!("{}", basic_form(ins))),
});
}
Ok((ops, insts))
}
// TODO make public in ppc750cl
fn basic_form(ins: Ins) -> SimplifiedIns {
SimplifiedIns {
mnemonic: ins.op.mnemonic(),
suffix: ins.suffix(),
args: ins.fields().iter().flat_map(|field| field.argument()).collect(),
ins,
}
}

View File

@@ -40,6 +40,7 @@ pub struct ConfigViewState {
pub watch_pattern_text: String,
pub load_error: Option<String>,
pub object_search: String,
pub filter_diffable: bool,
#[cfg(windows)]
pub available_wsl_distros: Option<Vec<String>>,
}
@@ -218,17 +219,19 @@ pub fn config_ui(
let target_path = target_dir.join(obj_path);
new_selected_obj = Some(ObjectConfig {
name: obj_path.display().to_string(),
target_path,
base_path: path,
target_path: Some(target_path),
base_path: Some(path),
reverse_fn_order: None,
complete: None,
});
} else if let Ok(obj_path) = path.strip_prefix(&target_dir) {
let base_path = base_dir.join(obj_path);
new_selected_obj = Some(ObjectConfig {
name: obj_path.display().to_string(),
target_path: path,
base_path,
target_path: Some(path),
base_path: Some(base_path),
reverse_fn_order: None,
complete: None,
});
}
}
@@ -266,6 +269,13 @@ pub fn config_ui(
root_open = Some(true);
node_open = NodeOpen::Object;
}
if ui
.selectable_label(state.filter_diffable, "Diffable")
.on_hover_text_at_pointer("Only show objects with a source file")
.clicked()
{
state.filter_diffable = !state.filter_diffable;
}
});
if state.object_search.is_empty() {
if had_search {
@@ -285,10 +295,13 @@ pub fn config_ui(
.default_open(true)
.show(ui, |ui| {
let mut nodes = Cow::Borrowed(object_nodes);
if !state.object_search.is_empty() {
if !state.object_search.is_empty() || state.filter_diffable {
let search = state.object_search.to_ascii_lowercase();
nodes = Cow::Owned(
object_nodes.iter().filter_map(|node| filter_node(node, &search)).collect(),
object_nodes
.iter()
.filter_map(|node| filter_node(node, &search, state.filter_diffable))
.collect(),
);
}
@@ -322,8 +335,18 @@ fn display_object(
) {
let object_name = object.name();
let selected = matches!(selected_obj, Some(obj) if obj.name == object_name);
let color = if selected { appearance.emphasized_text_color } else { appearance.text_color };
if SelectableLabel::new(
let color = if selected {
appearance.emphasized_text_color
} else if let Some(complete) = object.complete {
if complete {
appearance.insert_color
} else {
appearance.delete_color
}
} else {
appearance.text_color
};
let clicked = SelectableLabel::new(
selected,
RichText::new(name)
.font(FontId {
@@ -333,13 +356,16 @@ fn display_object(
.color(color),
)
.ui(ui)
.clicked()
{
.clicked();
// Always recreate ObjectConfig if selected, in case the project config changed.
// ObjectConfig is compared using equality, so this won't unnecessarily trigger a rebuild.
if selected || clicked {
*selected_obj = Some(ObjectConfig {
name: object_name.to_string(),
target_path: object.target_path.clone().unwrap_or_default(),
base_path: object.base_path.clone().unwrap_or_default(),
target_path: object.target_path.clone(),
base_path: object.base_path.clone(),
reverse_fn_order: object.reverse_fn_order,
complete: object.complete,
});
}
}
@@ -404,21 +430,30 @@ fn contains_node(node: &ProjectObjectNode, selected_obj: &ObjectConfig) -> bool
}
}
fn filter_node(node: &ProjectObjectNode, search: &str) -> Option<ProjectObjectNode> {
fn filter_node(
node: &ProjectObjectNode,
search: &str,
filter_diffable: bool,
) -> Option<ProjectObjectNode> {
match node {
ProjectObjectNode::File(name, _) => {
if name.to_ascii_lowercase().contains(search) {
ProjectObjectNode::File(name, object) => {
if (search.is_empty() || name.to_ascii_lowercase().contains(search))
&& (!filter_diffable || object.base_path.is_some())
{
Some(node.clone())
} else {
None
}
}
ProjectObjectNode::Dir(name, children) => {
if name.to_ascii_lowercase().contains(search) {
if (search.is_empty() || name.to_ascii_lowercase().contains(search)) && !filter_diffable
{
return Some(node.clone());
}
let new_children =
children.iter().filter_map(|child| filter_node(child, search)).collect::<Vec<_>>();
let new_children = children
.iter()
.filter_map(|child| filter_node(child, search, filter_diffable))
.collect::<Vec<_>>();
if !new_children.is_empty() {
Some(ProjectObjectNode::Dir(name.clone(), new_children))
} else {

View File

@@ -132,31 +132,39 @@ fn split_diffs(diffs: &[ObjDataDiff]) -> Vec<Vec<ObjDataDiff>> {
fn data_table_ui(
table: TableBuilder<'_>,
left_obj: &ObjInfo,
right_obj: &ObjInfo,
left_obj: Option<&ObjInfo>,
right_obj: Option<&ObjInfo>,
selected_symbol: &SymbolReference,
config: &Appearance,
) -> Option<()> {
let left_section = find_section(left_obj, selected_symbol)?;
let right_section = find_section(right_obj, selected_symbol)?;
let left_section = left_obj.and_then(|obj| find_section(obj, selected_symbol));
let right_section = right_obj.and_then(|obj| find_section(obj, selected_symbol));
let total_bytes = left_section.data_diff.iter().fold(0usize, |accum, item| accum + item.len);
let total_bytes = left_section
.or(right_section)?
.data_diff
.iter()
.fold(0usize, |accum, item| accum + item.len);
if total_bytes == 0 {
return None;
}
let total_rows = (total_bytes - 1) / BYTES_PER_ROW + 1;
let left_diffs = split_diffs(&left_section.data_diff);
let right_diffs = split_diffs(&right_section.data_diff);
let left_diffs = left_section.map(|section| split_diffs(&section.data_diff));
let right_diffs = right_section.map(|section| split_diffs(&section.data_diff));
table.body(|body| {
body.rows(config.code_font.size, total_rows, |row_index, mut row| {
let address = row_index * BYTES_PER_ROW;
row.col(|ui| {
data_row_ui(ui, address, &left_diffs[row_index], config);
if let Some(left_diffs) = &left_diffs {
data_row_ui(ui, address, &left_diffs[row_index], config);
}
});
row.col(|ui| {
data_row_ui(ui, address, &right_diffs[row_index], config);
if let Some(right_diffs) = &right_diffs {
data_row_ui(ui, address, &right_diffs[row_index], config);
}
});
});
});
@@ -243,15 +251,19 @@ pub fn data_diff_ui(ui: &mut egui::Ui, state: &mut DiffViewState, appearance: &A
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, appearance);
}
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,
result.first_obj.as_ref(),
result.second_obj.as_ref(),
selected_symbol,
appearance,
);
}

View File

@@ -1,9 +1,12 @@
use std::{cmp::Ordering, default::Default};
use std::{
cmp::{max, Ordering},
default::Default,
};
use cwdemangle::demangle;
use eframe::emath::Align;
use egui::{text::LayoutJob, Color32, FontId, Label, Layout, Sense, Vec2};
use egui_extras::{Column, TableBuilder};
use egui::{text::LayoutJob, Color32, Label, Layout, RichText, Sense, TextFormat, Vec2};
use egui_extras::{Column, TableBuilder, TableRow};
use ppc750cl::Argument;
use time::format_description;
@@ -19,21 +22,49 @@ use crate::{
},
};
#[derive(Default)]
pub enum HighlightKind {
#[default]
None,
Opcode(u8),
Arg(ObjInsArg),
Symbol(String),
Address(u32),
}
#[derive(Default)]
pub struct FunctionViewState {
pub highlight: HighlightKind,
}
fn write_reloc_name(
reloc: &ObjReloc,
color: Color32,
background_color: Color32,
job: &mut LayoutJob,
font_id: FontId,
appearance: &Appearance,
) {
let name = reloc.target.demangled_name.as_ref().unwrap_or(&reloc.target.name);
write_text(name, appearance.emphasized_text_color, job, font_id.clone());
job.append(name, 0.0, TextFormat {
font_id: appearance.code_font.clone(),
color: appearance.emphasized_text_color,
background: background_color,
..Default::default()
});
match reloc.target.addend.cmp(&0i64) {
Ordering::Greater => {
write_text(&format!("+{:#X}", reloc.target.addend), color, job, font_id)
}
Ordering::Greater => write_text(
&format!("+{:#X}", reloc.target.addend),
color,
job,
appearance.code_font.clone(),
),
Ordering::Less => {
write_text(&format!("-{:#X}", -reloc.target.addend), color, job, font_id);
write_text(
&format!("-{:#X}", -reloc.target.addend),
color,
job,
appearance.code_font.clone(),
);
}
_ => {}
}
@@ -42,57 +73,57 @@ fn write_reloc_name(
fn write_reloc(
reloc: &ObjReloc,
color: Color32,
background_color: Color32,
job: &mut LayoutJob,
font_id: FontId,
appearance: &Appearance,
) {
match reloc.kind {
ObjRelocKind::PpcAddr16Lo => {
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
write_text("@l", color, job, font_id);
write_reloc_name(reloc, color, background_color, job, appearance);
write_text("@l", color, job, appearance.code_font.clone());
}
ObjRelocKind::PpcAddr16Hi => {
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
write_text("@h", color, job, font_id);
write_reloc_name(reloc, color, background_color, job, appearance);
write_text("@h", color, job, appearance.code_font.clone());
}
ObjRelocKind::PpcAddr16Ha => {
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
write_text("@ha", color, job, font_id);
write_reloc_name(reloc, color, background_color, job, appearance);
write_text("@ha", color, job, appearance.code_font.clone());
}
ObjRelocKind::PpcEmbSda21 => {
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
write_text("@sda21", color, job, font_id);
write_reloc_name(reloc, color, background_color, job, appearance);
write_text("@sda21", color, job, appearance.code_font.clone());
}
ObjRelocKind::MipsHi16 => {
write_text("%hi(", color, job, font_id.clone());
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
write_text(")", color, job, font_id);
write_text("%hi(", color, job, appearance.code_font.clone());
write_reloc_name(reloc, color, background_color, job, appearance);
write_text(")", color, job, appearance.code_font.clone());
}
ObjRelocKind::MipsLo16 => {
write_text("%lo(", color, job, font_id.clone());
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
write_text(")", color, job, font_id);
write_text("%lo(", color, job, appearance.code_font.clone());
write_reloc_name(reloc, color, background_color, job, appearance);
write_text(")", color, job, appearance.code_font.clone());
}
ObjRelocKind::MipsGot16 => {
write_text("%got(", color, job, font_id.clone());
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
write_text(")", color, job, font_id);
write_text("%got(", color, job, appearance.code_font.clone());
write_reloc_name(reloc, color, background_color, job, appearance);
write_text(")", color, job, appearance.code_font.clone());
}
ObjRelocKind::MipsCall16 => {
write_text("%call16(", color, job, font_id.clone());
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
write_text(")", color, job, font_id);
write_text("%call16(", color, job, appearance.code_font.clone());
write_reloc_name(reloc, color, background_color, job, appearance);
write_text(")", color, job, appearance.code_font.clone());
}
ObjRelocKind::MipsGpRel16 => {
write_text("%gp_rel(", color, job, font_id.clone());
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
write_text(")", color, job, font_id);
write_text("%gp_rel(", color, job, appearance.code_font.clone());
write_reloc_name(reloc, color, background_color, job, appearance);
write_text(")", color, job, appearance.code_font.clone());
}
ObjRelocKind::PpcRel24 | ObjRelocKind::PpcRel14 | ObjRelocKind::Mips26 => {
write_reloc_name(reloc, color, job, font_id, appearance);
write_reloc_name(reloc, color, background_color, job, appearance);
}
ObjRelocKind::Absolute | ObjRelocKind::MipsGpRel32 => {
write_text("[INVALID]", color, job, font_id);
write_text("[INVALID]", color, job, appearance.code_font.clone());
}
};
}
@@ -102,8 +133,9 @@ fn write_ins(
diff_kind: &ObjInsDiffKind,
args: &[Option<ObjInsArgDiff>],
base_addr: u32,
job: &mut LayoutJob,
ui: &mut egui::Ui,
appearance: &Appearance,
ins_view_state: &mut FunctionViewState,
) {
let base_color = match diff_kind {
ObjInsDiffKind::None | ObjInsDiffKind::OpMismatch | ObjInsDiffKind::ArgMismatch => {
@@ -113,49 +145,92 @@ fn write_ins(
ObjInsDiffKind::Delete => appearance.delete_color,
ObjInsDiffKind::Insert => appearance.insert_color,
};
write_text(
&format!("{:<11}", ins.mnemonic),
match diff_kind {
ObjInsDiffKind::OpMismatch => appearance.replace_color,
_ => base_color,
},
job,
appearance.code_font.clone(),
);
let highlighted_op =
matches!(ins_view_state.highlight, HighlightKind::Opcode(op) if op == ins.op);
let op_label = RichText::new(ins.mnemonic.clone())
.font(appearance.code_font.clone())
.color(if highlighted_op {
appearance.emphasized_text_color
} else {
match diff_kind {
ObjInsDiffKind::OpMismatch => appearance.replace_color,
_ => base_color,
}
})
.background_color(if highlighted_op {
appearance.deemphasized_text_color
} else {
Color32::TRANSPARENT
});
if ui.add(Label::new(op_label).sense(Sense::click())).clicked() {
if highlighted_op {
ins_view_state.highlight = HighlightKind::None;
} else {
ins_view_state.highlight = HighlightKind::Opcode(ins.op);
}
}
let space_width = ui.fonts(|f| f.glyph_width(&appearance.code_font, ' '));
ui.add_space(space_width * (max(11, ins.mnemonic.len()) - ins.mnemonic.len()) as f32);
let mut writing_offset = false;
for (i, arg) in ins.args.iter().enumerate() {
let mut job = LayoutJob::default();
if i == 0 {
write_text(" ", base_color, job, appearance.code_font.clone());
write_text(" ", base_color, &mut job, appearance.code_font.clone());
}
if i > 0 && !writing_offset {
write_text(", ", base_color, job, appearance.code_font.clone());
write_text(", ", base_color, &mut job, appearance.code_font.clone());
}
let color = if let Some(diff) = args.get(i).and_then(|a| a.as_ref()) {
let highlighted_arg = match &ins_view_state.highlight {
HighlightKind::Symbol(v) => {
matches!(arg, ObjInsArg::Reloc | ObjInsArg::RelocWithBase)
&& matches!(&ins.reloc, Some(reloc) if &reloc.target.name == v)
}
HighlightKind::Address(v) => {
matches!(arg, ObjInsArg::BranchOffset(offset) if (offset + ins.address as i32 - base_addr as i32) as u32 == *v)
}
HighlightKind::Arg(v) => v == arg,
_ => false,
};
let color = if highlighted_arg {
appearance.emphasized_text_color
} else if let Some(diff) = args.get(i).and_then(|a| a.as_ref()) {
appearance.diff_colors[diff.idx % appearance.diff_colors.len()]
} else {
base_color
};
let text_format = TextFormat {
font_id: appearance.code_font.clone(),
color,
background: if highlighted_arg {
appearance.deemphasized_text_color
} else {
Color32::TRANSPARENT
},
..Default::default()
};
let mut new_writing_offset = false;
match arg {
ObjInsArg::PpcArg(arg) => match arg {
Argument::Offset(val) => {
write_text(&format!("{val}"), color, job, appearance.code_font.clone());
write_text("(", base_color, job, appearance.code_font.clone());
writing_offset = true;
continue;
job.append(&format!("{val}"), 0.0, text_format);
write_text("(", base_color, &mut job, appearance.code_font.clone());
new_writing_offset = true;
}
Argument::Uimm(_) | Argument::Simm(_) => {
write_text(&format!("{arg}"), color, job, appearance.code_font.clone());
job.append(&format!("{arg}"), 0.0, text_format);
}
_ => {
write_text(&format!("{arg}"), color, job, appearance.code_font.clone());
job.append(&format!("{arg}"), 0.0, text_format);
}
},
ObjInsArg::Reloc => {
write_reloc(
ins.reloc.as_ref().unwrap(),
base_color,
job,
appearance.code_font.clone(),
text_format.background,
&mut job,
appearance,
);
}
@@ -163,41 +238,42 @@ fn write_ins(
write_reloc(
ins.reloc.as_ref().unwrap(),
base_color,
job,
appearance.code_font.clone(),
text_format.background,
&mut job,
appearance,
);
write_text("(", base_color, job, appearance.code_font.clone());
writing_offset = true;
continue;
write_text("(", base_color, &mut job, appearance.code_font.clone());
new_writing_offset = true;
}
ObjInsArg::MipsArg(str) => {
write_text(
str.strip_prefix('$').unwrap_or(str),
color,
job,
appearance.code_font.clone(),
);
job.append(str.strip_prefix('$').unwrap_or(str), 0.0, text_format);
}
ObjInsArg::MipsArgWithBase(str) => {
write_text(
str.strip_prefix('$').unwrap_or(str),
color,
job,
appearance.code_font.clone(),
);
write_text("(", base_color, job, appearance.code_font.clone());
writing_offset = true;
continue;
job.append(str.strip_prefix('$').unwrap_or(str), 0.0, text_format);
write_text("(", base_color, &mut job, appearance.code_font.clone());
new_writing_offset = true;
}
ObjInsArg::BranchOffset(offset) => {
let addr = offset + ins.address as i32 - base_addr as i32;
write_text(&format!("{addr:x}"), color, job, appearance.code_font.clone());
job.append(&format!("{addr:x}"), 0.0, text_format);
}
}
if writing_offset {
write_text(")", base_color, job, appearance.code_font.clone());
writing_offset = false;
write_text(")", base_color, &mut job, appearance.code_font.clone());
}
writing_offset = new_writing_offset;
if ui.add(Label::new(job).sense(Sense::click())).clicked() {
if highlighted_arg {
ins_view_state.highlight = HighlightKind::None;
} else if matches!(arg, ObjInsArg::Reloc | ObjInsArg::RelocWithBase) {
ins_view_state.highlight =
HighlightKind::Symbol(ins.reloc.as_ref().unwrap().target.name.clone());
} else if let ObjInsArg::BranchOffset(offset) = arg {
ins_view_state.highlight =
HighlightKind::Address((offset + ins.address as i32 - base_addr as i32) as u32);
} else {
ins_view_state.highlight = HighlightKind::Arg(arg.clone());
}
}
}
}
@@ -209,6 +285,10 @@ fn ins_hover_ui(ui: &mut egui::Ui, ins: &ObjIns, appearance: &Appearance) {
ui.label(format!("{:02X?}", ins.code.to_be_bytes()));
if let Some(orig) = &ins.orig {
ui.label(format!("Original: {}", orig));
}
for arg in &ins.args {
if let ObjInsArg::PpcArg(arg) = arg {
match arg {
@@ -316,7 +396,9 @@ fn asm_row_ui(
ins_diff: &ObjInsDiff,
symbol: &ObjSymbol,
appearance: &Appearance,
ins_view_state: &mut FunctionViewState,
) {
ui.spacing_mut().item_spacing.x = 0.0;
if ins_diff.kind != ObjInsDiffKind::None {
ui.painter().rect_filled(ui.available_rect_before_wrap(), 0.0, ui.visuals().faint_bg_color);
}
@@ -345,58 +427,128 @@ fn asm_row_ui(
);
pad = 12 - line_str.len();
}
write_text(
&format!("{:<1$}", format!("{:x}: ", ins.address - symbol.address as u32), pad),
base_color,
&mut job,
appearance.code_font.clone(),
let base_addr = symbol.address as u32;
let addr_highlight = matches!(
&ins_view_state.highlight,
HighlightKind::Address(v) if *v == (ins.address - base_addr)
);
if let Some(branch) = &ins_diff.branch_from {
write_text(
"~> ",
appearance.diff_colors[branch.branch_idx % appearance.diff_colors.len()],
&mut job,
appearance.code_font.clone(),
);
} else {
write_text(" ", base_color, &mut job, appearance.code_font.clone());
let addr_string = format!("{:x}", ins.address - symbol.address as u32);
pad -= addr_string.len();
job.append(&addr_string, 0.0, TextFormat {
font_id: appearance.code_font.clone(),
color: if addr_highlight { appearance.emphasized_text_color } else { base_color },
background: if addr_highlight {
appearance.deemphasized_text_color
} else {
Color32::TRANSPARENT
},
..Default::default()
});
if ui.add(Label::new(job).sense(Sense::click())).clicked() {
if addr_highlight {
ins_view_state.highlight = HighlightKind::None;
} else {
ins_view_state.highlight = HighlightKind::Address(ins.address - base_addr);
}
}
write_ins(ins, &ins_diff.kind, &ins_diff.arg_diff, symbol.address as u32, &mut job, appearance);
let mut job = LayoutJob::default();
let space_width = ui.fonts(|f| f.glyph_width(&appearance.code_font, ' '));
let spacing = space_width * pad as f32;
job.append(": ", 0.0, TextFormat {
font_id: appearance.code_font.clone(),
color: base_color,
..Default::default()
});
if let Some(branch) = &ins_diff.branch_from {
job.append("~> ", spacing, TextFormat {
font_id: appearance.code_font.clone(),
color: appearance.diff_colors[branch.branch_idx % appearance.diff_colors.len()],
..Default::default()
});
} else {
job.append(" ", spacing, TextFormat {
font_id: appearance.code_font.clone(),
color: base_color,
..Default::default()
});
}
ui.add(Label::new(job));
write_ins(ins, &ins_diff.kind, &ins_diff.arg_diff, base_addr, ui, appearance, ins_view_state);
if let Some(branch) = &ins_diff.branch_to {
let mut job = LayoutJob::default();
write_text(
" ~>",
appearance.diff_colors[branch.branch_idx % appearance.diff_colors.len()],
&mut job,
appearance.code_font.clone(),
);
ui.add(Label::new(job));
}
ui.add(Label::new(job).sense(Sense::click()))
.on_hover_ui_at_pointer(|ui| ins_hover_ui(ui, ins, appearance))
.context_menu(|ui| ins_context_menu(ui, ins));
}
fn asm_col_ui(
row: &mut TableRow<'_, '_>,
ins_diff: &ObjInsDiff,
symbol: &ObjSymbol,
appearance: &Appearance,
ins_view_state: &mut FunctionViewState,
) {
let (_, response) = row.col(|ui| {
asm_row_ui(ui, ins_diff, symbol, appearance, ins_view_state);
});
if let Some(ins) = &ins_diff.ins {
response
.on_hover_ui_at_pointer(|ui| {
ins_hover_ui(ui, ins, appearance);
})
.context_menu(|ui| {
ins_context_menu(ui, ins);
});
}
}
fn empty_col_ui(row: &mut TableRow<'_, '_>) {
row.col(|ui| {
ui.label("");
});
}
fn asm_table_ui(
table: TableBuilder<'_>,
left_obj: &ObjInfo,
right_obj: &ObjInfo,
left_obj: Option<&ObjInfo>,
right_obj: Option<&ObjInfo>,
selected_symbol: &SymbolReference,
appearance: &Appearance,
ins_view_state: &mut FunctionViewState,
) -> Option<()> {
let left_symbol = find_symbol(left_obj, selected_symbol);
let right_symbol = find_symbol(right_obj, selected_symbol);
let left_symbol = left_obj.and_then(|obj| find_symbol(obj, selected_symbol));
let right_symbol = right_obj.and_then(|obj| find_symbol(obj, selected_symbol));
let instructions_len = left_symbol.or(right_symbol).map(|s| s.instructions.len())?;
table.body(|body| {
body.rows(appearance.code_font.size, instructions_len, |row_index, mut row| {
row.col(|ui| {
if let Some(symbol) = left_symbol {
asm_row_ui(ui, &symbol.instructions[row_index], symbol, appearance);
}
});
row.col(|ui| {
if let Some(symbol) = right_symbol {
asm_row_ui(ui, &symbol.instructions[row_index], symbol, appearance);
}
});
if let Some(symbol) = left_symbol {
asm_col_ui(
&mut row,
&symbol.instructions[row_index],
symbol,
appearance,
ins_view_state,
);
} else {
empty_col_ui(&mut row);
}
if let Some(symbol) = right_symbol {
asm_col_ui(
&mut row,
&symbol.instructions[row_index],
symbol,
appearance,
ins_view_state,
);
} else {
empty_col_ui(&mut row);
}
});
});
Some(())
@@ -492,7 +644,7 @@ pub fn function_diff_ui(ui: &mut egui::Ui, state: &mut DiffViewState, appearance
&format!("{match_percent:.0}%"),
);
} else {
ui.label("");
ui.colored_label(appearance.replace_color, "Missing");
}
ui.label("Diff base:");
});
@@ -503,15 +655,20 @@ pub fn function_diff_ui(ui: &mut egui::Ui, state: &mut DiffViewState, appearance
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, appearance);
}
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,
result.first_obj.as_ref(),
result.second_obj.as_ref(),
selected_symbol,
appearance,
&mut state.function_state,
);
}

View File

@@ -1,7 +1,7 @@
use std::mem::take;
use egui::{
text::LayoutJob, Align, CollapsingHeader, Color32, Layout, Rgba, ScrollArea, SelectableLabel,
text::LayoutJob, Align, CollapsingHeader, Color32, Layout, ScrollArea, SelectableLabel,
TextEdit, Ui, Vec2, Widget,
};
use egui_extras::{Size, StripBuilder};
@@ -13,7 +13,7 @@ use crate::{
Job, JobQueue, JobResult,
},
obj::{ObjInfo, ObjSection, ObjSectionKind, ObjSymbol, ObjSymbolFlags},
views::{appearance::Appearance, write_text},
views::{appearance::Appearance, function_diff::FunctionViewState, write_text},
};
pub struct SymbolReference {
@@ -35,6 +35,7 @@ pub struct DiffViewState {
pub build: Option<Box<ObjDiffResult>>,
pub current_view: View,
pub symbol_state: SymbolViewState,
pub function_state: FunctionViewState,
pub search: String,
pub queue_build: bool,
pub build_running: bool,
@@ -263,6 +264,15 @@ fn build_log_ui(ui: &mut Ui, status: &BuildStatus, appearance: &Appearance) {
});
}
fn missing_obj_ui(ui: &mut Ui, appearance: &Appearance) {
ui.scope(|ui| {
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false);
ui.colored_label(appearance.replace_color, "No object configured");
});
}
pub fn symbol_diff_ui(ui: &mut Ui, state: &mut DiffViewState, appearance: &Appearance) {
let DiffViewState { build, current_view, symbol_state, search, .. } = state;
let Some(result) = build else {
@@ -289,9 +299,13 @@ pub fn symbol_diff_ui(ui: &mut Ui, state: &mut DiffViewState, appearance: &Appea
ui.label("Build target:");
if result.first_status.success {
ui.label("OK");
if result.first_obj.is_none() {
ui.colored_label(appearance.replace_color, "Missing");
} else {
ui.label("OK");
}
} else {
ui.colored_label(Rgba::from_rgb(1.0, 0.0, 0.0), "Fail");
ui.colored_label(appearance.delete_color, "Fail");
}
});
@@ -312,9 +326,13 @@ pub fn symbol_diff_ui(ui: &mut Ui, state: &mut DiffViewState, appearance: &Appea
ui.label("Build base:");
if result.second_status.success {
ui.label("OK");
if result.second_obj.is_none() {
ui.colored_label(appearance.replace_color, "Missing");
} else {
ui.label("OK");
}
} else {
ui.colored_label(Rgba::from_rgb(1.0, 0.0, 0.0), "Fail");
ui.colored_label(appearance.delete_color, "Fail");
}
});
@@ -348,6 +366,8 @@ pub fn symbol_diff_ui(ui: &mut Ui, state: &mut DiffViewState, appearance: &Appea
&lower_search,
appearance,
));
} else {
missing_obj_ui(ui, appearance);
}
} else {
build_log_ui(ui, &result.first_status, appearance);
@@ -365,6 +385,8 @@ pub fn symbol_diff_ui(ui: &mut Ui, state: &mut DiffViewState, appearance: &Appea
&lower_search,
appearance,
));
} else {
missing_obj_ui(ui, appearance);
}
} else {
build_log_ui(ui, &result.second_status, appearance);