Generate debug info for LLDB/GDB (#50)
* Transform DWARF sections into native format for wasm2obj and wasmtime. Generate DWARF sections based on WASM DWARF. Ignore some of debug_info/debug_line for dead code. * Fix test
This commit is contained in:
committed by
Dan Gohman
parent
6eb09d9edd
commit
ddbc00752e
@@ -66,3 +66,32 @@ pub enum CompileError {
|
||||
#[fail(display = "Compilation error: {}", _0)]
|
||||
Codegen(CodegenError),
|
||||
}
|
||||
|
||||
/// Single address point transform.
|
||||
#[derive(Debug)]
|
||||
pub struct InstructionAddressTransform {
|
||||
/// Original source location.
|
||||
pub srcloc: ir::SourceLoc,
|
||||
|
||||
/// Generated instructions offset.
|
||||
pub code_offset: usize,
|
||||
|
||||
/// Generated instructions length.
|
||||
pub code_len: usize,
|
||||
}
|
||||
|
||||
/// Function and its instructions transforms.
|
||||
#[derive(Debug)]
|
||||
pub struct FunctionAddressTransform {
|
||||
/// Instructions transforms
|
||||
pub locations: Vec<InstructionAddressTransform>,
|
||||
|
||||
/// Generated function body offset if applicable, otherwise 0.
|
||||
pub body_offset: usize,
|
||||
|
||||
/// Generated function body length.
|
||||
pub body_len: usize,
|
||||
}
|
||||
|
||||
/// Function AddressTransforms collection.
|
||||
pub type AddressTransforms = PrimaryMap<DefinedFuncIndex, FunctionAddressTransform>;
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
//! Support for compiling with Cranelift.
|
||||
|
||||
use crate::compilation::{Compilation, CompileError, Relocation, RelocationTarget, Relocations};
|
||||
use crate::compilation::{
|
||||
AddressTransforms, Compilation, CompileError, FunctionAddressTransform,
|
||||
InstructionAddressTransform, Relocation, RelocationTarget, Relocations,
|
||||
};
|
||||
use crate::func_environ::{
|
||||
get_func_name, get_imported_memory32_grow_name, get_imported_memory32_size_name,
|
||||
get_memory32_grow_name, get_memory32_size_name, FuncEnvironment,
|
||||
@@ -81,15 +84,41 @@ impl RelocSink {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_address_transform(
|
||||
context: &Context,
|
||||
isa: &isa::TargetIsa,
|
||||
) -> Vec<InstructionAddressTransform> {
|
||||
let mut result = Vec::new();
|
||||
|
||||
let func = &context.func;
|
||||
let mut ebbs = func.layout.ebbs().collect::<Vec<_>>();
|
||||
ebbs.sort_by_key(|ebb| func.offsets[*ebb]); // Ensure inst offsets always increase
|
||||
|
||||
let encinfo = isa.encoding_info();
|
||||
for ebb in ebbs {
|
||||
for (offset, inst, size) in func.inst_offsets(ebb, &encinfo) {
|
||||
let srcloc = func.srclocs[inst];
|
||||
result.push(InstructionAddressTransform {
|
||||
srcloc,
|
||||
code_offset: offset as usize,
|
||||
code_len: size as usize,
|
||||
});
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
/// Compile the module using Cranelift, producing a compilation result with
|
||||
/// associated relocations.
|
||||
pub fn compile_module<'data, 'module>(
|
||||
module: &'module Module,
|
||||
function_body_inputs: PrimaryMap<DefinedFuncIndex, &'data [u8]>,
|
||||
isa: &dyn isa::TargetIsa,
|
||||
) -> Result<(Compilation, Relocations), CompileError> {
|
||||
generate_debug_info: bool,
|
||||
) -> Result<(Compilation, Relocations, AddressTransforms), CompileError> {
|
||||
let mut functions = PrimaryMap::with_capacity(function_body_inputs.len());
|
||||
let mut relocations = PrimaryMap::with_capacity(function_body_inputs.len());
|
||||
let mut address_transforms = PrimaryMap::with_capacity(function_body_inputs.len());
|
||||
|
||||
function_body_inputs
|
||||
.into_iter()
|
||||
@@ -116,15 +145,31 @@ pub fn compile_module<'data, 'module>(
|
||||
context
|
||||
.compile_and_emit(isa, &mut code_buf, &mut reloc_sink, &mut trap_sink)
|
||||
.map_err(CompileError::Codegen)?;
|
||||
Ok((code_buf, reloc_sink.func_relocs))
|
||||
|
||||
let address_transform = if generate_debug_info {
|
||||
let body_len = code_buf.len();
|
||||
let at = get_address_transform(&context, isa);
|
||||
Some(FunctionAddressTransform {
|
||||
locations: at,
|
||||
body_offset: 0,
|
||||
body_len,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Ok((code_buf, reloc_sink.func_relocs, address_transform))
|
||||
})
|
||||
.collect::<Result<Vec<_>, CompileError>>()?
|
||||
.into_iter()
|
||||
.for_each(|(function, relocs)| {
|
||||
.for_each(|(function, relocs, address_transform)| {
|
||||
functions.push(function);
|
||||
relocations.push(relocs);
|
||||
if let Some(address_transform) = address_transform {
|
||||
address_transforms.push(address_transform);
|
||||
}
|
||||
});
|
||||
|
||||
// TODO: Reorganize where we create the Vec for the resolved imports.
|
||||
Ok((Compilation::new(functions), relocations))
|
||||
Ok((Compilation::new(functions), relocations, address_transforms))
|
||||
}
|
||||
|
||||
@@ -47,7 +47,8 @@ mod vmoffsets;
|
||||
pub mod cranelift;
|
||||
|
||||
pub use crate::compilation::{
|
||||
Compilation, CompileError, Relocation, RelocationTarget, Relocations,
|
||||
AddressTransforms, Compilation, CompileError, InstructionAddressTransform, Relocation,
|
||||
RelocationTarget, Relocations,
|
||||
};
|
||||
pub use crate::module::{
|
||||
Export, MemoryPlan, MemoryStyle, Module, TableElements, TablePlan, TableStyle,
|
||||
@@ -57,7 +58,7 @@ pub use crate::module_environ::{
|
||||
ModuleTranslation,
|
||||
};
|
||||
pub use crate::tunables::Tunables;
|
||||
pub use crate::vmoffsets::VMOffsets;
|
||||
pub use crate::vmoffsets::{TargetSharedSignatureIndex, VMOffsets};
|
||||
|
||||
/// WebAssembly page sizes are defined to be 64KiB.
|
||||
pub const WASM_PAGE_SIZE: u32 = 0x10000;
|
||||
|
||||
@@ -518,3 +518,19 @@ impl VMOffsets {
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
/// Target specific type for shared signature index.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct TargetSharedSignatureIndex(u32);
|
||||
|
||||
impl TargetSharedSignatureIndex {
|
||||
/// Constructs `TargetSharedSignatureIndex`.
|
||||
pub fn new(value: u32) -> Self {
|
||||
TargetSharedSignatureIndex(value)
|
||||
}
|
||||
|
||||
/// Returns index value.
|
||||
pub fn index(&self) -> u32 {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user