Added: Support for Little Endian DWARF, Inline Arrays & Additional MetroWerks Extensions (#14)
* Added: Minimal Required Changes to Dump Sonic Heroes (PS2) * Added: Switch for Little Endian DWARF Dump * Added: Support for Array Ordering * Added: Big/Little Endian Variants of u32_from_bytes * Changed: Detect bitness from .elf header. * Changed: Use Proper MetroWerks Names * Changed: Use Endianness from File API * Refactor DWARF endian handling & some fixes * Undo accidental formatting changes --------- Co-authored-by: Luke Street <luke@street.dev>
This commit is contained in:
parent
0cfc5df20b
commit
d43b95a0e4
|
@ -154,14 +154,14 @@ where
|
|||
}
|
||||
|
||||
let mut reader = Cursor::new(&*data);
|
||||
let tags = read_debug_section(&mut reader)?;
|
||||
let info = read_debug_section(&mut reader, obj_file.endianness().into())?;
|
||||
|
||||
for (&addr, tag) in &tags {
|
||||
for (&addr, tag) in &info.tags {
|
||||
log::debug!("{}: {:?}", addr, tag);
|
||||
}
|
||||
|
||||
let mut units = Vec::<String>::new();
|
||||
if let Some((_, mut tag)) = tags.first_key_value() {
|
||||
if let Some((_, mut tag)) = info.tags.first_key_value() {
|
||||
loop {
|
||||
match tag.kind {
|
||||
TagKind::CompileUnit => {
|
||||
|
@ -175,10 +175,10 @@ where
|
|||
}
|
||||
writeln!(w, "\n// Compile unit: {}", unit)?;
|
||||
|
||||
let children = tag.children(&tags);
|
||||
let children = tag.children(&info.tags);
|
||||
let mut typedefs = BTreeMap::<u32, Vec<u32>>::new();
|
||||
for child in children {
|
||||
let tag_type = match process_root_tag(&tags, child) {
|
||||
let tag_type = match process_root_tag(&info, child) {
|
||||
Ok(tag_type) => tag_type,
|
||||
Err(e) => {
|
||||
log::error!(
|
||||
|
@ -198,7 +198,7 @@ where
|
|||
if should_skip_tag(&tag_type) {
|
||||
continue;
|
||||
}
|
||||
match tag_type_string(&tags, &typedefs, &tag_type) {
|
||||
match tag_type_string(&info, &typedefs, &tag_type) {
|
||||
Ok(s) => writeln!(w, "{}", s)?,
|
||||
Err(e) => {
|
||||
log::error!(
|
||||
|
@ -238,7 +238,7 @@ where
|
|||
break;
|
||||
}
|
||||
}
|
||||
if let Some(next) = tag.next_sibling(&tags) {
|
||||
if let Some(next) = tag.next_sibling(&info.tags) {
|
||||
tag = next;
|
||||
} else {
|
||||
break;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -11,6 +11,15 @@ pub enum Endian {
|
|||
Little,
|
||||
}
|
||||
|
||||
impl From<object::Endianness> for Endian {
|
||||
fn from(value: object::Endianness) -> Self {
|
||||
match value {
|
||||
object::Endianness::Big => Endian::Big,
|
||||
object::Endianness::Little => Endian::Little,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub const DYNAMIC_SIZE: usize = 0;
|
||||
|
||||
pub const fn struct_size<const N: usize>(fields: [usize; N]) -> usize {
|
||||
|
@ -52,9 +61,23 @@ pub trait FromReader: Sized {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait FromBytes<const N: usize>: Sized {
|
||||
fn from_bytes(bytes: [u8; N], e: Endian) -> Self;
|
||||
}
|
||||
|
||||
macro_rules! impl_from_reader {
|
||||
($($t:ty),*) => {
|
||||
$(
|
||||
impl FromBytes<{ <$t>::STATIC_SIZE }> for $t {
|
||||
#[inline]
|
||||
fn from_bytes(bytes: [u8; Self::STATIC_SIZE], e: Endian) -> Self {
|
||||
match e {
|
||||
Endian::Big => Self::from_be_bytes(bytes),
|
||||
Endian::Little => Self::from_le_bytes(bytes),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromReader for $t {
|
||||
const STATIC_SIZE: usize = std::mem::size_of::<Self>();
|
||||
|
||||
|
@ -65,10 +88,7 @@ macro_rules! impl_from_reader {
|
|||
where R: Read + Seek + ?Sized {
|
||||
let mut buf = [0u8; Self::STATIC_SIZE];
|
||||
reader.read_exact(&mut buf)?;
|
||||
Ok(match e {
|
||||
Endian::Big => Self::from_be_bytes(buf),
|
||||
Endian::Little => Self::from_le_bytes(buf),
|
||||
})
|
||||
Ok(Self::from_bytes(buf, e))
|
||||
}
|
||||
}
|
||||
)*
|
||||
|
|
Loading…
Reference in New Issue