Display Symbol information
This commit is contained in:
parent
c49644e5b0
commit
3e0da33bb8
|
@ -24,6 +24,20 @@ impl Section {
|
|||
}
|
||||
}
|
||||
|
||||
impl NamedMemoryArea for Section {
|
||||
fn get_name(&self) -> &str {
|
||||
self.name.as_str()
|
||||
}
|
||||
|
||||
fn get_adr(&self) -> u64 {
|
||||
self.adr
|
||||
}
|
||||
|
||||
fn get_size(&self) -> usize {
|
||||
self.size
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Symbol {
|
||||
pub name: String,
|
||||
|
@ -35,4 +49,28 @@ impl Symbol {
|
|||
pub fn new(name: String, adr: u64, size: usize) -> Symbol {
|
||||
Symbol{name, adr, size}
|
||||
}
|
||||
}
|
||||
|
||||
impl NamedMemoryArea for Symbol {
|
||||
fn get_name(&self) -> &str {
|
||||
self.name.as_str()
|
||||
}
|
||||
|
||||
fn get_adr(&self) -> u64 {
|
||||
self.adr
|
||||
}
|
||||
|
||||
fn get_size(&self) -> usize {
|
||||
self.size
|
||||
}
|
||||
}
|
||||
|
||||
pub trait NamedMemoryArea {
|
||||
fn get_name(&self) -> &str;
|
||||
fn get_adr(&self) -> u64;
|
||||
fn get_size(&self) -> usize;
|
||||
|
||||
fn get_end_adr(&self) -> u64 {
|
||||
self.get_adr() + self.get_size() as u64
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
mod readmap_helper;
|
||||
use crossterm::event::{KeyCode, KeyEvent};
|
||||
use readmap::types::{MemoryMap, Symbol};
|
||||
use readmap::types::{MemoryMap, NamedMemoryArea, Symbol};
|
||||
use std::{convert::From, path::PathBuf};
|
||||
use tool_helper::Error;
|
||||
use ratatui::{
|
||||
|
@ -115,17 +115,23 @@ impl<T:ID + Copy> DualSelection<T> {
|
|||
}
|
||||
|
||||
fn normalize_with(&mut self, max: i64) {
|
||||
let mut cur_idx = self.idx[self.mode.get_id()];
|
||||
|
||||
while cur_idx < 0 {
|
||||
cur_idx += max;
|
||||
}
|
||||
|
||||
if cur_idx >= max {
|
||||
cur_idx %= max;
|
||||
if max == 0 {
|
||||
self.idx[self.mode.get_id()] = 0;
|
||||
}
|
||||
|
||||
self.idx[self.mode.get_id()] = cur_idx;
|
||||
else {
|
||||
let mut cur_idx = self.idx[self.mode.get_id()];
|
||||
|
||||
while cur_idx < 0 {
|
||||
cur_idx += max;
|
||||
}
|
||||
|
||||
if cur_idx >= max {
|
||||
cur_idx %= max;
|
||||
}
|
||||
|
||||
self.idx[self.mode.get_id()] = cur_idx;
|
||||
}
|
||||
}
|
||||
|
||||
fn switch_mode_to(&mut self, section_mode: T) {
|
||||
|
@ -353,14 +359,14 @@ impl ConsoleUI {
|
|||
}
|
||||
};
|
||||
|
||||
if matches!(self.list_section_selection.mode, ListSectionMode::TopSection) {
|
||||
self.list_section_selection.normalize_with(self.data.section_info.len() as i64);
|
||||
}
|
||||
|
||||
else {
|
||||
let length = Self::get_selected_top_section(&self.list_section_selection, &self.data).symbols.len();
|
||||
self.list_section_selection.normalize_with(length as i64);
|
||||
}
|
||||
let length = {
|
||||
match self.list_section_selection.mode {
|
||||
ListSectionMode::TopSection => self.data.section_info.len() as i64,
|
||||
ListSectionMode::Section => Self::get_selected_top_section(&self.list_section_selection, &self.data).symbols.len() as i64
|
||||
}
|
||||
};
|
||||
|
||||
self.list_section_selection.normalize_with(length);
|
||||
result
|
||||
}
|
||||
|
||||
|
@ -412,13 +418,9 @@ impl ConsoleUI {
|
|||
.block(Self::create_default_border("Section"))
|
||||
.highlight_style(Style::default().bg(Color::White));
|
||||
|
||||
let top_section = Self::get_selected_top_section(section_selection, data);
|
||||
let info_text = Paragraph::new(format!("Name: {}\nAdr: 0x{:X} - 0x{:X}\nSize: {} Bytes", top_section.name, top_section.start_adr, top_section.get_end_adr(), top_section.size))
|
||||
.style(Style::default().fg(Color::White))
|
||||
.alignment(Alignment::Left)
|
||||
.block(Self::create_default_border("Information"));
|
||||
let top_section = Self::get_selected_top_section(section_selection, data);
|
||||
let mut info_data: &dyn NamedMemoryArea = top_section;
|
||||
|
||||
frame.render_widget(info_text, info_layout);
|
||||
frame.render_stateful_widget(section_list, list_layout[0], &mut section_selection.get_selection_state_for(ListSectionMode::TopSection));
|
||||
|
||||
if matches!(section_selection.mode, ListSectionMode::TopSection) {
|
||||
|
@ -438,8 +440,19 @@ impl ConsoleUI {
|
|||
.block(Self::create_default_border(format!("Symbols in {}", top_section.name)))
|
||||
.highlight_style(Style::default().bg(Color::White));
|
||||
|
||||
let current_selection = section_selection.get_selection_for(ListSectionMode::Section);
|
||||
if top_section.symbols.len() > 0 {
|
||||
info_data = &top_section.symbols[current_selection];
|
||||
}
|
||||
|
||||
frame.render_stateful_widget(symbol_list, list_layout[1], &mut section_selection.get_selection_state_for(ListSectionMode::Section));
|
||||
}
|
||||
|
||||
let info_text = Paragraph::new(format!("Name: {}\nAdr: 0x{:X} - 0x{:X}\nSize: {} Bytes", info_data.get_name(), info_data.get_adr(), info_data.get_end_adr(), info_data.get_size()))
|
||||
.style(Style::default().fg(Color::White))
|
||||
.alignment(Alignment::Left)
|
||||
.block(Self::create_default_border("Information"));
|
||||
frame.render_widget(info_text, info_layout);
|
||||
}
|
||||
|
||||
fn render_quit(frame: &mut ConsoleFrame, layout: Rect) {
|
||||
|
@ -552,15 +565,25 @@ struct SectionInfo {
|
|||
}
|
||||
|
||||
impl SectionInfo {
|
||||
fn get_end_adr(&self) -> u64 {
|
||||
self.start_adr + self.size as u64
|
||||
}
|
||||
|
||||
fn get_size_ratio(&self) -> f64 {
|
||||
self.size as f64 / self.max_size as f64
|
||||
}
|
||||
}
|
||||
|
||||
impl NamedMemoryArea for SectionInfo {
|
||||
fn get_name(&self) -> &str {
|
||||
self.name.as_str()
|
||||
}
|
||||
|
||||
fn get_adr(&self) -> u64 {
|
||||
self.start_adr
|
||||
}
|
||||
|
||||
fn get_size(&self) -> usize {
|
||||
self.size
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_memory_map(use_wsl: bool, input: PathBuf) -> Result<MemoryMap, Error> {
|
||||
readmap_helper::generate_memory_map(use_wsl, input)
|
||||
}
|
Loading…
Reference in New Issue