mirror of https://github.com/encounter/objdiff.git
Compare commits
3 Commits
2dd3dd60a8
...
e68629c339
Author | SHA1 | Date |
---|---|---|
Luke Street | e68629c339 | |
Luke Street | bb9ff4b928 | |
Luke Street | 57392daaeb |
File diff suppressed because it is too large
Load Diff
60
Cargo.toml
60
Cargo.toml
|
@ -1,8 +1,8 @@
|
||||||
[package]
|
[package]
|
||||||
name = "objdiff"
|
name = "objdiff"
|
||||||
version = "0.4.4"
|
version = "0.5.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.65"
|
rust-version = "1.70"
|
||||||
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"
|
||||||
|
@ -22,46 +22,46 @@ default = []
|
||||||
wgpu = ["eframe/wgpu"]
|
wgpu = ["eframe/wgpu"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.71"
|
anyhow = "1.0.75"
|
||||||
byteorder = "1.4.3"
|
byteorder = "1.5.0"
|
||||||
bytes = "1.4.0"
|
bytes = "1.5.0"
|
||||||
cfg-if = "1.0.0"
|
cfg-if = "1.0.0"
|
||||||
const_format = "0.2.31"
|
const_format = "0.2.31"
|
||||||
cwdemangle = "0.1.6"
|
cwdemangle = "0.1.6"
|
||||||
dirs = "5.0.1"
|
dirs = "5.0.1"
|
||||||
eframe = { version = "0.22.0", features = ["persistence"] }
|
eframe = { version = "0.23.0", features = ["persistence"] }
|
||||||
egui = "0.22.0"
|
egui = "0.23.0"
|
||||||
egui_extras = "0.22.0"
|
egui_extras = "0.23.0"
|
||||||
flagset = "0.4.3"
|
flagset = "0.4.4"
|
||||||
globset = { version = "0.4.13", features = ["serde1"] }
|
globset = { version = "0.4.13", features = ["serde1"] }
|
||||||
log = "0.4.19"
|
log = "0.4.20"
|
||||||
memmap2 = "0.7.1"
|
memmap2 = "0.9.0"
|
||||||
notify = "6.0.1"
|
notify = "6.1.1"
|
||||||
object = { version = "0.31.1", features = ["read_core", "std", "elf"], default-features = false }
|
object = { version = "0.32.1", features = ["read_core", "std", "elf"], default-features = false }
|
||||||
png = "0.17.9"
|
png = "0.17.10"
|
||||||
ppc750cl = { git = "https://github.com/terorie/ppc750cl", rev = "9ae36eef34aa6d74e00972c7671f547a2acfd0aa" }
|
ppc750cl = { git = "https://github.com/encounter/ppc750cl", rev = "4a2bbbc6f84dcb76255ab6f3595a8d4a0ce96618" }
|
||||||
rabbitizer = "1.7.4"
|
rabbitizer = "1.7.10"
|
||||||
rfd = { version = "0.11.4" } #, default-features = false, features = ['xdg-portal']
|
rfd = { version = "0.12.0" } #, default-features = false, features = ['xdg-portal']
|
||||||
ron = "0.8.0"
|
ron = "0.8.1"
|
||||||
semver = "1.0.17"
|
semver = "1.0.19"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1.0.104"
|
serde_json = "1.0.107"
|
||||||
serde_yaml = "0.9.25"
|
serde_yaml = "0.9.25"
|
||||||
tempfile = "3.6.0"
|
tempfile = "3.8.0"
|
||||||
thiserror = "1.0.41"
|
thiserror = "1.0.49"
|
||||||
time = { version = "0.3.22", features = ["formatting", "local-offset"] }
|
time = { version = "0.3.29", features = ["formatting", "local-offset"] }
|
||||||
toml = "0.7.6"
|
toml = "0.8.2"
|
||||||
twox-hash = "1.6.3"
|
twox-hash = "1.6.3"
|
||||||
|
|
||||||
# For Linux static binaries, use rustls
|
# For Linux static binaries, use rustls
|
||||||
[target.'cfg(target_os = "linux")'.dependencies]
|
[target.'cfg(target_os = "linux")'.dependencies]
|
||||||
reqwest = { version = "0.11.18", default-features = false, features = ["blocking", "json", "rustls"] }
|
reqwest = { version = "0.11.22", default-features = false, features = ["blocking", "json", "rustls"] }
|
||||||
self_update = { version = "0.37.0", default-features = false, features = ["rustls"] }
|
self_update = { version = "0.38.0", default-features = false, features = ["rustls"] }
|
||||||
|
|
||||||
# For all other platforms, use native TLS
|
# For all other platforms, use native TLS
|
||||||
[target.'cfg(not(target_os = "linux"))'.dependencies]
|
[target.'cfg(not(target_os = "linux"))'.dependencies]
|
||||||
reqwest = "0.11.18"
|
reqwest = "0.11.22"
|
||||||
self_update = "0.37.0"
|
self_update = "0.38.0"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
path-slash = "0.2.1"
|
path-slash = "0.2.1"
|
||||||
|
@ -83,5 +83,5 @@ console_error_panic_hook = "0.1.7"
|
||||||
tracing-wasm = "0.2"
|
tracing-wasm = "0.2"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
anyhow = "1.0.71"
|
anyhow = "1.0.75"
|
||||||
vergen = { version = "8.2.4", features = ["build", "cargo", "git", "gitcl"] }
|
vergen = { version = "8.2.5", features = ["build", "cargo", "git", "gitcl"] }
|
||||||
|
|
|
@ -91,6 +91,7 @@ pub fn process_code(
|
||||||
reloc: reloc.cloned(),
|
reloc: reloc.cloned(),
|
||||||
branch_dest,
|
branch_dest,
|
||||||
line,
|
line,
|
||||||
|
orig: None,
|
||||||
});
|
});
|
||||||
cur_addr += 4;
|
cur_addr += 4;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,8 @@ pub struct ObjSection {
|
||||||
pub data_diff: Vec<ObjDataDiff>,
|
pub data_diff: Vec<ObjDataDiff>,
|
||||||
pub match_percent: f32,
|
pub match_percent: f32,
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub enum ObjInsArg {
|
pub enum ObjInsArg {
|
||||||
PpcArg(ppc750cl::Argument),
|
PpcArg(ppc750cl::Argument),
|
||||||
MipsArg(String),
|
MipsArg(String),
|
||||||
|
@ -46,6 +47,7 @@ pub enum ObjInsArg {
|
||||||
RelocWithBase,
|
RelocWithBase,
|
||||||
BranchOffset(i32),
|
BranchOffset(i32),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub struct ObjInsArgDiff {
|
pub struct ObjInsArgDiff {
|
||||||
/// Incrementing index for coloring
|
/// Incrementing index for coloring
|
||||||
|
@ -86,6 +88,8 @@ pub struct ObjIns {
|
||||||
pub branch_dest: Option<u32>,
|
pub branch_dest: Option<u32>,
|
||||||
/// Line info
|
/// Line info
|
||||||
pub line: Option<u32>,
|
pub line: Option<u32>,
|
||||||
|
/// Original (unsimplified) instruction
|
||||||
|
pub orig: Option<String>,
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct ObjInsDiff {
|
pub struct ObjInsDiff {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use ppc750cl::{disasm_iter, Argument};
|
use ppc750cl::{disasm_iter, Argument, SimplifiedIns};
|
||||||
|
|
||||||
use crate::obj::{ObjIns, ObjInsArg, ObjReloc, ObjRelocKind};
|
use crate::obj::{ObjIns, ObjInsArg, ObjReloc, ObjRelocKind};
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ pub fn process_code(
|
||||||
_ => ins.code,
|
_ => ins.code,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
let simplified = ins.simplified();
|
let simplified = ins.clone().simplified();
|
||||||
let mut args: Vec<ObjInsArg> = simplified
|
let mut args: Vec<ObjInsArg> = simplified
|
||||||
.args
|
.args
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -86,9 +86,10 @@ pub fn process_code(
|
||||||
mnemonic: format!("{}{}", simplified.mnemonic, simplified.suffix),
|
mnemonic: format!("{}{}", simplified.mnemonic, simplified.suffix),
|
||||||
args,
|
args,
|
||||||
reloc: reloc.cloned(),
|
reloc: reloc.cloned(),
|
||||||
op: 0,
|
op: ins.op as u8,
|
||||||
branch_dest: None,
|
branch_dest: None,
|
||||||
line,
|
line,
|
||||||
|
orig: Some(format!("{}", SimplifiedIns::basic_form(ins))),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Ok((ops, insts))
|
Ok((ops, insts))
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
use std::{cmp::Ordering, default::Default};
|
use std::{
|
||||||
|
cmp::{max, Ordering},
|
||||||
|
default::Default,
|
||||||
|
};
|
||||||
|
|
||||||
use cwdemangle::demangle;
|
use cwdemangle::demangle;
|
||||||
use eframe::emath::Align;
|
use eframe::emath::Align;
|
||||||
use egui::{text::LayoutJob, Color32, FontId, Label, Layout, Sense, Vec2};
|
use egui::{text::LayoutJob, Color32, Label, Layout, RichText, Sense, TextFormat, Vec2};
|
||||||
use egui_extras::{Column, TableBuilder};
|
use egui_extras::{Column, TableBuilder, TableRow};
|
||||||
use ppc750cl::Argument;
|
use ppc750cl::Argument;
|
||||||
use time::format_description;
|
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(
|
fn write_reloc_name(
|
||||||
reloc: &ObjReloc,
|
reloc: &ObjReloc,
|
||||||
color: Color32,
|
color: Color32,
|
||||||
|
background_color: Color32,
|
||||||
job: &mut LayoutJob,
|
job: &mut LayoutJob,
|
||||||
font_id: FontId,
|
|
||||||
appearance: &Appearance,
|
appearance: &Appearance,
|
||||||
) {
|
) {
|
||||||
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, 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) {
|
match reloc.target.addend.cmp(&0i64) {
|
||||||
Ordering::Greater => {
|
Ordering::Greater => write_text(
|
||||||
write_text(&format!("+{:#X}", reloc.target.addend), color, job, font_id)
|
&format!("+{:#X}", reloc.target.addend),
|
||||||
}
|
color,
|
||||||
|
job,
|
||||||
|
appearance.code_font.clone(),
|
||||||
|
),
|
||||||
Ordering::Less => {
|
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(
|
fn write_reloc(
|
||||||
reloc: &ObjReloc,
|
reloc: &ObjReloc,
|
||||||
color: Color32,
|
color: Color32,
|
||||||
|
background_color: Color32,
|
||||||
job: &mut LayoutJob,
|
job: &mut LayoutJob,
|
||||||
font_id: FontId,
|
|
||||||
appearance: &Appearance,
|
appearance: &Appearance,
|
||||||
) {
|
) {
|
||||||
match reloc.kind {
|
match reloc.kind {
|
||||||
ObjRelocKind::PpcAddr16Lo => {
|
ObjRelocKind::PpcAddr16Lo => {
|
||||||
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
|
write_reloc_name(reloc, color, background_color, job, appearance);
|
||||||
write_text("@l", color, job, font_id);
|
write_text("@l", color, job, appearance.code_font.clone());
|
||||||
}
|
}
|
||||||
ObjRelocKind::PpcAddr16Hi => {
|
ObjRelocKind::PpcAddr16Hi => {
|
||||||
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
|
write_reloc_name(reloc, color, background_color, job, appearance);
|
||||||
write_text("@h", color, job, font_id);
|
write_text("@h", color, job, appearance.code_font.clone());
|
||||||
}
|
}
|
||||||
ObjRelocKind::PpcAddr16Ha => {
|
ObjRelocKind::PpcAddr16Ha => {
|
||||||
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
|
write_reloc_name(reloc, color, background_color, job, appearance);
|
||||||
write_text("@ha", color, job, font_id);
|
write_text("@ha", color, job, appearance.code_font.clone());
|
||||||
}
|
}
|
||||||
ObjRelocKind::PpcEmbSda21 => {
|
ObjRelocKind::PpcEmbSda21 => {
|
||||||
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
|
write_reloc_name(reloc, color, background_color, job, appearance);
|
||||||
write_text("@sda21", color, job, font_id);
|
write_text("@sda21", color, job, appearance.code_font.clone());
|
||||||
}
|
}
|
||||||
ObjRelocKind::MipsHi16 => {
|
ObjRelocKind::MipsHi16 => {
|
||||||
write_text("%hi(", color, job, font_id.clone());
|
write_text("%hi(", color, job, appearance.code_font.clone());
|
||||||
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
|
write_reloc_name(reloc, color, background_color, job, appearance);
|
||||||
write_text(")", color, job, font_id);
|
write_text(")", color, job, appearance.code_font.clone());
|
||||||
}
|
}
|
||||||
ObjRelocKind::MipsLo16 => {
|
ObjRelocKind::MipsLo16 => {
|
||||||
write_text("%lo(", color, job, font_id.clone());
|
write_text("%lo(", color, job, appearance.code_font.clone());
|
||||||
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
|
write_reloc_name(reloc, color, background_color, job, appearance);
|
||||||
write_text(")", color, job, font_id);
|
write_text(")", color, job, appearance.code_font.clone());
|
||||||
}
|
}
|
||||||
ObjRelocKind::MipsGot16 => {
|
ObjRelocKind::MipsGot16 => {
|
||||||
write_text("%got(", color, job, font_id.clone());
|
write_text("%got(", color, job, appearance.code_font.clone());
|
||||||
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
|
write_reloc_name(reloc, color, background_color, job, appearance);
|
||||||
write_text(")", color, job, font_id);
|
write_text(")", color, job, appearance.code_font.clone());
|
||||||
}
|
}
|
||||||
ObjRelocKind::MipsCall16 => {
|
ObjRelocKind::MipsCall16 => {
|
||||||
write_text("%call16(", color, job, font_id.clone());
|
write_text("%call16(", color, job, appearance.code_font.clone());
|
||||||
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
|
write_reloc_name(reloc, color, background_color, job, appearance);
|
||||||
write_text(")", color, job, font_id);
|
write_text(")", color, job, appearance.code_font.clone());
|
||||||
}
|
}
|
||||||
ObjRelocKind::MipsGpRel16 => {
|
ObjRelocKind::MipsGpRel16 => {
|
||||||
write_text("%gp_rel(", color, job, font_id.clone());
|
write_text("%gp_rel(", color, job, appearance.code_font.clone());
|
||||||
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
|
write_reloc_name(reloc, color, background_color, job, appearance);
|
||||||
write_text(")", color, job, font_id);
|
write_text(")", color, job, appearance.code_font.clone());
|
||||||
}
|
}
|
||||||
ObjRelocKind::PpcRel24 | ObjRelocKind::PpcRel14 | ObjRelocKind::Mips26 => {
|
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 => {
|
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,
|
diff_kind: &ObjInsDiffKind,
|
||||||
args: &[Option<ObjInsArgDiff>],
|
args: &[Option<ObjInsArgDiff>],
|
||||||
base_addr: u32,
|
base_addr: u32,
|
||||||
job: &mut LayoutJob,
|
ui: &mut egui::Ui,
|
||||||
appearance: &Appearance,
|
appearance: &Appearance,
|
||||||
|
ins_view_state: &mut FunctionViewState,
|
||||||
) {
|
) {
|
||||||
let base_color = match diff_kind {
|
let base_color = match diff_kind {
|
||||||
ObjInsDiffKind::None | ObjInsDiffKind::OpMismatch | ObjInsDiffKind::ArgMismatch => {
|
ObjInsDiffKind::None | ObjInsDiffKind::OpMismatch | ObjInsDiffKind::ArgMismatch => {
|
||||||
|
@ -113,49 +145,92 @@ fn write_ins(
|
||||||
ObjInsDiffKind::Delete => appearance.delete_color,
|
ObjInsDiffKind::Delete => appearance.delete_color,
|
||||||
ObjInsDiffKind::Insert => appearance.insert_color,
|
ObjInsDiffKind::Insert => appearance.insert_color,
|
||||||
};
|
};
|
||||||
write_text(
|
|
||||||
&format!("{:<11}", ins.mnemonic),
|
let highlighted_op =
|
||||||
match diff_kind {
|
matches!(ins_view_state.highlight, HighlightKind::Opcode(op) if op == ins.op);
|
||||||
ObjInsDiffKind::OpMismatch => appearance.replace_color,
|
let op_label = RichText::new(ins.mnemonic.clone())
|
||||||
_ => base_color,
|
.font(appearance.code_font.clone())
|
||||||
},
|
.color(if highlighted_op {
|
||||||
job,
|
appearance.emphasized_text_color
|
||||||
appearance.code_font.clone(),
|
} 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;
|
let mut writing_offset = false;
|
||||||
for (i, arg) in ins.args.iter().enumerate() {
|
for (i, arg) in ins.args.iter().enumerate() {
|
||||||
|
let mut job = LayoutJob::default();
|
||||||
if i == 0 {
|
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 {
|
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()]
|
appearance.diff_colors[diff.idx % appearance.diff_colors.len()]
|
||||||
} else {
|
} else {
|
||||||
base_color
|
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 {
|
match arg {
|
||||||
ObjInsArg::PpcArg(arg) => match arg {
|
ObjInsArg::PpcArg(arg) => match arg {
|
||||||
Argument::Offset(val) => {
|
Argument::Offset(val) => {
|
||||||
write_text(&format!("{val}"), color, job, appearance.code_font.clone());
|
job.append(&format!("{val}"), 0.0, text_format);
|
||||||
write_text("(", base_color, job, appearance.code_font.clone());
|
write_text("(", base_color, &mut job, appearance.code_font.clone());
|
||||||
writing_offset = true;
|
new_writing_offset = true;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
Argument::Uimm(_) | Argument::Simm(_) => {
|
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 => {
|
ObjInsArg::Reloc => {
|
||||||
write_reloc(
|
write_reloc(
|
||||||
ins.reloc.as_ref().unwrap(),
|
ins.reloc.as_ref().unwrap(),
|
||||||
base_color,
|
base_color,
|
||||||
job,
|
text_format.background,
|
||||||
appearance.code_font.clone(),
|
&mut job,
|
||||||
appearance,
|
appearance,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -163,41 +238,42 @@ fn write_ins(
|
||||||
write_reloc(
|
write_reloc(
|
||||||
ins.reloc.as_ref().unwrap(),
|
ins.reloc.as_ref().unwrap(),
|
||||||
base_color,
|
base_color,
|
||||||
job,
|
text_format.background,
|
||||||
appearance.code_font.clone(),
|
&mut job,
|
||||||
appearance,
|
appearance,
|
||||||
);
|
);
|
||||||
write_text("(", base_color, job, appearance.code_font.clone());
|
write_text("(", base_color, &mut job, appearance.code_font.clone());
|
||||||
writing_offset = true;
|
new_writing_offset = true;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
ObjInsArg::MipsArg(str) => {
|
ObjInsArg::MipsArg(str) => {
|
||||||
write_text(
|
job.append(str.strip_prefix('$').unwrap_or(str), 0.0, text_format);
|
||||||
str.strip_prefix('$').unwrap_or(str),
|
|
||||||
color,
|
|
||||||
job,
|
|
||||||
appearance.code_font.clone(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
ObjInsArg::MipsArgWithBase(str) => {
|
ObjInsArg::MipsArgWithBase(str) => {
|
||||||
write_text(
|
job.append(str.strip_prefix('$').unwrap_or(str), 0.0, text_format);
|
||||||
str.strip_prefix('$').unwrap_or(str),
|
write_text("(", base_color, &mut job, appearance.code_font.clone());
|
||||||
color,
|
new_writing_offset = true;
|
||||||
job,
|
|
||||||
appearance.code_font.clone(),
|
|
||||||
);
|
|
||||||
write_text("(", base_color, job, appearance.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, appearance.code_font.clone());
|
job.append(&format!("{addr:x}"), 0.0, text_format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if writing_offset {
|
if writing_offset {
|
||||||
write_text(")", base_color, job, appearance.code_font.clone());
|
write_text(")", base_color, &mut job, appearance.code_font.clone());
|
||||||
writing_offset = false;
|
}
|
||||||
|
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()));
|
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 {
|
for arg in &ins.args {
|
||||||
if let ObjInsArg::PpcArg(arg) = arg {
|
if let ObjInsArg::PpcArg(arg) = arg {
|
||||||
match arg {
|
match arg {
|
||||||
|
@ -316,7 +396,9 @@ fn asm_row_ui(
|
||||||
ins_diff: &ObjInsDiff,
|
ins_diff: &ObjInsDiff,
|
||||||
symbol: &ObjSymbol,
|
symbol: &ObjSymbol,
|
||||||
appearance: &Appearance,
|
appearance: &Appearance,
|
||||||
|
ins_view_state: &mut FunctionViewState,
|
||||||
) {
|
) {
|
||||||
|
ui.spacing_mut().item_spacing.x = 0.0;
|
||||||
if ins_diff.kind != ObjInsDiffKind::None {
|
if ins_diff.kind != ObjInsDiffKind::None {
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -345,34 +427,91 @@ fn asm_row_ui(
|
||||||
);
|
);
|
||||||
pad = 12 - line_str.len();
|
pad = 12 - line_str.len();
|
||||||
}
|
}
|
||||||
write_text(
|
let base_addr = symbol.address as u32;
|
||||||
&format!("{:<1$}", format!("{:x}: ", ins.address - symbol.address as u32), pad),
|
let addr_highlight = matches!(
|
||||||
base_color,
|
&ins_view_state.highlight,
|
||||||
&mut job,
|
HighlightKind::Address(v) if *v == (ins.address - base_addr)
|
||||||
appearance.code_font.clone(),
|
|
||||||
);
|
);
|
||||||
if let Some(branch) = &ins_diff.branch_from {
|
let addr_string = format!("{:x}", ins.address - symbol.address as u32);
|
||||||
write_text(
|
pad -= addr_string.len();
|
||||||
"~> ",
|
job.append(&addr_string, 0.0, TextFormat {
|
||||||
appearance.diff_colors[branch.branch_idx % appearance.diff_colors.len()],
|
font_id: appearance.code_font.clone(),
|
||||||
&mut job,
|
color: if addr_highlight { appearance.emphasized_text_color } else { base_color },
|
||||||
appearance.code_font.clone(),
|
background: if addr_highlight {
|
||||||
);
|
appearance.deemphasized_text_color
|
||||||
} else {
|
} else {
|
||||||
write_text(" ", base_color, &mut job, appearance.code_font.clone());
|
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 {
|
if let Some(branch) = &ins_diff.branch_to {
|
||||||
|
let mut job = LayoutJob::default();
|
||||||
write_text(
|
write_text(
|
||||||
" ~>",
|
" ~>",
|
||||||
appearance.diff_colors[branch.branch_idx % appearance.diff_colors.len()],
|
appearance.diff_colors[branch.branch_idx % appearance.diff_colors.len()],
|
||||||
&mut job,
|
&mut job,
|
||||||
appearance.code_font.clone(),
|
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(
|
fn asm_table_ui(
|
||||||
|
@ -381,22 +520,35 @@ fn asm_table_ui(
|
||||||
right_obj: Option<&ObjInfo>,
|
right_obj: Option<&ObjInfo>,
|
||||||
selected_symbol: &SymbolReference,
|
selected_symbol: &SymbolReference,
|
||||||
appearance: &Appearance,
|
appearance: &Appearance,
|
||||||
|
ins_view_state: &mut FunctionViewState,
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
let left_symbol = left_obj.and_then(|obj| find_symbol(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 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())?;
|
let instructions_len = left_symbol.or(right_symbol).map(|s| s.instructions.len())?;
|
||||||
table.body(|body| {
|
table.body(|body| {
|
||||||
body.rows(appearance.code_font.size, instructions_len, |row_index, mut row| {
|
body.rows(appearance.code_font.size, instructions_len, |row_index, mut row| {
|
||||||
row.col(|ui| {
|
if let Some(symbol) = left_symbol {
|
||||||
if let Some(symbol) = left_symbol {
|
asm_col_ui(
|
||||||
asm_row_ui(ui, &symbol.instructions[row_index], symbol, appearance);
|
&mut row,
|
||||||
}
|
&symbol.instructions[row_index],
|
||||||
});
|
symbol,
|
||||||
row.col(|ui| {
|
appearance,
|
||||||
if let Some(symbol) = right_symbol {
|
ins_view_state,
|
||||||
asm_row_ui(ui, &symbol.instructions[row_index], symbol, appearance);
|
);
|
||||||
}
|
} 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(())
|
Some(())
|
||||||
|
@ -517,5 +669,6 @@ pub fn function_diff_ui(ui: &mut egui::Ui, state: &mut DiffViewState, appearance
|
||||||
result.second_obj.as_ref(),
|
result.second_obj.as_ref(),
|
||||||
selected_symbol,
|
selected_symbol,
|
||||||
appearance,
|
appearance,
|
||||||
|
&mut state.function_state,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ use crate::{
|
||||||
Job, JobQueue, JobResult,
|
Job, JobQueue, JobResult,
|
||||||
},
|
},
|
||||||
obj::{ObjInfo, ObjSection, ObjSectionKind, ObjSymbol, ObjSymbolFlags},
|
obj::{ObjInfo, ObjSection, ObjSectionKind, ObjSymbol, ObjSymbolFlags},
|
||||||
views::{appearance::Appearance, write_text},
|
views::{appearance::Appearance, function_diff::FunctionViewState, write_text},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct SymbolReference {
|
pub struct SymbolReference {
|
||||||
|
@ -35,6 +35,7 @@ pub struct DiffViewState {
|
||||||
pub build: Option<Box<ObjDiffResult>>,
|
pub build: Option<Box<ObjDiffResult>>,
|
||||||
pub current_view: View,
|
pub current_view: View,
|
||||||
pub symbol_state: SymbolViewState,
|
pub symbol_state: SymbolViewState,
|
||||||
|
pub function_state: FunctionViewState,
|
||||||
pub search: String,
|
pub search: String,
|
||||||
pub queue_build: bool,
|
pub queue_build: bool,
|
||||||
pub build_running: bool,
|
pub build_running: bool,
|
||||||
|
|
Loading…
Reference in New Issue