Add addr2line usage to attempt to get source-loc information
This commit is contained in:
parent
8d0dc93930
commit
ceaa8acac6
|
@ -18,3 +18,4 @@ smallvec = "1.7"
|
||||||
rayon = "1.5"
|
rayon = "1.5"
|
||||||
lazy_static = "1.4"
|
lazy_static = "1.4"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
|
addr2line = "0.19"
|
||||||
|
|
|
@ -7,6 +7,7 @@ use crate::errors::FrontendError;
|
||||||
use crate::ir::*;
|
use crate::ir::*;
|
||||||
use crate::op_traits::{op_inputs, op_outputs};
|
use crate::op_traits::{op_inputs, op_outputs};
|
||||||
use crate::ops::Operator;
|
use crate::ops::Operator;
|
||||||
|
use addr2line::gimli;
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use fxhash::{FxHashMap, FxHashSet};
|
use fxhash::{FxHashMap, FxHashSet};
|
||||||
use log::trace;
|
use log::trace;
|
||||||
|
@ -19,10 +20,13 @@ pub fn wasm_to_ir(bytes: &[u8]) -> Result<Module<'_>> {
|
||||||
let mut module = Module::with_orig_bytes(bytes);
|
let mut module = Module::with_orig_bytes(bytes);
|
||||||
let parser = Parser::new(0);
|
let parser = Parser::new(0);
|
||||||
let mut next_func = 0;
|
let mut next_func = 0;
|
||||||
|
let mut dwarf = gimli::Dwarf::default();
|
||||||
for payload in parser.parse_all(bytes) {
|
for payload in parser.parse_all(bytes) {
|
||||||
let payload = payload?;
|
let payload = payload?;
|
||||||
handle_payload(&mut module, payload, &mut next_func)?;
|
handle_payload(&mut module, payload, &mut next_func, &mut dwarf)?;
|
||||||
}
|
}
|
||||||
|
let debug_map = DebugMap::from_dwarf(dwarf, &mut module.debug);
|
||||||
|
module.debug_map = debug_map;
|
||||||
|
|
||||||
Ok(module)
|
Ok(module)
|
||||||
}
|
}
|
||||||
|
@ -57,6 +61,7 @@ fn handle_payload<'a>(
|
||||||
module: &mut Module<'a>,
|
module: &mut Module<'a>,
|
||||||
payload: Payload<'a>,
|
payload: Payload<'a>,
|
||||||
next_func: &mut usize,
|
next_func: &mut usize,
|
||||||
|
dwarf: &mut gimli::Dwarf<gimli::EndianSlice<'a, gimli::LittleEndian>>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
trace!("Wasm parser item: {:?}", payload);
|
trace!("Wasm parser item: {:?}", payload);
|
||||||
match payload {
|
match payload {
|
||||||
|
@ -213,6 +218,38 @@ fn handle_payload<'a>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Payload::CustomSection(reader) if reader.name() == ".debug_info" => {
|
||||||
|
dwarf.debug_info = gimli::DebugInfo::new(reader.data(), gimli::LittleEndian);
|
||||||
|
}
|
||||||
|
Payload::CustomSection(reader) if reader.name() == ".debug_abbrev" => {
|
||||||
|
dwarf.debug_abbrev = gimli::DebugAbbrev::new(reader.data(), gimli::LittleEndian);
|
||||||
|
}
|
||||||
|
Payload::CustomSection(reader) if reader.name() == ".debug_addr" => {
|
||||||
|
dwarf.debug_addr =
|
||||||
|
gimli::DebugAddr::from(gimli::EndianSlice::new(reader.data(), gimli::LittleEndian));
|
||||||
|
}
|
||||||
|
Payload::CustomSection(reader) if reader.name() == ".debug_aranges" => {
|
||||||
|
dwarf.debug_aranges = gimli::DebugAranges::new(reader.data(), gimli::LittleEndian);
|
||||||
|
}
|
||||||
|
Payload::CustomSection(reader) if reader.name() == ".debug_line" => {
|
||||||
|
dwarf.debug_line = gimli::DebugLine::new(reader.data(), gimli::LittleEndian);
|
||||||
|
}
|
||||||
|
Payload::CustomSection(reader) if reader.name() == ".debug_line_str" => {
|
||||||
|
dwarf.debug_line_str = gimli::DebugLineStr::new(reader.data(), gimli::LittleEndian);
|
||||||
|
}
|
||||||
|
Payload::CustomSection(reader) if reader.name() == ".debug_str" => {
|
||||||
|
dwarf.debug_str = gimli::DebugStr::new(reader.data(), gimli::LittleEndian);
|
||||||
|
}
|
||||||
|
Payload::CustomSection(reader) if reader.name() == ".debug_str_offsets" => {
|
||||||
|
dwarf.debug_str_offsets = gimli::DebugStrOffsets::from(gimli::EndianSlice::new(
|
||||||
|
reader.data(),
|
||||||
|
gimli::LittleEndian,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Payload::CustomSection(reader) if reader.name() == ".debug_types" => {
|
||||||
|
dwarf.debug_types = gimli::DebugTypes::new(reader.data(), gimli::LittleEndian);
|
||||||
|
}
|
||||||
|
Payload::CustomSection(_) => {}
|
||||||
Payload::CodeSectionStart { .. } => {}
|
Payload::CodeSectionStart { .. } => {}
|
||||||
Payload::Version { .. } => {}
|
Payload::Version { .. } => {}
|
||||||
Payload::ElementSection(reader) => {
|
Payload::ElementSection(reader) => {
|
||||||
|
|
|
@ -69,3 +69,5 @@ mod value;
|
||||||
pub use value::*;
|
pub use value::*;
|
||||||
mod display;
|
mod display;
|
||||||
pub use display::*;
|
pub use display::*;
|
||||||
|
mod debug;
|
||||||
|
pub use debug::*;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use super::{Func, FuncDecl, Global, Memory, ModuleDisplay, Signature, Table, Type};
|
use super::{Func, FuncDecl, Global, Memory, ModuleDisplay, Signature, Table, Type};
|
||||||
use crate::entity::{EntityRef, EntityVec};
|
use crate::entity::{EntityRef, EntityVec};
|
||||||
use crate::ir::FunctionBody;
|
use crate::ir::{Debug, DebugMap, FunctionBody};
|
||||||
use crate::{backend, frontend};
|
use crate::{backend, frontend};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
|
@ -15,6 +15,8 @@ pub struct Module<'a> {
|
||||||
pub exports: Vec<Export>,
|
pub exports: Vec<Export>,
|
||||||
pub memories: EntityVec<Memory, MemoryData>,
|
pub memories: EntityVec<Memory, MemoryData>,
|
||||||
pub start_func: Option<Func>,
|
pub start_func: Option<Func>,
|
||||||
|
pub debug: Debug,
|
||||||
|
pub debug_map: DebugMap,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
|
@ -137,6 +139,8 @@ impl<'a> Module<'a> {
|
||||||
exports: vec![],
|
exports: vec![],
|
||||||
memories: EntityVec::default(),
|
memories: EntityVec::default(),
|
||||||
start_func: None,
|
start_func: None,
|
||||||
|
debug: Debug::default(),
|
||||||
|
debug_map: DebugMap::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue