Skip to content

Commit

Permalink
Support Linkle's DWARF implementation for target_env = "devkita64" (#361
Browse files Browse the repository at this point in the history
)

* Disable libbacktrace on DevkitA64

* Force noop symbolizer on DevkitA64 (for now)

* Add support for linkle's DWARF format to gimli symbolizer

* fmt

* Address review

* Subtract bias from len, revert back to wrapping_add

* Use Vec::with_capacity in mmap_fake

* fmt
  • Loading branch information
leo60228 authored Jul 20, 2020
1 parent 5965cf5 commit 5930de7
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 6 deletions.
48 changes: 42 additions & 6 deletions src/symbolize/gimli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,19 @@ mod mystd {
#[cfg(not(backtrace_in_libstd))]
extern crate std as mystd;

#[cfg(windows)]
#[path = "gimli/mmap_windows.rs"]
mod mmap;
#[cfg(unix)]
#[path = "gimli/mmap_unix.rs"]
mod mmap;
cfg_if::cfg_if! {
if #[cfg(windows)] {
#[path = "gimli/mmap_windows.rs"]
mod mmap;
} else if #[cfg(target_env = "devkita64")] {
#[path = "gimli/mmap_fake.rs"]
mod mmap;
} else {
#[path = "gimli/mmap_unix.rs"]
mod mmap;
}
}

mod stash;

const MAPPINGS_CACHE_SIZE: usize = 4;
Expand Down Expand Up @@ -386,6 +393,35 @@ cfg_if::cfg_if! {
});
0
}
} else if #[cfg(target_env = "devkita64")] {
// DevkitA64 doesn't natively support debug info, but the build system will place debug
// info at the path `romfs:/debug_info.elf`.
mod elf;
use self::elf::Object;

fn native_libraries() -> Vec<Library> {
extern "C" {
static __start__: u8;
}

let bias = unsafe { &__start__ } as *const u8 as usize;

let mut ret = Vec::new();
let mut segments = Vec::new();
segments.push(LibrarySegment {
stated_virtual_memory_address: 0,
len: usize::max_value() - bias,
});

let path = "romfs:/debug_info.elf";
ret.push(Library {
name: path.into(),
segments,
bias,
});

ret
}
} else {
// Everything else should use ELF, but doesn't know how to load native
// libraries.
Expand Down
25 changes: 25 additions & 0 deletions src/symbolize/gimli/mmap_fake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use super::{mystd::io::Read, File};
use alloc::vec::Vec;
use core::ops::Deref;

pub struct Mmap {
vec: Vec<u8>,
}

impl Mmap {
pub unsafe fn map(mut file: &File, len: usize) -> Option<Mmap> {
let mut mmap = Mmap {
vec: Vec::with_capacity(len),
};
file.read_to_end(&mut mmap.vec).ok()?;
Some(mmap)
}
}

impl Deref for Mmap {
type Target = [u8];

fn deref(&self) -> &[u8] {
&self.vec[..]
}
}

0 comments on commit 5930de7

Please sign in to comment.