Skip to content

Commit

Permalink
Merge branch '11-cant-dissasemble-macos-executables-bad-cpu-type-in-e…
Browse files Browse the repository at this point in the history
…xecutable'.
  • Loading branch information
WINSDK committed Apr 21, 2024
2 parents 582ca54 + fb600cb commit 4f16809
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 23 deletions.
3 changes: 2 additions & 1 deletion binformat/src/macho.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ fn parse_dynamic_table<'data>(
) -> Result<(), object::Error> {
log::complex!(
w "[macho::parse_dynamic_table] ",
y "TODO",
y "Missing an implementation",
w ".",
);
Ok(())
}
Expand Down
Binary file not shown.
Binary file added debugvault/bin/dsymutil_x86_64
Binary file not shown.
2 changes: 2 additions & 0 deletions debugvault/src/dwarf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ impl Dwarf {
Ok(Dwarf { file_attrs })
}

#[allow(dead_code)]
pub fn load(path: &Path) -> Result<Self> {
let file = std::fs::File::open(path)?;
let mmap = unsafe { memmap2::Mmap::map(&file)? };
let obj = object::File::parse(&*mmap)?;
Self::parse(&obj)
}

#[allow(dead_code)]
pub fn merge(&mut self, other: Self) {
self.file_attrs.extend(other.file_attrs);
}
Expand Down
65 changes: 44 additions & 21 deletions debugvault/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use processor_shared::{AddressMap, Addressed};
use radix_trie::{Trie, TrieCommon};
use std::path::Path;
use std::sync::Arc;
use std::{fmt, process::Command};
use std::fmt;
use tokenizing::Token;

mod common;
Expand Down Expand Up @@ -131,22 +131,37 @@ pub struct Index {
impl Index {
pub fn parse<'data>(
obj: &object::File<'data>,
#[allow(unused_variables)]
path: &Path,
mut syms: AddressMap<RawSymbol<'data>>,
) -> Result<Self, Error> {
let mut this = Self::default();

let dwarf = match obj {
object::File::MachO32(_) => macho_dwarf(obj, path)?,
object::File::MachO64(_) => macho_dwarf(obj, path)?,
_ => dwarf::Dwarf::parse(obj)?,
#[cfg(target_os = "macos")]
object::File::MachO32(_) | object::File::MachO64(_) => macho_dwarf(obj, path),
_ => Dwarf::parse(obj),
};

this.file_attrs.extend(dwarf.file_attrs);
match dwarf {
Ok(dwarf) => this.file_attrs.extend(dwarf.file_attrs),
Err(err) => log::complex!(
w "[dwarf::parse] ",
y format!("Failed to parse dwarf: {err:?}"),
w ".",
)
};

let mut pdb = None;
if let Some(parsed_pdb) = pdb::PDB::parse(obj) {
pdb = Some(parsed_pdb?);
match parsed_pdb {
Ok(parsed_pdb) => pdb = Some(parsed_pdb),
Err(err) => log::complex!(
w "[pdb::parse] ",
y format!("Failed to parse pdb: {err}"),
w ".",
)
};
}

// NOTE: This is a little scuffed. We have to take a `ref mut` here
Expand Down Expand Up @@ -295,6 +310,7 @@ fn sort_by_shortest_match(input: &[&ArcStr], prefix: &str) -> Vec<String> {
matches
}

#[cfg(target_os = "macos")]
pub fn macho_dwarf(obj: &object::File, path: &Path) -> Result<Dwarf, dwarf::Error> {
let mut dwarf = Dwarf::parse(obj)?;

Expand All @@ -310,21 +326,28 @@ pub fn macho_dwarf(obj: &object::File, path: &Path) -> Result<Dwarf, dwarf::Erro
.join(path.file_name().unwrap());

if !opt_dsym.is_file() {
let dsymutil_path = Path::new(env!("CARGO_MANIFEST_DIR")).join("bin/dsymutil");
assert!(dsymutil_path.exists(), "dsymutil somehow missing");

log::PROGRESS.set("Running dsymutil.", 1);
let exit_status =
Command::new(dsymutil_path).arg("--linker=parallel").arg(path).spawn()?.wait()?;
log::PROGRESS.step();

if !exit_status.success() {
log::complex!(
w "[macho::dwarf] ",
y "Generating dSym failed with exit code ",
g exit_status.code().unwrap_or(1).to_string(),
y "."
);
#[cfg(target_arch = "x86_64")]
let dsymutil_path = Path::new(env!("CARGO_MANIFEST_DIR")).join("bin/dsymutil_x86_64");
#[cfg(target_arch = "aarch64")]
let dsymutil_path = Path::new(env!("CARGO_MANIFEST_DIR")).join("bin/dsymutil_aarch64");

if dsymutil_path.exists() {
log::PROGRESS.set("Running dsymutil.", 1);
let exit_status = std::process::Command::new(dsymutil_path)
.arg("--linker=parallel")
.arg(path)
.spawn()?
.wait()?;
log::PROGRESS.step();

if !exit_status.success() {
log::complex!(
w "[macho::dwarf] ",
y "Generating dSym failed with exit code ",
g exit_status.code().unwrap_or(1).to_string(),
y "."
);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion gui/src/widgets/text_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl TextEditState {
ctx.data_mut(|d| d.insert_persisted(id, self));
}

/// The the currently selected range of characters.
/// The currently selected range of characters.
pub fn ccursor_range(&self) -> Option<CCursorRange> {
self.ccursor_range
.or_else(|| self.cursor_range.map(|cursor_range| cursor_range.as_ccursor_range()))
Expand Down

0 comments on commit 4f16809

Please sign in to comment.