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

dwarf debugging #137

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "orca-wasm"
version = "0.1.2"
version = "0.1.1"
edition = "2021"
authors = ["Suhas Thalanki", "Alex Bai", "Elizabeth Gilbert"]
description = "A lightweight WebAssembly Transformation Library for the Component Model"
Expand Down
10 changes: 10 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::ops::Range;
use wasmparser::BinaryReaderError;

use gimli;

#[derive(Debug, Clone)]
#[allow(clippy::enum_variant_names)]

Expand Down Expand Up @@ -35,6 +37,14 @@ pub enum Error {
},
}

impl From<gimli::Error> for Error {
fn from(err: gimli::Error) -> Error {
// You need to map `gimli::Error` to your custom error type here.
// This is a simple example, adjust based on your `error::Error` definition.
Self::ConversionError(err.to_string()) // Assuming you have a variant `GimliError` in your `error::Error` enum
}
}

impl From<BinaryReaderError> for Error {
fn from(e: BinaryReaderError) -> Self {
Self::BinaryReaderError(e)
Expand Down
501 changes: 497 additions & 4 deletions src/ir/dwarf.rs

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions src/ir/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,49 @@ pub fn print_component_import(imp: &ComponentImport) {
pub fn print_component_export(exp: &ComponentExport) {
eprintln!("Component Export: {:?}", exp.name.0);
}

pub fn decode_u32(pos: &mut u32, func: &&[u8]) -> u32 {
let byte = func[*pos as usize];
if (byte & 0x80) == 0 {
u32::from(byte)
} else {
*pos += 1; // Increment the position only when you have to read in another byte
decode_u32_big(pos, func, byte)
}
}

pub fn decode_u32_big(pos: &mut u32, func: &&[u8], byte: u8) -> u32 {
let mut result = (byte & 0x7F) as u32;
let mut shift = 7;
loop {
let byte = func[*pos as usize];
result |= ((byte & 0x7F) as u32) << shift;
if shift >= 25 && (byte >> (32 - shift)) != 0 {
panic!("!trap");
}
shift += 7;
if (byte & 0x80) == 0 {
break;
}
*pos += 1; // Increment the position only when you have to read in another byte
}
result
}

pub(crate) fn get_size_of_local(func: &[u8]) -> u32 {
// If the first byte is 0, there are no local declarations
let mut pos = 0;
let num_local_decl = decode_u32(&mut pos, &func);
for _ in 0..num_local_decl {
// Go to the next byte
pos += 1;
// First u32 is for count
decode_u32(&mut pos, &func);
// Go to the next byte
pos += 1;
// Now is valtype encoding
decode_u32(&mut pos, &func);
}
// The location of the current offset will be the size of locals
pos + 1 // + 1 as it points to the last byte of locals
}
3 changes: 2 additions & 1 deletion src/ir/instr_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ pub fn assert_panics_with_message(func: impl FnOnce() + UnwindSafe, msg: &str) {
}

fn check_instr_op(op: &Operator, mode: InstrumentationMode) -> bool {
let mut instr = Instruction::new(op.clone());
// TODO: Check if this offset 0 makes sense
let mut instr = Instruction::new(op.clone(), 0);
instr.instr_flag.current_mode = Some(mode);
instr.add_instr(Operator::Nop); // should OR should not panic!
true
Expand Down
1 change: 1 addition & 0 deletions src/ir/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! The Intermediate Representation for components and modules.

pub mod component;
mod dwarf;
pub mod function;
mod helpers;
pub mod id;
Expand Down
Loading