mirror of
https://github.com/Noratrieb/elven-forest.git
synced 2026-01-14 10:45:03 +01:00
size works
This commit is contained in:
parent
a5058bef51
commit
e998012a18
2 changed files with 28 additions and 8 deletions
|
|
@ -39,6 +39,10 @@ fn main() -> anyhow::Result<()> {
|
||||||
let opts = Opts::parse();
|
let opts = Opts::parse();
|
||||||
|
|
||||||
for obj in &opts.files {
|
for obj in &opts.files {
|
||||||
|
if opts.files.len() > 1 {
|
||||||
|
println!("{}", obj.display());
|
||||||
|
}
|
||||||
|
|
||||||
print_file(&opts, obj).with_context(|| format!("Failed to print {}", obj.display()))?;
|
print_file(&opts, obj).with_context(|| format!("Failed to print {}", obj.display()))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -103,8 +107,6 @@ struct DynTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_file(opts: &Opts, path: &Path) -> anyhow::Result<()> {
|
fn print_file(opts: &Opts, path: &Path) -> anyhow::Result<()> {
|
||||||
println!("{}", path.display());
|
|
||||||
|
|
||||||
let file = File::open(path)?;
|
let file = File::open(path)?;
|
||||||
let mmap = unsafe { Mmap::map(&file) }?;
|
let mmap = unsafe { Mmap::map(&file) }?;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ pub fn analyze_text_bloat(elf: ElfReader<'_>) -> Result<()> {
|
||||||
let text = elf
|
let text = elf
|
||||||
.section_header_by_name(b".text")
|
.section_header_by_name(b".text")
|
||||||
.context(".text not found")?;
|
.context(".text not found")?;
|
||||||
dbg!(text.size);
|
|
||||||
|
|
||||||
let syms = elf.symbols().context("symbols not found")?;
|
let syms = elf.symbols().context("symbols not found")?;
|
||||||
|
|
||||||
|
|
@ -49,24 +48,43 @@ fn symbol_components(sym: &str) -> Result<String> {
|
||||||
|
|
||||||
if demangled.starts_with('<') {
|
if demangled.starts_with('<') {
|
||||||
let qpath = parse_qpath(&demangled).context("invalid qpath")?;
|
let qpath = parse_qpath(&demangled).context("invalid qpath")?;
|
||||||
|
let components = qpath_components(qpath)?;
|
||||||
|
|
||||||
// qpath
|
// qpath
|
||||||
return Ok(demangled);
|
return Ok(components.join(","));
|
||||||
} else {
|
} else {
|
||||||
// normal path
|
// normal path
|
||||||
let components = demangled.split("::").collect::<Vec<_>>();
|
let components = demangled.split("::").collect::<Vec<_>>();
|
||||||
let path = components.join(";");
|
let path = components.join(",");
|
||||||
return Ok(path);
|
return Ok(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
struct QPath<'a> {
|
struct QPath<'a> {
|
||||||
qself: &'a str,
|
qself: &'a str,
|
||||||
trait_: &'a str,
|
trait_: &'a str,
|
||||||
pathy_bit: &'a str,
|
pathy_bit: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn qpath_components(qpath: QPath<'_>) -> Result<Vec<&str>> {
|
||||||
|
if qpath.qself.starts_with('<') {
|
||||||
|
let sub_qpath = parse_qpath(qpath.qself)?;
|
||||||
|
let mut sub_components = qpath_components(sub_qpath)?;
|
||||||
|
sub_components.extend(qpath.pathy_bit.split("::"));
|
||||||
|
Ok(sub_components)
|
||||||
|
} else {
|
||||||
|
Ok(qpath
|
||||||
|
.qself
|
||||||
|
.split("::")
|
||||||
|
.chain(qpath.pathy_bit.split("::"))
|
||||||
|
.collect())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Apparently the symbol `std::os::linux::process::<impl core::convert::From<std::os::linux::process::PidFd> for std::os::fd::owned::OwnedFd>::from` exists in std
|
||||||
|
// I have no clue what to do about that.
|
||||||
|
|
||||||
fn parse_qpath(s: &str) -> Result<QPath<'_>> {
|
fn parse_qpath(s: &str) -> Result<QPath<'_>> {
|
||||||
let mut chars = s.char_indices().skip(1);
|
let mut chars = s.char_indices().skip(1);
|
||||||
let mut angle_brackets = 1u64;
|
let mut angle_brackets = 1u64;
|
||||||
|
|
@ -145,13 +163,13 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn path_debug_helper() {
|
fn path_debug_helper() {
|
||||||
// <<std::path::Components as core::fmt::Debug>::fmt::DebugHelper as core::fmt::Debug>::fmt::hc586615181f69e94
|
// <<std::path::Components as core::fmt::Debug>::fmt::DebugHelper as core::fmt::Debug>::fmt::h4f87ac80fb33df05
|
||||||
let sym = "_ZN106_$LT$$LT$std..path..Iter$u20$as$u20$core..fmt..Debug$GT$..fmt..DebugHelper$u20$as$u20$core..fmt..Debug$GT$3fmt17h4f87ac80fb33df05E";
|
let sym = "_ZN106_$LT$$LT$std..path..Iter$u20$as$u20$core..fmt..Debug$GT$..fmt..DebugHelper$u20$as$u20$core..fmt..Debug$GT$3fmt17h4f87ac80fb33df05E";
|
||||||
let components = symbol_components(sym).unwrap();
|
let components = symbol_components(sym).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
components,
|
components,
|
||||||
"std;path;Iter;fmt;DebugHelper;fmt;hc586615181f69e94"
|
"std,path,Iter,fmt,DebugHelper,fmt,h4f87ac80fb33df05"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue