Expose precise offset information in wasmtime::FrameInfo (#1495)
* Consolidate trap/frame information This commit removes `TrapRegistry` in favor of consolidating this information in the `FRAME_INFO` we already have in the `wasmtime` crate. This allows us to keep information generally in one place and have one canonical location for "map this PC to some original wasm stuff". The intent for this is to next update with enough information to go from a program counter to a position in the original wasm file. * Expose module offset information in `FrameInfo` This commit implements functionality for `FrameInfo`, the wasm stack trace of a `Trap`, to return the module/function offset. This allows knowing the precise wasm location of each stack frame, instead of only the main trap itself. The intention here is to provide more visibility into the wasm source when something traps, so you know precisely where calls were and where traps were, in order to assist in debugging. Eventually we might use this information for mapping back to native source languages as well (given sufficient debug information). This change makes a previously-optional artifact of compilation always computed on the cranelift side of things. This `ModuleAddressMap` is then propagated to the same store of information other frame information is stored within. This also removes the need for passing a `SourceLoc` with wasm traps or to wasm trap creation, since the backtrace's wasm frames will be able to infer their own `SourceLoc` from the relevant program counters.
This commit is contained in:
@@ -16,12 +16,13 @@ use wasmtime_debug::read_debuginfo;
|
||||
use wasmtime_environ::entity::{BoxedSlice, PrimaryMap};
|
||||
use wasmtime_environ::wasm::{DefinedFuncIndex, SignatureIndex};
|
||||
use wasmtime_environ::{
|
||||
CompileError, DataInitializer, DataInitializerLocation, Module, ModuleEnvironment,
|
||||
CompileError, DataInitializer, DataInitializerLocation, Module, ModuleAddressMap,
|
||||
ModuleEnvironment, Traps,
|
||||
};
|
||||
use wasmtime_profiling::ProfilingAgent;
|
||||
use wasmtime_runtime::{
|
||||
GdbJitImageRegistration, InstanceHandle, InstantiationError, RuntimeMemoryCreator,
|
||||
SignatureRegistry, TrapRegistration, VMFunctionBody, VMSharedSignatureIndex, VMTrampoline,
|
||||
SignatureRegistry, VMFunctionBody, VMSharedSignatureIndex, VMTrampoline,
|
||||
};
|
||||
|
||||
/// An error condition while setting up a wasm instance, be it validation,
|
||||
@@ -55,7 +56,8 @@ struct RawCompiledModule<'data> {
|
||||
data_initializers: Box<[DataInitializer<'data>]>,
|
||||
signatures: BoxedSlice<SignatureIndex, VMSharedSignatureIndex>,
|
||||
dbg_jit_registration: Option<GdbJitImageRegistration>,
|
||||
trap_registration: TrapRegistration,
|
||||
traps: Traps,
|
||||
address_transform: ModuleAddressMap,
|
||||
}
|
||||
|
||||
impl<'data> RawCompiledModule<'data> {
|
||||
@@ -119,7 +121,8 @@ impl<'data> RawCompiledModule<'data> {
|
||||
data_initializers: translation.data_initializers.into_boxed_slice(),
|
||||
signatures: signatures.into_boxed_slice(),
|
||||
dbg_jit_registration,
|
||||
trap_registration: compilation.trap_registration,
|
||||
traps: compilation.traps,
|
||||
address_transform: compilation.address_transform,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -132,7 +135,8 @@ pub struct CompiledModule {
|
||||
data_initializers: Box<[OwnedDataInitializer]>,
|
||||
signatures: BoxedSlice<SignatureIndex, VMSharedSignatureIndex>,
|
||||
dbg_jit_registration: Option<Rc<GdbJitImageRegistration>>,
|
||||
trap_registration: TrapRegistration,
|
||||
traps: Traps,
|
||||
address_transform: ModuleAddressMap,
|
||||
}
|
||||
|
||||
impl CompiledModule {
|
||||
@@ -155,7 +159,8 @@ impl CompiledModule {
|
||||
.into_boxed_slice(),
|
||||
raw.signatures.clone(),
|
||||
raw.dbg_jit_registration,
|
||||
raw.trap_registration,
|
||||
raw.traps,
|
||||
raw.address_transform,
|
||||
))
|
||||
}
|
||||
|
||||
@@ -167,7 +172,8 @@ impl CompiledModule {
|
||||
data_initializers: Box<[OwnedDataInitializer]>,
|
||||
signatures: BoxedSlice<SignatureIndex, VMSharedSignatureIndex>,
|
||||
dbg_jit_registration: Option<GdbJitImageRegistration>,
|
||||
trap_registration: TrapRegistration,
|
||||
traps: Traps,
|
||||
address_transform: ModuleAddressMap,
|
||||
) -> Self {
|
||||
Self {
|
||||
module: Arc::new(module),
|
||||
@@ -176,7 +182,8 @@ impl CompiledModule {
|
||||
data_initializers,
|
||||
signatures,
|
||||
dbg_jit_registration: dbg_jit_registration.map(Rc::new),
|
||||
trap_registration,
|
||||
traps,
|
||||
address_transform,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,7 +214,6 @@ impl CompiledModule {
|
||||
let imports = resolve_imports(&self.module, &sig_registry, resolver)?;
|
||||
InstanceHandle::new(
|
||||
Arc::clone(&self.module),
|
||||
self.trap_registration.clone(),
|
||||
self.finished_functions.clone(),
|
||||
self.trampolines.clone(),
|
||||
imports,
|
||||
@@ -239,6 +245,16 @@ impl CompiledModule {
|
||||
pub fn finished_functions(&self) -> &BoxedSlice<DefinedFuncIndex, *mut [VMFunctionBody]> {
|
||||
&self.finished_functions
|
||||
}
|
||||
|
||||
/// Returns the a map for all traps in this module.
|
||||
pub fn traps(&self) -> &Traps {
|
||||
&self.traps
|
||||
}
|
||||
|
||||
/// Returns a map of compiled addresses back to original bytecode offsets.
|
||||
pub fn address_transform(&self) -> &ModuleAddressMap {
|
||||
&self.address_transform
|
||||
}
|
||||
}
|
||||
|
||||
/// Similar to `DataInitializer`, but owns its own copy of the data rather
|
||||
|
||||
Reference in New Issue
Block a user