Add command line flag, make debug crate optional, clean up API

This commit is contained in:
Mark McCaskey 2020-02-14 12:34:25 -08:00
parent e34e0bb897
commit 923e4ac83a
8 changed files with 52 additions and 54 deletions

1
Cargo.lock generated
View File

@ -1949,7 +1949,6 @@ dependencies = [
"bincode",
"blake3",
"cc",
"cranelift-entity",
"digest",
"errno",
"hex",

View File

@ -79,7 +79,7 @@ serde = { version = "1", features = ["derive"] } # used by the plugin example
typetag = "0.1" # used by the plugin example
[features]
default = ["fast-tests", "wasi", "backend-cranelift", "wabt"]
default = ["fast-tests", "wasi", "backend-cranelift", "wabt", "wasmer-runtime-core/generate-debug-information"]
"loader-kernel" = ["wasmer-kernel-loader"]
debug = ["fern", "log/max_level_debug", "log/release_max_level_debug"]
trace = ["fern", "log/max_level_trace", "log/release_max_level_trace"]

View File

@ -11,7 +11,6 @@ use crate::{
use byteorder::{ByteOrder, LittleEndian};
use cranelift_codegen::{
binemit::{Stackmap, StackmapSink},
entity::PrimaryMap,
ir, isa, Context, ValueLabelsRanges,
};
use rayon::prelude::*;
@ -199,10 +198,10 @@ impl FuncResolverBuilder {
use wasm_debug::types::CompiledFunctionData;
let mut debug_metadata = if generate_debug_info {
Some(wasmer_runtime_core::codegen::DebugMetadata {
func_info: PrimaryMap::new(),
inst_info: PrimaryMap::new(),
func_info: Map::new(),
inst_info: Map::new(),
pointers: vec![],
stack_slot_offsets: PrimaryMap::new(),
stack_slot_offsets: Map::new(),
})
} else {
None

View File

@ -20,10 +20,7 @@ libc = "0.2.60"
hex = "0.4"
smallvec = "0.6"
bincode = "1.1"
# todo: review
cranelift-entity = "0.52"
# todo, make optional, etc
wasm-debug = { version = "0.1.0", path = "../../../Dev/wasm-debug" }
wasm-debug = { optional = true, version = "0.1.0", path = "../../../Dev/wasm-debug" }
target-lexicon = "0.9"
[dependencies.indexmap]
@ -57,3 +54,5 @@ cc = "1.0"
[features]
managed = []
deterministic-execution = ["wasmparser/deterministic"]
# generate debug information from Wasm DWARF for use with the GDB JIT interface
generate-debug-information = ["wasm-debug"]

View File

@ -18,6 +18,7 @@ use std::fmt;
use std::fmt::Debug;
use std::marker::PhantomData;
use std::sync::{Arc, RwLock};
use wasm_debug::types::{CompiledFunctionData, ValueLabelsRangesInner};
use wasmparser::{self, WasmDecoder};
use wasmparser::{Operator, Type as WpType};
@ -127,15 +128,14 @@ pub trait ModuleCodeGenerator<FCG: FunctionCodeGenerator<E>, RM: RunnableModule,
unsafe fn from_cache(cache: Artifact, _: Token) -> Result<ModuleInner, CacheError>;
}
use cranelift_entity::PrimaryMap;
/// missing documentation!
pub struct DebugMetadata {
///f unc info
pub func_info: PrimaryMap<FuncIndex, wasm_debug::types::CompiledFunctionData>,
/// inst_info
pub inst_info: PrimaryMap<FuncIndex, wasm_debug::types::ValueLabelsRangesInner>,
/// stack slot offsets!
pub stack_slot_offsets: PrimaryMap<FuncIndex, Vec<Option<i32>>>,
/// [`CompiledFunctionData`] in [`FuncIndex`] order
pub func_info: Map<FuncIndex, CompiledFunctionData>,
/// [`ValueLabelsRangesInner`] in [`FuncIndex`] order
pub inst_info: Map<FuncIndex, ValueLabelsRangesInner>,
/// Stack slot offsets in [`FuncIndex`] order
pub stack_slot_offsets: Map<FuncIndex, Vec<Option<i32>>>,
/// function pointers and their lengths
pub pointers: Vec<(*const u8, usize)>,
}
@ -280,34 +280,36 @@ impl<
};
if compiler_config.generate_debug_info {
let debug_metadata = debug_metadata.expect("debug metadata");
let debug_info = wasm_debug::read_debuginfo(wasm);
let extra_info = wasm_debug::types::ModuleVmctxInfo::new(
14 * 8,
debug_metadata.stack_slot_offsets.values(),
);
// lazy type hack (TODO:)
let compiled_fn_map =
wasm_debug::types::create_module_address_map(debug_metadata.func_info.values());
let range_map =
wasm_debug::types::build_values_ranges(debug_metadata.inst_info.values());
let raw_func_slice = debug_metadata.pointers;
if let Some(debug_metadata) = debug_metadata {
let debug_info = wasm_debug::read_debuginfo(wasm);
let extra_info = wasm_debug::types::ModuleVmctxInfo::new(
14 * 8,
debug_metadata.stack_slot_offsets.values(),
);
let compiled_fn_map =
wasm_debug::types::create_module_address_map(debug_metadata.func_info.values());
let range_map =
wasm_debug::types::build_values_ranges(debug_metadata.inst_info.values());
let raw_func_slice = debug_metadata.pointers;
let debug_image = wasm_debug::emit_debugsections_image(
X86_64_OSX,
std::mem::size_of::<usize>() as u8,
&debug_info,
&extra_info,
&compiled_fn_map,
&range_map,
&raw_func_slice,
)
.expect("make debug image");
let debug_image = wasm_debug::emit_debugsections_image(
X86_64_OSX,
std::mem::size_of::<usize>() as u8,
&debug_info,
&extra_info,
&compiled_fn_map,
&range_map,
&raw_func_slice,
)
.expect("make debug image");
crate::jit_debug::register_new_jit_code_entry(
&debug_image,
crate::jit_debug::JITAction::JIT_REGISTER_FN,
);
crate::jit_debug::register_new_jit_code_entry(
&debug_image,
crate::jit_debug::JITAction::JIT_REGISTER_FN,
);
} else {
eprintln!("Failed to generate debug information!");
}
}
Ok(ModuleInner {
cache_gen,

View File

@ -78,6 +78,11 @@ where
pub fn into_vec(self) -> Vec<V> {
self.elems
}
/// Iterate over the values of the map in order
pub fn values(&self) -> impl Iterator<Item = &V> {
self.elems.iter()
}
}
impl<K, V> Map<K, V>

View File

@ -502,17 +502,6 @@ define_map_index![
| imported: ImportedFuncIndex, ImportedMemoryIndex, ImportedTableIndex, ImportedGlobalIndex,
];
// lol
impl cranelift_entity::EntityRef for FuncIndex {
fn index(self) -> usize {
self.0 as usize
}
fn new(x: usize) -> Self {
Self(x as u32)
}
}
#[rustfmt::skip]
macro_rules! define_local_or_import {
($ty:ident, $local_ty:ident, $imported_ty:ident, $imports:ident) => {

View File

@ -567,6 +567,10 @@ impl LLVMCallbacks for LLVMCLIOptions {
/// Execute a wasm/wat file
fn execute_wasm(options: &Run) -> Result<(), String> {
if options.generate_debug_info && options.backend != Backend::Cranelift {
return Err("Generating debug information is currently only available with the `cranelift` backend.".to_owned());
}
let disable_cache = options.disable_cache;
let mapped_dirs = get_mapped_dirs(&options.mapped_dirs[..])?;
@ -1021,6 +1025,7 @@ fn get_backend(backend: Backend, path: &PathBuf) -> Backend {
fn run(options: &mut Run) {
options.backend = get_backend(options.backend, &options.path);
#[cfg(any(feature = "debug", feature = "trace"))]
{
if options.debug {