WIP.
This commit is contained in:
parent
b24ca8de43
commit
ebfd4209fe
|
@ -358,18 +358,23 @@ fn handle_payload<'a>(
|
||||||
}
|
}
|
||||||
|
|
||||||
struct DebugLocReader<'a> {
|
struct DebugLocReader<'a> {
|
||||||
|
code_section_offset: u32,
|
||||||
locs: &'a [(u32, u32, SourceLoc)],
|
locs: &'a [(u32, u32, SourceLoc)],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> DebugLocReader<'a> {
|
impl<'a> DebugLocReader<'a> {
|
||||||
fn new(module: &'a Module, offset: usize) -> Self {
|
fn new(module: &'a Module, offset: usize) -> Self {
|
||||||
DebugLocReader {
|
DebugLocReader {
|
||||||
locs: module.debug_map.locs_from_offset(offset),
|
code_section_offset: u32::try_from(offset).unwrap(),
|
||||||
|
locs: &module.debug_map.tuples[..],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_loc(&mut self, offset: usize) -> SourceLoc {
|
fn get_loc(&mut self, offset: usize) -> SourceLoc {
|
||||||
let offset = u32::try_from(offset).unwrap();
|
let offset = u32::try_from(offset)
|
||||||
|
.unwrap()
|
||||||
|
.checked_sub(self.code_section_offset)
|
||||||
|
.unwrap();
|
||||||
while self.locs.len() > 0 {
|
while self.locs.len() > 0 {
|
||||||
let (start, len, loc) = self.locs[0];
|
let (start, len, loc) = self.locs[0];
|
||||||
if offset < start {
|
if offset < start {
|
||||||
|
|
|
@ -5,7 +5,6 @@ use crate::entity::EntityVec;
|
||||||
use addr2line::gimli;
|
use addr2line::gimli;
|
||||||
use std::collections::hash_map::Entry as HashEntry;
|
use std::collections::hash_map::Entry as HashEntry;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::convert::TryFrom;
|
|
||||||
|
|
||||||
declare_entity!(SourceFile, "file");
|
declare_entity!(SourceFile, "file");
|
||||||
declare_entity!(SourceLoc, "loc");
|
declare_entity!(SourceLoc, "loc");
|
||||||
|
@ -49,7 +48,9 @@ impl Debug {
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
pub struct DebugMap {
|
pub struct DebugMap {
|
||||||
tuples: Vec<(u32, u32, SourceLoc)>,
|
/// Each tuple is `(start, len, loc)`. The `start` offset is
|
||||||
|
/// relative to the Wasm code section (*not* the entire file).
|
||||||
|
pub tuples: Vec<(u32, u32, SourceLoc)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DebugMap {
|
impl DebugMap {
|
||||||
|
@ -79,21 +80,4 @@ impl DebugMap {
|
||||||
|
|
||||||
Ok(DebugMap { tuples })
|
Ok(DebugMap { tuples })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn locs_from_offset<'a>(&'a self, offset: usize) -> &'a [(u32, u32, SourceLoc)] {
|
|
||||||
let offset = u32::try_from(offset).unwrap();
|
|
||||||
let start = match self.tuples.binary_search_by(|&(start, len, _)| {
|
|
||||||
if offset < start {
|
|
||||||
std::cmp::Ordering::Greater
|
|
||||||
} else if offset >= (start + len) {
|
|
||||||
std::cmp::Ordering::Less
|
|
||||||
} else {
|
|
||||||
std::cmp::Ordering::Equal
|
|
||||||
}
|
|
||||||
}) {
|
|
||||||
Ok(idx) => idx,
|
|
||||||
Err(first_after) => first_after,
|
|
||||||
};
|
|
||||||
&self.tuples[start..]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue