Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(wasm): support for wasm #166

Merged
merged 20 commits into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cabi/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ pub enum SymbolicErrorCode {
ObjectErrorBadPdbObject = 2105,
ObjectErrorBadPeObject = 2106,
ObjectErrorBadSourceBundle = 2107,
ObjectErrorBadWasmObject = 2108,
DwarfErrorUnknown = 2200,
DwarfErrorInvalidUnitRef = 2201,
DwarfErrorInvalidFileRef = 2202,
Expand Down Expand Up @@ -260,6 +261,7 @@ impl SymbolicErrorCode {
ObjectError::MachO(_) => SymbolicErrorCode::ObjectErrorBadMachOObject,
ObjectError::Pdb(_) => SymbolicErrorCode::ObjectErrorBadPdbObject,
ObjectError::Pe(_) => SymbolicErrorCode::ObjectErrorBadPeObject,
ObjectError::Wasm(_) => SymbolicErrorCode::ObjectErrorBadWasmObject,
ObjectError::Dwarf(ref e) => match e.kind() {
DwarfErrorKind::InvalidUnitRef(_) => {
SymbolicErrorCode::DwarfErrorInvalidUnitRef
Expand Down
12 changes: 12 additions & 0 deletions common/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ pub enum CpuFamily {
Mips64 = 8,
/// ILP32 ABI on 64-bit ARM.
Arm64_32 = 9,
/// Virtual WASM architecture.
Wasm = 10,
}

impl CpuFamily {
Expand All @@ -113,6 +115,7 @@ impl CpuFamily {
pub fn pointer_size(self) -> Option<usize> {
match self {
CpuFamily::Unknown => None,
CpuFamily::Wasm => Some(4),
CpuFamily::Amd64
| CpuFamily::Arm64
| CpuFamily::Ppc64
Expand Down Expand Up @@ -141,6 +144,7 @@ impl CpuFamily {
/// ```
pub fn instruction_alignment(self) -> Option<u64> {
match self {
CpuFamily::Wasm => Some(4),
CpuFamily::Arm32 => Some(2),
CpuFamily::Arm64 | CpuFamily::Arm64_32 => Some(4),
CpuFamily::Ppc32 | CpuFamily::Mips32 | CpuFamily::Mips64 => Some(4),
Expand Down Expand Up @@ -176,6 +180,7 @@ impl CpuFamily {
CpuFamily::Arm32 | CpuFamily::Arm64 | CpuFamily::Arm64_32 => Some("pc"),
CpuFamily::Ppc32 | CpuFamily::Ppc64 => Some("srr0"),
CpuFamily::Mips32 | CpuFamily::Mips64 => Some("pc"),
CpuFamily::Wasm => None,
CpuFamily::Unknown => None,
}
}
Expand Down Expand Up @@ -275,6 +280,7 @@ pub enum Arch {
Arm64_32 = 901,
Arm64_32V8 = 902,
Arm64_32Unknown = 999,
Wasm = 100_001,
}

impl Arch {
Expand Down Expand Up @@ -320,6 +326,7 @@ impl Arch {
901 => Arch::Arm64_32,
902 => Arch::Arm64_32V8,
999 => Arch::Arm64_32Unknown,
100_001 => Arch::Wasm,
_ => Arch::Unknown,
}
}
Expand Down Expand Up @@ -356,6 +363,7 @@ impl Arch {
Arch::Mips => CpuFamily::Mips32,
Arch::Mips64 => CpuFamily::Mips64,
Arch::Arm64_32 | Arch::Arm64_32V8 | Arch::Arm64_32Unknown => CpuFamily::Arm64_32,
Arch::Wasm => CpuFamily::Wasm,
}
}

Expand All @@ -379,6 +387,7 @@ impl Arch {
pub fn name(self) -> &'static str {
match self {
Arch::Unknown => "unknown",
Arch::Wasm => "wasm",
Arch::X86 => "x86",
Arch::X86Unknown => "x86_unknown",
Arch::Amd64 => "x86_64",
Expand Down Expand Up @@ -510,6 +519,9 @@ impl str::FromStr for Arch {
"x86-64" => Arch::Amd64,
"arm-64" => Arch::Arm64,

// wasm extensions
"wasm" => Arch::Wasm,

_ => return Err(UnknownArchError),
})
}
Expand Down
1 change: 1 addition & 0 deletions debuginfo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ serde_json = "1.0.40"
smallvec = "1.2.0"
symbolic-common = { version = "7.4.0", path = "../common" }
zip = "0.5.2"
walrus = "0.13.0"

[dev-dependencies]
insta = "0.15.0"
Expand Down
4 changes: 4 additions & 0 deletions debuginfo/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ pub enum FileFormat {
Pe,
/// Source code bundle ZIP.
SourceBundle,
/// WASM container.
Wasm,
}

impl FileFormat {
Expand All @@ -157,6 +159,7 @@ impl FileFormat {
FileFormat::Pdb => "pdb",
FileFormat::Pe => "pe",
FileFormat::SourceBundle => "sourcebundle",
FileFormat::Wasm => "wasm",
}
}
}
Expand All @@ -178,6 +181,7 @@ impl FromStr for FileFormat {
"pdb" => FileFormat::Pdb,
"pe" => FileFormat::Pe,
"sourcebundle" => FileFormat::SourceBundle,
"wasm" => FileFormat::Wasm,
_ => return Err(UnknownFileFormatError),
})
}
Expand Down
1 change: 1 addition & 0 deletions debuginfo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub mod macho;
pub mod pdb;
pub mod pe;
pub mod sourcebundle;
pub mod wasm;

pub use crate::base::*;
pub use crate::object::*;
27 changes: 27 additions & 0 deletions debuginfo/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::pdb::*;
use crate::pe::*;
use crate::private::{MonoArchive, MonoArchiveObjects};
use crate::sourcebundle::*;
use crate::wasm::*;

macro_rules! match_inner {
($value:expr, $ty:tt ($pat:pat) => $expr:expr) => {
Expand All @@ -26,6 +27,7 @@ macro_rules! match_inner {
$ty::Pdb($pat) => $expr,
$ty::Pe($pat) => $expr,
$ty::SourceBundle($pat) => $expr,
$ty::Wasm($pat) => $expr,
}
};
}
Expand All @@ -39,6 +41,7 @@ macro_rules! map_inner {
$from::Pdb($pat) => $to::Pdb($expr),
$from::Pe($pat) => $to::Pe($expr),
$from::SourceBundle($pat) => $to::SourceBundle($expr),
$from::Wasm($pat) => $to::Wasm($expr),
}
};
}
Expand All @@ -54,6 +57,7 @@ macro_rules! map_result {
$from::SourceBundle($pat) => $expr
.map($to::SourceBundle)
.map_err(ObjectError::SourceBundle),
$from::Wasm($pat) => $expr.map($to::Wasm).map_err(ObjectError::Wasm),
}
};
}
Expand Down Expand Up @@ -94,6 +98,10 @@ pub enum ObjectError {
/// An error in source bundles.
#[fail(display = "failed to process source bundle")]
SourceBundle(#[fail(cause)] SourceBundleError),

/// An error in source bundles.
#[fail(display = "failed to process wasm file")]
Wasm(#[fail(cause)] WasmError),
}

/// Tries to infer the object type from the start of the given buffer.
Expand Down Expand Up @@ -124,6 +132,8 @@ pub fn peek(data: &[u8], archive: bool) -> FileFormat {
FileFormat::Breakpad
} else if PdbObject::test(data) {
FileFormat::Pdb
} else if WasmObject::test(data) {
FileFormat::Wasm
} else {
FileFormat::Unknown
}
Expand All @@ -145,6 +155,8 @@ pub enum Object<'d> {
Pe(PeObject<'d>),
/// A source bundle
SourceBundle(SourceBundle<'d>),
/// a WASM file.
Wasm(WasmObject<'d>),
}

impl<'d> Object<'d> {
Expand Down Expand Up @@ -173,6 +185,7 @@ impl<'d> Object<'d> {
FileFormat::Pdb => parse_object!(Pdb, PdbObject, data),
FileFormat::Pe => parse_object!(Pe, PeObject, data),
FileFormat::SourceBundle => parse_object!(SourceBundle, SourceBundle, data),
FileFormat::Wasm => parse_object!(Wasm, WasmObject, data),
FileFormat::Unknown => return Err(ObjectError::UnsupportedObject),
};

Expand All @@ -188,6 +201,7 @@ impl<'d> Object<'d> {
Object::Pdb(_) => FileFormat::Pdb,
Object::Pe(_) => FileFormat::Pe,
Object::SourceBundle(_) => FileFormat::SourceBundle,
Object::Wasm(_) => FileFormat::Wasm,
}
}

Expand Down Expand Up @@ -282,6 +296,10 @@ impl<'d> Object<'d> {
.debug_session()
.map(ObjectDebugSession::SourceBundle)
.map_err(ObjectError::SourceBundle),
Object::Wasm(ref o) => o
.debug_session()
.map(ObjectDebugSession::Dwarf)
.map_err(ObjectError::Dwarf),
}
}

Expand Down Expand Up @@ -508,6 +526,7 @@ pub enum SymbolIterator<'d, 'o> {
Pdb(PdbSymbolIterator<'d, 'o>),
Pe(PeSymbolIterator<'d, 'o>),
SourceBundle(SourceBundleSymbolIterator<'d>),
Wasm(WasmSymbolIterator<'d, 'o>),
}

impl<'d, 'o> Iterator for SymbolIterator<'d, 'o> {
Expand All @@ -526,6 +545,7 @@ enum ArchiveInner<'d> {
Pdb(MonoArchive<'d, PdbObject<'d>>),
Pe(MonoArchive<'d, PeObject<'d>>),
SourceBundle(MonoArchive<'d, SourceBundle<'d>>),
Wasm(MonoArchive<'d, WasmObject<'d>>),
}

/// A generic archive that can contain one or more object files.
Expand Down Expand Up @@ -561,6 +581,7 @@ impl<'d> Archive<'d> {
FileFormat::Pdb => Archive(ArchiveInner::Pdb(MonoArchive::new(data))),
FileFormat::Pe => Archive(ArchiveInner::Pe(MonoArchive::new(data))),
FileFormat::SourceBundle => Archive(ArchiveInner::SourceBundle(MonoArchive::new(data))),
FileFormat::Wasm => Archive(ArchiveInner::Wasm(MonoArchive::new(data))),
FileFormat::Unknown => return Err(ObjectError::UnsupportedObject),
};

Expand All @@ -575,6 +596,7 @@ impl<'d> Archive<'d> {
ArchiveInner::MachO(_) => FileFormat::MachO,
ArchiveInner::Pdb(_) => FileFormat::Pdb,
ArchiveInner::Pe(_) => FileFormat::Pe,
ArchiveInner::Wasm(_) => FileFormat::Wasm,
ArchiveInner::SourceBundle(_) => FileFormat::SourceBundle,
}
}
Expand Down Expand Up @@ -620,6 +642,10 @@ impl<'d> Archive<'d> {
.object_by_index(index)
.map(|opt| opt.map(Object::SourceBundle))
.map_err(ObjectError::SourceBundle),
ArchiveInner::Wasm(ref a) => a
.object_by_index(index)
.map(|opt| opt.map(Object::Wasm))
.map_err(ObjectError::Wasm),
}
}

Expand Down Expand Up @@ -647,6 +673,7 @@ enum ObjectIteratorInner<'d, 'a> {
Pdb(MonoArchiveObjects<'d, PdbObject<'d>>),
Pe(MonoArchiveObjects<'d, PeObject<'d>>),
SourceBundle(MonoArchiveObjects<'d, SourceBundle<'d>>),
Wasm(MonoArchiveObjects<'d, WasmObject<'d>>),
}

/// An iterator over [`Object`](enum.Object.html)s in an [`Archive`](struct.Archive.html).
Expand Down
Loading