Skip to content

Commit 5930de7

Browse files
authored
Support Linkle's DWARF implementation for target_env = "devkita64" (#361)
* 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
1 parent 5965cf5 commit 5930de7

File tree

2 files changed

+67
-6
lines changed

2 files changed

+67
-6
lines changed

src/symbolize/gimli.rs

+42-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,19 @@ mod mystd {
2828
#[cfg(not(backtrace_in_libstd))]
2929
extern crate std as mystd;
3030

31-
#[cfg(windows)]
32-
#[path = "gimli/mmap_windows.rs"]
33-
mod mmap;
34-
#[cfg(unix)]
35-
#[path = "gimli/mmap_unix.rs"]
36-
mod mmap;
31+
cfg_if::cfg_if! {
32+
if #[cfg(windows)] {
33+
#[path = "gimli/mmap_windows.rs"]
34+
mod mmap;
35+
} else if #[cfg(target_env = "devkita64")] {
36+
#[path = "gimli/mmap_fake.rs"]
37+
mod mmap;
38+
} else {
39+
#[path = "gimli/mmap_unix.rs"]
40+
mod mmap;
41+
}
42+
}
43+
3744
mod stash;
3845

3946
const MAPPINGS_CACHE_SIZE: usize = 4;
@@ -386,6 +393,35 @@ cfg_if::cfg_if! {
386393
});
387394
0
388395
}
396+
} else if #[cfg(target_env = "devkita64")] {
397+
// DevkitA64 doesn't natively support debug info, but the build system will place debug
398+
// info at the path `romfs:/debug_info.elf`.
399+
mod elf;
400+
use self::elf::Object;
401+
402+
fn native_libraries() -> Vec<Library> {
403+
extern "C" {
404+
static __start__: u8;
405+
}
406+
407+
let bias = unsafe { &__start__ } as *const u8 as usize;
408+
409+
let mut ret = Vec::new();
410+
let mut segments = Vec::new();
411+
segments.push(LibrarySegment {
412+
stated_virtual_memory_address: 0,
413+
len: usize::max_value() - bias,
414+
});
415+
416+
let path = "romfs:/debug_info.elf";
417+
ret.push(Library {
418+
name: path.into(),
419+
segments,
420+
bias,
421+
});
422+
423+
ret
424+
}
389425
} else {
390426
// Everything else should use ELF, but doesn't know how to load native
391427
// libraries.

src/symbolize/gimli/mmap_fake.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use super::{mystd::io::Read, File};
2+
use alloc::vec::Vec;
3+
use core::ops::Deref;
4+
5+
pub struct Mmap {
6+
vec: Vec<u8>,
7+
}
8+
9+
impl Mmap {
10+
pub unsafe fn map(mut file: &File, len: usize) -> Option<Mmap> {
11+
let mut mmap = Mmap {
12+
vec: Vec::with_capacity(len),
13+
};
14+
file.read_to_end(&mut mmap.vec).ok()?;
15+
Some(mmap)
16+
}
17+
}
18+
19+
impl Deref for Mmap {
20+
type Target = [u8];
21+
22+
fn deref(&self) -> &[u8] {
23+
&self.vec[..]
24+
}
25+
}

0 commit comments

Comments
 (0)