Skip to content

Commit

Permalink
Clickable labels added to function listing.
Browse files Browse the repository at this point in the history
  • Loading branch information
WINSDK committed Apr 18, 2024
1 parent 21ee2d0 commit dbcd4ea
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 53 deletions.
39 changes: 23 additions & 16 deletions gui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod common;
mod fmt;
mod icon;
mod interp;
mod panels;
mod panes;
mod style;
mod wgpu_backend;
mod widgets;
Expand Down Expand Up @@ -57,6 +57,7 @@ pub enum UIEvent {
BinaryRequested(std::path::PathBuf),
BinaryFailed(processor::Error),
BinaryLoaded(processor::Processor),
GotoAddr(usize),
}

#[derive(Clone)]
Expand Down Expand Up @@ -86,7 +87,7 @@ pub struct UI {
arch: Arch,
window: &'static Window, // Box::leak'd
event_loop: Option<EventLoop<WinitEvent>>,
panels: panels::Panels,
panels: panes::Panels,
instance: wgpu_backend::Instance<'static>,
egui_render_pass: wgpu_backend::egui::Pipeline,
platform: winit_backend::Platform,
Expand Down Expand Up @@ -117,7 +118,7 @@ impl UI {
inner: event_loop.create_proxy(),
};

let panels = panels::Panels::new(ui_queue.clone(), winit_queue.clone());
let panels = panes::Panels::new(ui_queue.clone(), winit_queue);
let instance = wgpu_backend::Instance::new(window)?;
let egui_render_pass = wgpu_backend::egui::Pipeline::new(&instance, 1);
let platform = winit_backend::Platform::new(window);
Expand Down Expand Up @@ -162,23 +163,23 @@ impl UI {
while let Ok(event) = self.arch.menu_channel.try_recv() {
match event.id.0.as_str() {
"open" => self.panels.ask_for_binary(),
panels::SOURCE => {
self.panels.goto_window(panels::SOURCE);
self.arch.bar.set_checked(panels::SOURCE);
panes::SOURCE => {
self.panels.goto_window(panes::SOURCE);
self.arch.bar.set_checked(panes::SOURCE);
}
panels::DISASSEMBLY => {
self.panels.goto_window(panels::DISASSEMBLY);
self.arch.bar.set_checked(panels::DISASSEMBLY);
panes::DISASSEMBLY => {
self.panels.goto_window(panes::DISASSEMBLY);
self.arch.bar.set_checked(panes::DISASSEMBLY);
}
panels::FUNCTIONS => {
self.panels.goto_window(panels::FUNCTIONS);
self.arch.bar.set_checked(panels::FUNCTIONS);
panes::FUNCTIONS => {
self.panels.goto_window(panes::FUNCTIONS);
self.arch.bar.set_checked(panes::FUNCTIONS);
}
panels::LOGGING => {
self.panels.goto_window(panels::LOGGING);
self.arch.bar.set_checked(panels::LOGGING);
panes::LOGGING => {
self.panels.goto_window(panes::LOGGING);
self.arch.bar.set_checked(panes::LOGGING);
}
_ => { dbg!(event.id.0.as_str()); }
_ => {}
}
}

Expand All @@ -198,6 +199,12 @@ impl UI {
self.panels.stop_loading();
self.panels.load_binary(disassembly);
}
UIEvent::GotoAddr(addr) => {
if let Some(listing) = self.panels.listing() {
listing.jump(addr);
self.panels.goto_window(panes::DISASSEMBLY);
}
}
}
}
}
Expand Down
33 changes: 19 additions & 14 deletions gui/src/panels/functions.rs → gui/src/panes/functions.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
use crate::common::*;

use crate::{UIQueue, UIEvent};
use config::CONFIG;
use processor_shared::Addressed;
use egui::text::LayoutJob;
use processor::Processor;
use std::sync::Arc;
use tokenizing::{colors, Token};

pub struct Functions {
processor: Arc<Processor>,
lines: LayoutJob,
ui_queue: Arc<UIQueue>,
lines: Vec<(usize, Vec<Token>)>,
lines_count: usize,
min_row: usize,
max_row: usize,
}

impl Functions {
pub fn new(processor: Arc<Processor>) -> Self {
pub fn new(processor: Arc<Processor>, ui_queue: Arc<UIQueue>) -> Self {
let function_count = processor.index.named_funcs_count();

Self {
processor,
lines: LayoutJob::default(),
ui_queue,
lines: Vec::new(),
lines_count: function_count,
min_row: 0,
max_row: 0,
}
}
}

fn tokenize_functions(index: &debugvault::Index, range: std::ops::Range<usize>) -> Vec<Token> {
let mut tokens: Vec<Token> = Vec::new();

fn tokenize_functions(index: &debugvault::Index, range: std::ops::Range<usize>) -> Vec<(usize, Vec<Token>)> {
let mut functions = Vec::new();
let lines_to_read = range.end - range.start;
let lines = index
.functions()
.filter(|func| !func.item.intrinsic())
.skip(range.start)
.take(lines_to_read + 10);

// for each instruction
for Addressed { addr, item } in lines {
let mut tokens = Vec::new();
tokens.push(Token::from_string(format!("{addr:0>10X}"), colors::WHITE));
tokens.push(Token::from_str(" | ", colors::WHITE));

Expand All @@ -53,10 +53,10 @@ fn tokenize_functions(index: &debugvault::Index, range: std::ops::Range<usize>)
tokens.push(token.clone());
}

tokens.push(Token::from_str("\n", colors::WHITE));
functions.push((*addr, tokens));
}

tokens
functions
}

impl Display for Functions {
Expand All @@ -65,14 +65,19 @@ impl Display for Functions {

area.show_rows(ui, FONT.size, self.lines_count, |ui, row_range| {
if row_range != (self.min_row..self.max_row) {
let functions = tokenize_functions(&self.processor.index, row_range.clone());
self.lines = tokens_to_layoutjob(functions);
self.lines = tokenize_functions(&self.processor.index, row_range.clone());
self.lines_count = self.processor.index.named_funcs_count();
self.min_row = row_range.start;
self.max_row = row_range.end;
}

ui.label(self.lines.clone());
for (addr, line) in self.lines.iter() {
let output = tokens_to_layoutjob(line.clone());

if ui.link(output).clicked() {
self.ui_queue.push(UIEvent::GotoAddr(*addr));
}
}
});
}
}
7 changes: 5 additions & 2 deletions gui/src/panels/listing.rs → gui/src/panes/listing.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::common::*;
use crate::{common::*, UIQueue};
use config::CONFIG;
use egui::mutex::RwLock;
use egui::Color32;
Expand All @@ -10,6 +10,8 @@ use tokenizing::{colors, TokenStream};

pub struct Listing {
processor: Arc<Processor>,
#[allow(dead_code)]
ui_queue: Arc<UIQueue>,
boundaries: Arc<RwLock<Vec<usize>>>,
scroll: InfiniteScroll<Block, usize>,
reset_position: Arc<AtomicUsize>,
Expand All @@ -18,7 +20,7 @@ pub struct Listing {
}

impl Listing {
pub fn new(processor: Arc<Processor>) -> Self {
pub fn new(processor: Arc<Processor>, ui_queue: Arc<UIQueue>) -> Self {
let boundaries: Arc<RwLock<Vec<usize>>> = Arc::default();

{
Expand Down Expand Up @@ -128,6 +130,7 @@ impl Listing {

Self {
scroll,
ui_queue,
boundaries,
processor,
reset_position,
Expand Down
27 changes: 17 additions & 10 deletions gui/src/panels/mod.rs → gui/src/panes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ mod functions;
mod listing;
mod source_code;

use crate::common::*;
use crate::style::{EGUI, STYLE};
use crate::widgets::{Donut, Terminal};
use egui_tiles::{Container, SimplificationOptions, Tile, TileId, Tiles, Tree, UiResponse};
use crate::{common::*, WinitQueue};
use config::CONFIG;
use egui_tiles::{Container, SimplificationOptions, Tile, TileId, Tiles, Tree, UiResponse};
use processor::Processor;
use tokenizing::colors;

Expand Down Expand Up @@ -100,7 +100,7 @@ impl egui_tiles::Behavior<Identifier> for Tabs {
ui: &mut egui::Ui,
_tile_id: egui_tiles::TileId,
pane: &mut Identifier,
) -> egui_tiles::UiResponse {
) -> UiResponse {
// Set pane background color.
ui.painter().rect_filled(ui.max_rect(), 0.0, CONFIG.colors.bg_primary);

Expand Down Expand Up @@ -129,15 +129,16 @@ impl egui_tiles::Behavior<Identifier> for Tabs {
}

pub struct Panels {
pub tree: egui_tiles::Tree<Identifier>,
pub panes: Tabs,
pub ui_queue: Arc<crate::UIQueue>,
pub winit_queue: crate::WinitQueue,
tree: Tree<Identifier>,
panes: Tabs,
ui_queue: Arc<crate::UIQueue>,
#[allow(dead_code)] // used on windows and linux for top bar
winit_queue: WinitQueue,
loading: bool,
}

impl Panels {
pub fn new(ui_queue: Arc<crate::UIQueue>, winit_queue: crate::WinitQueue) -> Self {
pub fn new(ui_queue: Arc<crate::UIQueue>, winit_queue: WinitQueue) -> Self {
let mut tiles = Tiles::default();
let tabs = vec![
tiles.insert_pane(DISASSEMBLY),
Expand Down Expand Up @@ -205,12 +206,18 @@ impl Panels {

self.panes.mapping.insert(
DISASSEMBLY,
PanelKind::Disassembly(listing::Listing::new(processor.clone())),
PanelKind::Disassembly(listing::Listing::new(
processor.clone(),
self.ui_queue.clone(),
)),
);

self.panes.mapping.insert(
FUNCTIONS,
PanelKind::Functions(functions::Functions::new(processor.clone())),
PanelKind::Functions(functions::Functions::new(
processor.clone(),
self.ui_queue.clone(),
)),
);

self.panes.processor = Some(processor);
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions gui/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub static EGUI: Lazy<egui::Style> = Lazy::new(|| egui::Style {
rounding: STYLE.tab_rounding,
bg_stroke: Stroke::NONE,
fg_stroke: Stroke {
width: 5.0,
width: 0.0,
color: STYLE.active_text_color,
},
expansion: 0.0,
Expand All @@ -51,7 +51,7 @@ pub static EGUI: Lazy<egui::Style> = Lazy::new(|| egui::Style {
rounding: STYLE.tab_rounding,
bg_stroke: Stroke::NONE,
fg_stroke: Stroke {
width: 5.0,
width: 0.0,
color: STYLE.text_color,
},
expansion: 0.0,
Expand All @@ -62,7 +62,7 @@ pub static EGUI: Lazy<egui::Style> = Lazy::new(|| egui::Style {
rounding: STYLE.tab_rounding,
bg_stroke: Stroke::NONE,
fg_stroke: Stroke {
width: 5.0,
width: 0.0,
color: STYLE.text_color,
},
expansion: 0.0,
Expand All @@ -73,7 +73,7 @@ pub static EGUI: Lazy<egui::Style> = Lazy::new(|| egui::Style {
rounding: STYLE.tab_rounding,
bg_stroke: Stroke::NONE,
fg_stroke: Stroke {
width: 5.0,
width: 0.0,
color: STYLE.active_text_color,
},
expansion: 0.0,
Expand All @@ -84,7 +84,7 @@ pub static EGUI: Lazy<egui::Style> = Lazy::new(|| egui::Style {
rounding: STYLE.tab_rounding,
bg_stroke: Stroke::NONE,
fg_stroke: Stroke {
width: 5.0,
width: 0.0,
color: STYLE.text_color,
},
expansion: 0.0,
Expand Down
10 changes: 5 additions & 5 deletions gui/src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod macos {
use muda::{MenuEvent, MenuEventReceiver};
use std::mem::ManuallyDrop;
use std::path::Path;
use crate::panels::{self, Identifier};
use crate::panes::{self, Identifier};

pub struct Arch {
pub menu_channel: MenuEventReceiver,
Expand Down Expand Up @@ -77,28 +77,28 @@ mod macos {

let mut windows = Vec::new();
windows.push(CheckMenuItem::with_id(
panels::DISASSEMBLY,
panes::DISASSEMBLY,
"Disassembly",
true,
true,
None,
));
windows.push(CheckMenuItem::with_id(
panels::FUNCTIONS,
panes::FUNCTIONS,
"Functions",
true,
false,
None,
));
windows.push(CheckMenuItem::with_id(
panels::SOURCE,
panes::SOURCE,
"Source",
true,
false,
None,
));
windows.push(CheckMenuItem::with_id(
panels::LOGGING,
panes::LOGGING,
"Logging",
true,
false,
Expand Down
2 changes: 1 addition & 1 deletion gui/src/wgpu_backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl<'window> Instance<'window> {
window: &crate::Window,
platform: &mut crate::winit_backend::Platform,
render_pass: &mut egui::Pipeline,
panels: &mut crate::panels::Panels,
panels: &mut crate::panes::Panels,
) -> Result<(), Error> {
let frame = match self.surface.get_current_texture() {
Ok(frame) => frame,
Expand Down

0 comments on commit dbcd4ea

Please sign in to comment.