mirror of
https://github.com/encounter/objdiff.git
synced 2025-12-10 22:17:51 +00:00
Initial commit
This commit is contained in:
87
src/views/config.rs
Normal file
87
src/views/config.rs
Normal file
@@ -0,0 +1,87 @@
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
use crate::{
|
||||
app::{AppConfig, ViewState},
|
||||
jobs::build::queue_build,
|
||||
};
|
||||
|
||||
pub fn config_ui(ui: &mut egui::Ui, config: &Arc<RwLock<AppConfig>>, view_state: &mut ViewState) {
|
||||
let mut config_guard = config.write().unwrap();
|
||||
let AppConfig { project_dir, project_dir_change, build_asm_dir, build_src_dir, build_obj } =
|
||||
&mut *config_guard;
|
||||
|
||||
if ui.button("Select project dir").clicked() {
|
||||
if let Some(path) = rfd::FileDialog::new().pick_folder() {
|
||||
*project_dir = Some(path);
|
||||
*project_dir_change = true;
|
||||
*build_asm_dir = None;
|
||||
*build_src_dir = None;
|
||||
*build_obj = None;
|
||||
}
|
||||
}
|
||||
if let Some(dir) = project_dir {
|
||||
ui.label(dir.to_string_lossy());
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
|
||||
if let Some(project_dir) = project_dir {
|
||||
if ui.button("Select asm build dir").clicked() {
|
||||
if let Some(path) = rfd::FileDialog::new().set_directory(&project_dir).pick_folder() {
|
||||
*build_asm_dir = Some(path);
|
||||
*build_obj = None;
|
||||
}
|
||||
}
|
||||
if let Some(dir) = build_asm_dir {
|
||||
ui.label(dir.to_string_lossy());
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
|
||||
if ui.button("Select src build dir").clicked() {
|
||||
if let Some(path) = rfd::FileDialog::new().set_directory(&project_dir).pick_folder() {
|
||||
*build_src_dir = Some(path);
|
||||
*build_obj = None;
|
||||
}
|
||||
}
|
||||
if let Some(dir) = build_src_dir {
|
||||
ui.label(dir.to_string_lossy());
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
}
|
||||
|
||||
if let Some(build_src_dir) = build_src_dir {
|
||||
if ui.button("Select obj").clicked() {
|
||||
if let Some(path) = rfd::FileDialog::new()
|
||||
.set_directory(&build_src_dir)
|
||||
.add_filter("Object file", &["o"])
|
||||
.pick_file()
|
||||
{
|
||||
let mut new_build_obj: Option<String> = None;
|
||||
if let Ok(obj_path) = path.strip_prefix(&build_src_dir) {
|
||||
new_build_obj = Some(obj_path.display().to_string());
|
||||
} else if let Some(build_asm_dir) = build_asm_dir {
|
||||
if let Ok(obj_path) = path.strip_prefix(&build_asm_dir) {
|
||||
new_build_obj = Some(obj_path.display().to_string());
|
||||
}
|
||||
}
|
||||
if let Some(new_build_obj) = new_build_obj {
|
||||
*build_obj = Some(new_build_obj.clone());
|
||||
view_state.jobs.push(queue_build(new_build_obj, config.clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(build_obj) = build_obj {
|
||||
ui.label(&*build_obj);
|
||||
if ui.button("Build").clicked() {
|
||||
view_state.jobs.push(queue_build(build_obj.clone(), config.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
}
|
||||
|
||||
ui.checkbox(&mut view_state.reverse_fn_order, "Reverse function order (deferred)");
|
||||
ui.separator();
|
||||
}
|
||||
338
src/views/function_diff.rs
Normal file
338
src/views/function_diff.rs
Normal file
@@ -0,0 +1,338 @@
|
||||
use std::default::Default;
|
||||
|
||||
use cwdemangle::demangle;
|
||||
use egui::{text::LayoutJob, Color32, FontFamily, FontId, Label, Sense, TextFormat};
|
||||
use egui_extras::{Size, StripBuilder, TableBuilder};
|
||||
use ppc750cl::Argument;
|
||||
|
||||
use crate::{
|
||||
app::ViewState,
|
||||
obj::{
|
||||
ObjInfo, ObjIns, ObjInsArg, ObjInsArgDiff, ObjInsDiff, ObjInsDiffKind, ObjReloc,
|
||||
ObjRelocKind, ObjSymbol,
|
||||
},
|
||||
views::symbol_diff::match_color_for_symbol,
|
||||
};
|
||||
|
||||
const FONT_SIZE: f32 = 14.0;
|
||||
const FONT_ID: FontId = FontId::new(FONT_SIZE, FontFamily::Monospace);
|
||||
|
||||
const COLOR_RED: Color32 = Color32::from_rgb(200, 40, 41);
|
||||
|
||||
fn write_text(str: &str, color: Color32, job: &mut LayoutJob) {
|
||||
job.append(str, 0.0, TextFormat { font_id: FONT_ID, color, ..Default::default() });
|
||||
}
|
||||
|
||||
fn write_reloc(reloc: &ObjReloc, job: &mut LayoutJob) {
|
||||
let name = reloc.target.demangled_name.as_ref().unwrap_or(&reloc.target.name);
|
||||
write_text(name, Color32::LIGHT_GRAY, job);
|
||||
match reloc.kind {
|
||||
ObjRelocKind::PpcAddr16Lo => write_text("@l", Color32::GRAY, job),
|
||||
ObjRelocKind::PpcAddr16Hi => write_text("@h", Color32::GRAY, job),
|
||||
ObjRelocKind::PpcAddr16Ha => write_text("@ha", Color32::GRAY, job),
|
||||
ObjRelocKind::PpcEmbSda21 => write_text("@sda21", Color32::GRAY, job),
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
|
||||
fn write_ins(
|
||||
ins: &ObjIns,
|
||||
diff_kind: &ObjInsDiffKind,
|
||||
args: &[Option<ObjInsArgDiff>],
|
||||
base_addr: u32,
|
||||
job: &mut LayoutJob,
|
||||
) {
|
||||
let base_color = match diff_kind {
|
||||
ObjInsDiffKind::None | ObjInsDiffKind::OpMismatch | ObjInsDiffKind::ArgMismatch => {
|
||||
Color32::GRAY
|
||||
}
|
||||
ObjInsDiffKind::Replace => Color32::LIGHT_BLUE,
|
||||
ObjInsDiffKind::Delete => COLOR_RED,
|
||||
ObjInsDiffKind::Insert => Color32::GREEN,
|
||||
};
|
||||
write_text(
|
||||
&ins.mnemonic,
|
||||
match diff_kind {
|
||||
ObjInsDiffKind::OpMismatch => Color32::LIGHT_BLUE,
|
||||
_ => base_color,
|
||||
},
|
||||
job,
|
||||
);
|
||||
let mut writing_offset = false;
|
||||
for (i, arg) in ins.args.iter().enumerate() {
|
||||
if i == 0 {
|
||||
write_text(" ", base_color, job);
|
||||
}
|
||||
if i > 0 && !writing_offset {
|
||||
write_text(", ", base_color, job);
|
||||
}
|
||||
let color = if let Some(diff) = args.get(i).and_then(|a| a.as_ref()) {
|
||||
COLOR_ROTATION[diff.idx % COLOR_ROTATION.len()]
|
||||
} else {
|
||||
base_color
|
||||
};
|
||||
match arg {
|
||||
ObjInsArg::Arg(arg) => match arg {
|
||||
Argument::Offset(val) => {
|
||||
write_text(&format!("{}", val), color, job);
|
||||
write_text("(", base_color, job);
|
||||
writing_offset = true;
|
||||
continue;
|
||||
}
|
||||
Argument::BranchDest(dest) => {
|
||||
let addr = dest.0 + ins.ins.addr as i32 - base_addr as i32;
|
||||
write_text(&format!("{:x}", addr), color, job);
|
||||
}
|
||||
Argument::Uimm(_) | Argument::Simm(_) => {
|
||||
write_text(&format!("{}", arg), color, job);
|
||||
}
|
||||
_ => {
|
||||
write_text(&format!("{}", arg), color, job);
|
||||
}
|
||||
},
|
||||
ObjInsArg::Reloc => {
|
||||
write_reloc(ins.reloc.as_ref().unwrap(), job);
|
||||
}
|
||||
ObjInsArg::RelocOffset => {
|
||||
write_reloc(ins.reloc.as_ref().unwrap(), job);
|
||||
write_text("(", base_color, job);
|
||||
writing_offset = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if writing_offset {
|
||||
write_text(")", base_color, job);
|
||||
writing_offset = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn ins_hover_ui(ui: &mut egui::Ui, ins: &ObjIns) {
|
||||
ui.scope(|ui| {
|
||||
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
|
||||
ui.style_mut().wrap = Some(false);
|
||||
|
||||
ui.label(format!("{:02X?}", ins.ins.code.to_be_bytes()));
|
||||
|
||||
for arg in &ins.args {
|
||||
if let ObjInsArg::Arg(arg) = arg {
|
||||
match arg {
|
||||
Argument::Uimm(v) => {
|
||||
ui.label(format!("{} == {}", v, v.0));
|
||||
}
|
||||
Argument::Simm(v) => {
|
||||
ui.label(format!("{} == {}", v, v.0));
|
||||
}
|
||||
Argument::Offset(v) => {
|
||||
ui.label(format!("{} == {}", v, v.0));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(reloc) = &ins.reloc {
|
||||
ui.label(format!("Relocation type: {:?}", reloc.kind));
|
||||
ui.colored_label(Color32::WHITE, format!("Name: {}", reloc.target.name));
|
||||
if let Some(section) = &reloc.target_section {
|
||||
ui.colored_label(Color32::WHITE, format!("Section: {}", section));
|
||||
ui.colored_label(Color32::WHITE, format!("Address: {:x}", reloc.target.address));
|
||||
ui.colored_label(Color32::WHITE, format!("Size: {:x}", reloc.target.size));
|
||||
} else {
|
||||
ui.colored_label(Color32::WHITE, "Extern".to_string());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn ins_context_menu(ui: &mut egui::Ui, ins: &ObjIns) {
|
||||
ui.scope(|ui| {
|
||||
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
|
||||
ui.style_mut().wrap = Some(false);
|
||||
|
||||
// if ui.button("Copy hex").clicked() {}
|
||||
|
||||
for arg in &ins.args {
|
||||
if let ObjInsArg::Arg(arg) = arg {
|
||||
match arg {
|
||||
Argument::Uimm(v) => {
|
||||
if ui.button(format!("Copy \"{}\"", v)).clicked() {
|
||||
ui.output().copied_text = format!("{}", v);
|
||||
ui.close_menu();
|
||||
}
|
||||
if ui.button(format!("Copy \"{}\"", v.0)).clicked() {
|
||||
ui.output().copied_text = format!("{}", v.0);
|
||||
ui.close_menu();
|
||||
}
|
||||
}
|
||||
Argument::Simm(v) => {
|
||||
if ui.button(format!("Copy \"{}\"", v)).clicked() {
|
||||
ui.output().copied_text = format!("{}", v);
|
||||
ui.close_menu();
|
||||
}
|
||||
if ui.button(format!("Copy \"{}\"", v.0)).clicked() {
|
||||
ui.output().copied_text = format!("{}", v.0);
|
||||
ui.close_menu();
|
||||
}
|
||||
}
|
||||
Argument::Offset(v) => {
|
||||
if ui.button(format!("Copy \"{}\"", v)).clicked() {
|
||||
ui.output().copied_text = format!("{}", v);
|
||||
ui.close_menu();
|
||||
}
|
||||
if ui.button(format!("Copy \"{}\"", v.0)).clicked() {
|
||||
ui.output().copied_text = format!("{}", v.0);
|
||||
ui.close_menu();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(reloc) = &ins.reloc {
|
||||
if let Some(name) = &reloc.target.demangled_name {
|
||||
if ui.button(format!("Copy \"{}\"", name)).clicked() {
|
||||
ui.output().copied_text = name.clone();
|
||||
ui.close_menu();
|
||||
}
|
||||
}
|
||||
if ui.button(format!("Copy \"{}\"", reloc.target.name)).clicked() {
|
||||
ui.output().copied_text = reloc.target.name.clone();
|
||||
ui.close_menu();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const COLOR_ROTATION: [Color32; 9] = [
|
||||
Color32::from_rgb(255, 0, 255),
|
||||
Color32::from_rgb(0, 255, 255),
|
||||
Color32::from_rgb(0, 128, 0),
|
||||
Color32::from_rgb(255, 0, 0),
|
||||
Color32::from_rgb(255, 255, 0),
|
||||
Color32::from_rgb(255, 192, 203),
|
||||
Color32::from_rgb(0, 0, 255),
|
||||
Color32::from_rgb(0, 255, 0),
|
||||
Color32::from_rgb(128, 128, 128),
|
||||
];
|
||||
|
||||
fn find_symbol<'a>(obj: &'a ObjInfo, section_name: &str, name: &str) -> Option<&'a ObjSymbol> {
|
||||
let section = obj.sections.iter().find(|s| s.name == section_name)?;
|
||||
section.symbols.iter().find(|s| s.name == name)
|
||||
}
|
||||
|
||||
fn asm_row_ui(ui: &mut egui::Ui, ins_diff: &ObjInsDiff, symbol: &ObjSymbol) {
|
||||
if ins_diff.kind != ObjInsDiffKind::None {
|
||||
ui.painter().rect_filled(ui.available_rect_before_wrap(), 0.0, ui.visuals().faint_bg_color);
|
||||
}
|
||||
let mut job = LayoutJob::default();
|
||||
if let Some(ins) = &ins_diff.ins {
|
||||
let base_color = match ins_diff.kind {
|
||||
ObjInsDiffKind::None | ObjInsDiffKind::OpMismatch | ObjInsDiffKind::ArgMismatch => {
|
||||
Color32::GRAY
|
||||
}
|
||||
ObjInsDiffKind::Replace => Color32::LIGHT_BLUE,
|
||||
ObjInsDiffKind::Delete => COLOR_RED,
|
||||
ObjInsDiffKind::Insert => Color32::GREEN,
|
||||
};
|
||||
write_text(
|
||||
&format!("{:<6}", format!("{:x}:", ins.ins.addr - symbol.address as u32)),
|
||||
base_color,
|
||||
&mut job,
|
||||
);
|
||||
if let Some(branch) = &ins_diff.branch_from {
|
||||
write_text("~> ", COLOR_ROTATION[branch.branch_idx % COLOR_ROTATION.len()], &mut job);
|
||||
} else {
|
||||
write_text(" ", base_color, &mut job);
|
||||
}
|
||||
write_ins(ins, &ins_diff.kind, &ins_diff.arg_diff, symbol.address as u32, &mut job);
|
||||
if let Some(branch) = &ins_diff.branch_to {
|
||||
write_text(" ~>", COLOR_ROTATION[branch.branch_idx % COLOR_ROTATION.len()], &mut job);
|
||||
}
|
||||
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 {
|
||||
ui.label("");
|
||||
}
|
||||
}
|
||||
|
||||
fn asm_table_ui(
|
||||
table: TableBuilder<'_>,
|
||||
left_obj: &ObjInfo,
|
||||
right_obj: &ObjInfo,
|
||||
fn_name: &str,
|
||||
) -> Option<()> {
|
||||
let left_symbol = find_symbol(left_obj, ".text", fn_name)?;
|
||||
let right_symbol = find_symbol(right_obj, ".text", fn_name)?;
|
||||
table.body(|body| {
|
||||
body.rows(FONT_SIZE, left_symbol.instructions.len(), |row_index, mut row| {
|
||||
row.col(|ui| {
|
||||
asm_row_ui(ui, &left_symbol.instructions[row_index], left_symbol);
|
||||
});
|
||||
row.col(|ui| {
|
||||
asm_row_ui(ui, &right_symbol.instructions[row_index], right_symbol);
|
||||
});
|
||||
});
|
||||
});
|
||||
Some(())
|
||||
}
|
||||
|
||||
pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) {
|
||||
if let (Some(result), Some(selected_symbol)) = (&view_state.build, &view_state.selected_symbol)
|
||||
{
|
||||
StripBuilder::new(ui).size(Size::exact(40.0)).size(Size::remainder()).vertical(
|
||||
|mut strip| {
|
||||
strip.strip(|builder| {
|
||||
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| {
|
||||
let demangled = demangle(selected_symbol);
|
||||
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 asm:");
|
||||
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(obj) = &result.second_obj {
|
||||
if let Some(symbol) = find_symbol(obj, ".text", selected_symbol)
|
||||
{
|
||||
ui.colored_label(
|
||||
match_color_for_symbol(symbol),
|
||||
&format!("{:.0}%", symbol.match_percent),
|
||||
);
|
||||
}
|
||||
}
|
||||
ui.label("Diff src:");
|
||||
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);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
38
src/views/jobs.rs
Normal file
38
src/views/jobs.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
use egui::{Color32, ProgressBar, Widget};
|
||||
|
||||
use crate::app::ViewState;
|
||||
|
||||
pub fn jobs_ui(ui: &mut egui::Ui, view_state: &ViewState) {
|
||||
ui.label("Jobs");
|
||||
|
||||
for job in &view_state.jobs {
|
||||
if let Ok(status) = job.status.read() {
|
||||
ui.group(|ui| {
|
||||
ui.label(&status.title);
|
||||
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 {
|
||||
format!("{:width$}", &status.status, width = STATUS_LENGTH)
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
4
src/views/mod.rs
Normal file
4
src/views/mod.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
pub(crate) mod config;
|
||||
pub(crate) mod function_diff;
|
||||
pub(crate) mod jobs;
|
||||
pub(crate) mod symbol_diff;
|
||||
240
src/views/symbol_diff.rs
Normal file
240
src/views/symbol_diff.rs
Normal file
@@ -0,0 +1,240 @@
|
||||
use egui::{
|
||||
text::LayoutJob, CollapsingHeader, Color32, FontFamily, FontId, Rgba, ScrollArea,
|
||||
SelectableLabel, TextFormat, Ui, Widget,
|
||||
};
|
||||
use egui_extras::{Size, StripBuilder};
|
||||
|
||||
use crate::{
|
||||
app::{View, ViewState},
|
||||
jobs::build::BuildStatus,
|
||||
obj::{ObjInfo, ObjSymbol, ObjSymbolFlags},
|
||||
};
|
||||
|
||||
pub fn match_color_for_symbol(symbol: &ObjSymbol) -> Color32 {
|
||||
if symbol.match_percent == 100.0 {
|
||||
Color32::GREEN
|
||||
} else if symbol.match_percent >= 50.0 {
|
||||
Color32::LIGHT_BLUE
|
||||
} else {
|
||||
Color32::RED
|
||||
}
|
||||
}
|
||||
|
||||
fn symbol_ui(
|
||||
ui: &mut Ui,
|
||||
symbol: &ObjSymbol,
|
||||
highlighted_symbol: &mut Option<String>,
|
||||
selected_symbol: &mut Option<String>,
|
||||
current_view: &mut View,
|
||||
) {
|
||||
let mut job = LayoutJob::default();
|
||||
let name: &str =
|
||||
if let Some(demangled) = &symbol.demangled_name { demangled } else { &symbol.name };
|
||||
let mut selected = false;
|
||||
if let Some(sym) = highlighted_symbol {
|
||||
selected = sym == &symbol.name;
|
||||
}
|
||||
let font_id = FontId::new(14.0, FontFamily::Monospace);
|
||||
job.append("[", 0.0, TextFormat {
|
||||
font_id: font_id.clone(),
|
||||
color: Color32::GRAY,
|
||||
..Default::default()
|
||||
});
|
||||
if symbol.flags.0.contains(ObjSymbolFlags::Common) {
|
||||
job.append("c", 0.0, TextFormat {
|
||||
font_id: font_id.clone(),
|
||||
color: Color32::from_rgb(0, 255, 255),
|
||||
..Default::default()
|
||||
});
|
||||
} else if symbol.flags.0.contains(ObjSymbolFlags::Global) {
|
||||
job.append("g", 0.0, TextFormat {
|
||||
font_id: font_id.clone(),
|
||||
color: Color32::GREEN,
|
||||
..Default::default()
|
||||
});
|
||||
} else if symbol.flags.0.contains(ObjSymbolFlags::Local) {
|
||||
job.append("l", 0.0, TextFormat {
|
||||
font_id: font_id.clone(),
|
||||
color: Color32::GRAY,
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
if symbol.flags.0.contains(ObjSymbolFlags::Weak) {
|
||||
job.append("w", 0.0, TextFormat {
|
||||
font_id: font_id.clone(),
|
||||
color: Color32::GRAY,
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
job.append("] (", 0.0, TextFormat {
|
||||
font_id: font_id.clone(),
|
||||
color: Color32::GRAY,
|
||||
..Default::default()
|
||||
});
|
||||
job.append(&format!("{:.0}%", symbol.match_percent), 0.0, TextFormat {
|
||||
font_id: font_id.clone(),
|
||||
color: match_color_for_symbol(symbol),
|
||||
..Default::default()
|
||||
});
|
||||
job.append(") ", 0.0, TextFormat {
|
||||
font_id: font_id.clone(),
|
||||
color: Color32::GRAY,
|
||||
..Default::default()
|
||||
});
|
||||
job.append(name, 0.0, TextFormat { font_id, color: Color32::WHITE, ..Default::default() });
|
||||
let response = SelectableLabel::new(selected, job).ui(ui);
|
||||
if response.clicked() {
|
||||
*selected_symbol = Some(symbol.name.clone());
|
||||
*current_view = View::FunctionDiff;
|
||||
} else if response.hovered() {
|
||||
*highlighted_symbol = Some(symbol.name.clone());
|
||||
}
|
||||
}
|
||||
|
||||
fn symbol_list_ui(
|
||||
ui: &mut Ui,
|
||||
obj: &ObjInfo,
|
||||
highlighted_symbol: &mut Option<String>,
|
||||
selected_symbol: &mut Option<String>,
|
||||
current_view: &mut View,
|
||||
reverse_function_order: bool,
|
||||
) {
|
||||
ScrollArea::both().auto_shrink([false, false]).show(ui, |ui| {
|
||||
ui.scope(|ui| {
|
||||
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
|
||||
ui.style_mut().wrap = Some(false);
|
||||
|
||||
if !obj.common.is_empty() {
|
||||
CollapsingHeader::new(".comm").default_open(true).show(ui, |ui| {
|
||||
for symbol in &obj.common {
|
||||
symbol_ui(ui, symbol, highlighted_symbol, selected_symbol, current_view);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for section in &obj.sections {
|
||||
CollapsingHeader::new(format!("{} ({:x})", section.name, section.size))
|
||||
.default_open(true)
|
||||
.show(ui, |ui| {
|
||||
if section.name == ".text" && reverse_function_order {
|
||||
for symbol in section.symbols.iter().rev() {
|
||||
symbol_ui(
|
||||
ui,
|
||||
symbol,
|
||||
highlighted_symbol,
|
||||
selected_symbol,
|
||||
current_view,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
for symbol in §ion.symbols {
|
||||
symbol_ui(
|
||||
ui,
|
||||
symbol,
|
||||
highlighted_symbol,
|
||||
selected_symbol,
|
||||
current_view,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn build_log_ui(ui: &mut Ui, status: &BuildStatus) {
|
||||
ui.scope(|ui| {
|
||||
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
|
||||
ui.style_mut().wrap = Some(false);
|
||||
ui.colored_label(Color32::from_rgb(255, 0, 0), &status.log);
|
||||
});
|
||||
}
|
||||
|
||||
pub fn symbol_diff_ui(ui: &mut Ui, view_state: &mut ViewState) {
|
||||
if let (Some(result), highlighted_symbol, selected_symbol, current_view) = (
|
||||
&view_state.build,
|
||||
&mut view_state.highlighted_symbol,
|
||||
&mut view_state.selected_symbol,
|
||||
&mut view_state.current_view,
|
||||
) {
|
||||
StripBuilder::new(ui).size(Size::exact(40.0)).size(Size::remainder()).vertical(
|
||||
|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 asm:");
|
||||
if result.first_status.success {
|
||||
ui.label("OK");
|
||||
} else {
|
||||
ui.colored_label(Rgba::from_rgb(1.0, 0.0, 0.0), "Fail");
|
||||
}
|
||||
});
|
||||
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("Build src:");
|
||||
if result.second_status.success {
|
||||
ui.label("OK");
|
||||
} else {
|
||||
ui.colored_label(Rgba::from_rgb(1.0, 0.0, 0.0), "Fail");
|
||||
}
|
||||
});
|
||||
ui.separator();
|
||||
});
|
||||
});
|
||||
});
|
||||
strip.strip(|builder| {
|
||||
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| {
|
||||
strip.cell(|ui| {
|
||||
if result.first_status.success {
|
||||
if let Some(obj) = &result.first_obj {
|
||||
ui.push_id("left", |ui| {
|
||||
symbol_list_ui(
|
||||
ui,
|
||||
obj,
|
||||
highlighted_symbol,
|
||||
selected_symbol,
|
||||
current_view,
|
||||
view_state.reverse_fn_order,
|
||||
);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
build_log_ui(ui, &result.first_status);
|
||||
}
|
||||
});
|
||||
strip.cell(|ui| {
|
||||
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,
|
||||
);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
build_log_ui(ui, &result.second_status);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user