Parse ELF exclusively on emulation thread

This commit is contained in:
2025-08-30 13:02:38 -04:00
parent e5abd48337
commit 04c92c1454
9 changed files with 182 additions and 137 deletions
+2 -4
View File
@@ -24,10 +24,8 @@ impl Recording {
let process =
profile.add_process(state.name(), 1, Timestamp::from_nanos_since_reference(0));
if let Some(symbol_file) = state.symbol_file() {
let lib = profile.add_lib(symbol_file.library_info().clone());
profile.add_lib_mapping(process, lib, 0x00000000, 0xffffffff, 0);
}
let lib = profile.add_lib(state.library_info().clone());
profile.add_lib_mapping(process, lib, 0x00000000, 0xffffffff, 0);
let mut me = Self {
profile,
+9 -20
View File
@@ -1,12 +1,12 @@
use std::{collections::HashMap, path::PathBuf};
use std::{collections::HashMap, sync::Arc};
use anyhow::{Result, bail};
use fxprof_processed_profile::LibraryInfo;
use crate::profiler::symbols::SymbolFile;
use crate::emulator::GameInfo;
pub struct ProgramState {
name: String,
symbol_file: Option<SymbolFile>,
info: Arc<GameInfo>,
call_stacks: HashMap<u16, Vec<StackFrame>>,
context_stack: Vec<u16>,
}
@@ -17,17 +17,7 @@ pub struct StackFrame {
pub const RESET_CODE: u16 = 0xfff0;
impl ProgramState {
pub async fn new(file_path: PathBuf) -> Self {
let symbol_file = SymbolFile::load(&file_path).await.ok();
let name = symbol_file
.as_ref()
.map(|f| f.name().to_string())
.or_else(|| {
file_path
.file_stem()
.map(|s| s.to_string_lossy().into_owned())
})
.unwrap_or_else(|| "game".to_string());
pub async fn new(info: Arc<GameInfo>) -> Self {
let mut call_stacks = HashMap::new();
call_stacks.insert(
RESET_CODE,
@@ -36,19 +26,18 @@ impl ProgramState {
}],
);
Self {
name,
symbol_file,
info,
call_stacks,
context_stack: vec![RESET_CODE],
}
}
pub fn name(&self) -> &str {
&self.name
self.info.name()
}
pub fn symbol_file(&self) -> Option<&SymbolFile> {
self.symbol_file.as_ref()
pub fn library_info(&self) -> &LibraryInfo {
self.info.library_info()
}
pub fn current_stack(&self) -> Option<(u16, &[StackFrame])> {
-67
View File
@@ -1,67 +0,0 @@
use std::{path::Path, sync::Arc};
use anyhow::Result;
use fxprof_processed_profile::{LibraryInfo, Symbol, SymbolTable};
use wholesym::{SymbolManager, samply_symbols::demangle_any};
pub struct SymbolFile {
library_info: LibraryInfo,
}
impl SymbolFile {
pub async fn load(file_path: &Path) -> Result<Self> {
let normalized = normpath::PathExt::normalize(file_path)?;
let library_info =
SymbolManager::library_info_for_binary_at_path(normalized.as_path(), None).await?;
let symbol_manager = SymbolManager::with_config(Default::default());
let symbol_map = symbol_manager
.load_symbol_map_for_binary_at_path(normalized.as_path(), None)
.await?;
let name = library_info
.name
.or_else(|| {
normalized
.file_name()
.map(|n| n.to_string_lossy().into_owned())
})
.unwrap_or("game".to_string());
let debug_name = library_info.debug_name.unwrap_or_else(|| name.clone());
let path = library_info
.path
.unwrap_or_else(|| normalized.into_os_string().to_string_lossy().into_owned());
let debug_path = library_info.debug_path.unwrap_or_else(|| path.clone());
let debug_id = library_info.debug_id.unwrap_or_default();
let code_id = library_info.code_id.map(|id| id.to_string());
let arch = library_info.arch;
let symbols = symbol_map
.iter_symbols()
.map(|(address, name)| Symbol {
address: address + 0x07000000,
size: None,
name: demangle_any(&name),
})
.collect();
Ok(Self {
library_info: LibraryInfo {
name,
debug_name,
path,
debug_path,
debug_id,
code_id,
arch,
symbol_table: Some(Arc::new(SymbolTable::new(symbols))),
},
})
}
pub fn name(&self) -> &str {
&self.library_info.name
}
pub fn library_info(&self) -> &LibraryInfo {
&self.library_info
}
}