Skip to content

Support Linkle's DWARF implementation for target_env = "devkita64" #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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[..]
}
}