Hide hidden symbols by default; add "Diff Options" to menu

This commit is contained in:
Luke Street 2023-10-07 13:27:12 -04:00
parent e1dc84698f
commit 803eaafee6
4 changed files with 47 additions and 9 deletions

View File

@ -373,15 +373,23 @@ impl eframe::App for App {
egui::TopBottomPanel::top("top_panel").show(ctx, |ui| { egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
egui::menu::bar(ui, |ui| { egui::menu::bar(ui, |ui| {
ui.menu_button("File", |ui| { ui.menu_button("File", |ui| {
if ui.button("Project…").clicked() {
*show_project_config = !*show_project_config;
ui.close_menu();
}
let recent_projects = if let Ok(guard) = config.read() { let recent_projects = if let Ok(guard) = config.read() {
guard.recent_projects.clone() guard.recent_projects.clone()
} else { } else {
vec![] vec![]
}; };
if recent_projects.is_empty() { if recent_projects.is_empty() {
ui.add_enabled(false, egui::Button::new("Recent Projects…")); ui.add_enabled(false, egui::Button::new("Recent projects…"));
} else { } else {
ui.menu_button("Recent Projects…", |ui| { ui.menu_button("Recent Projects…", |ui| {
if ui.button("Clear").clicked() {
config.write().unwrap().recent_projects.clear();
};
ui.separator();
for path in recent_projects { for path in recent_projects {
if ui.button(format!("{}", path.display())).clicked() { if ui.button(format!("{}", path.display())).clicked() {
config.write().unwrap().set_project_dir(path); config.write().unwrap().set_project_dir(path);
@ -404,6 +412,29 @@ impl eframe::App for App {
ui.close_menu(); ui.close_menu();
} }
}); });
ui.menu_button("Diff Options", |ui| {
let mut config = config.write().unwrap();
let response = ui
.checkbox(&mut config.rebuild_on_changes, "Rebuild on changes")
.on_hover_text("Automatically re-run the build & diff when files change.");
if response.changed() {
config.watcher_change = true;
};
ui.add_enabled(
!diff_state.symbol_state.disable_reverse_fn_order,
egui::Checkbox::new(
&mut diff_state.symbol_state.reverse_fn_order,
"Reverse function order (-inline deferred)",
),
)
.on_disabled_hover_text(
"Option disabled because it's set by the project configuration file.",
);
ui.checkbox(
&mut diff_state.symbol_state.show_hidden_symbols,
"Show hidden symbols",
);
});
}); });
}); });

View File

@ -6,7 +6,7 @@ use cwdemangle::demangle;
use flagset::Flags; use flagset::Flags;
use object::{ use object::{
elf, Architecture, File, Object, ObjectSection, ObjectSymbol, RelocationKind, RelocationTarget, elf, Architecture, File, Object, ObjectSection, ObjectSymbol, RelocationKind, RelocationTarget,
SectionIndex, SectionKind, Symbol, SymbolKind, SymbolSection, SectionIndex, SectionKind, Symbol, SymbolKind, SymbolScope, SymbolSection,
}; };
use crate::obj::{ use crate::obj::{
@ -42,6 +42,9 @@ fn to_obj_symbol(obj_file: &File<'_>, symbol: &Symbol<'_, '_>, addend: i64) -> R
if symbol.is_weak() { if symbol.is_weak() {
flags = ObjSymbolFlagSet(flags.0 | ObjSymbolFlags::Weak); flags = ObjSymbolFlagSet(flags.0 | ObjSymbolFlags::Weak);
} }
if symbol.scope() == SymbolScope::Linkage {
flags = ObjSymbolFlagSet(flags.0 | ObjSymbolFlags::Hidden);
}
let section_address = if let Some(section) = let section_address = if let Some(section) =
symbol.section_index().and_then(|idx| obj_file.section_by_index(idx).ok()) symbol.section_index().and_then(|idx| obj_file.section_by_index(idx).ok())
{ {

View File

@ -18,6 +18,7 @@ flags! {
Local, Local,
Weak, Weak,
Common, Common,
Hidden,
} }
} }
#[derive(Debug, Copy, Clone, Default)] #[derive(Debug, Copy, Clone, Default)]

View File

@ -47,6 +47,7 @@ pub struct SymbolViewState {
pub selected_symbol: Option<SymbolReference>, pub selected_symbol: Option<SymbolReference>,
pub reverse_fn_order: bool, pub reverse_fn_order: bool,
pub disable_reverse_fn_order: bool, pub disable_reverse_fn_order: bool,
pub show_hidden_symbols: bool,
} }
impl DiffViewState { impl DiffViewState {
@ -136,6 +137,9 @@ fn symbol_ui(
state: &mut SymbolViewState, state: &mut SymbolViewState,
appearance: &Appearance, appearance: &Appearance,
) -> Option<View> { ) -> Option<View> {
if symbol.flags.0.contains(ObjSymbolFlags::Hidden) && !state.show_hidden_symbols {
return None;
}
let mut ret = None; let mut ret = None;
let mut job = LayoutJob::default(); let mut job = LayoutJob::default();
let name: &str = let name: &str =
@ -155,6 +159,9 @@ fn symbol_ui(
if symbol.flags.0.contains(ObjSymbolFlags::Weak) { if symbol.flags.0.contains(ObjSymbolFlags::Weak) {
write_text("w", appearance.text_color, &mut job, appearance.code_font.clone()); write_text("w", appearance.text_color, &mut job, appearance.code_font.clone());
} }
if symbol.flags.0.contains(ObjSymbolFlags::Hidden) {
write_text("h", appearance.deemphasized_text_color, &mut job, appearance.code_font.clone());
}
write_text("] ", appearance.text_color, &mut job, appearance.code_font.clone()); write_text("] ", appearance.text_color, &mut job, appearance.code_font.clone());
if let Some(match_percent) = symbol.match_percent { if let Some(match_percent) = symbol.match_percent {
write_text("(", appearance.text_color, &mut job, appearance.code_font.clone()); write_text("(", appearance.text_color, &mut job, appearance.code_font.clone());
@ -336,13 +343,9 @@ pub fn symbol_diff_ui(ui: &mut Ui, state: &mut DiffViewState, appearance: &Appea
} }
}); });
ui.add_enabled( if ui.add_enabled(!state.build_running, egui::Button::new("Build")).clicked() {
!symbol_state.disable_reverse_fn_order, state.queue_build = true;
egui::Checkbox::new( }
&mut symbol_state.reverse_fn_order,
"Reverse function order (-inline deferred)",
),
);
}, },
); );
}, },