Add support for listing symbols

This commit is contained in:
pjht 2022-10-12 16:18:45 -05:00
parent 4a0ad44276
commit 2ee7f27b32

View File

@ -14,7 +14,10 @@ use crate::{
m68k::{BusError, M68K},
};
use disas::DisassemblyError;
use elf::symbol::Symbol;
use elf::{
gabi::{STT_FILE, STT_SECTION},
symbol::Symbol,
};
use itertools::Itertools;
use parse_int::parse;
use reedline_repl_rs::{
@ -425,11 +428,7 @@ fn main() -> Result<(), ReplError> {
)
.with_command(
Command::new("sym")
.arg(
Arg::new("file")
.required(true)
.help("The ELF file to load symbols from"),
)
.arg(Arg::new("file").help("The ELF file to load symbols from"))
.arg(
Arg::new("append")
.long("append")
@ -437,9 +436,9 @@ fn main() -> Result<(), ReplError> {
.action(ArgAction::SetTrue)
.help("Append the file's symbols to the loaded list of symbols"),
)
.about("Load symbols from an ELF file"),
.about("Load symbols from an ELF file, or list symbols if no file provided"),
|args, state| {
let file = args.get_one::<String>("file").unwrap();
if let Some(file) = args.get_one::<String>("file") {
let file = elf::File::open_path(file).map_err(<Box<dyn error::Error>>::from)?;
let symtab = file
.get_section(".symtab")
@ -453,6 +452,17 @@ fn main() -> Result<(), ReplError> {
state.symbols = symbols;
}
Ok(None)
} else {
#[allow(unstable_name_collisions)]
Ok(Some(
state
.symbols
.iter()
.map(ToString::to_string)
.intersperse("\n".to_string())
.collect::<String>(),
))
}
},
)
.with_command(