Skip to content

Instantly share code, notes, and snippets.

View yurydelendik's full-sized avatar

Yury Delendik yurydelendik

View GitHub Profile
@yurydelendik
yurydelendik / fib-frames.dump
Created July 30, 2020 14:22
fib.wat with cranelift
.debug_frame contents:
00000000 00000014 ffffffff CIE
Version: 1
Augmentation: ""
Code alignment factor: 1
Data alignment factor: -8
Return address column: 16
DW_CFA_def_cfa: reg7 +8
diff --git a/lld/test/wasm/debuginfo.test b/lld/test/wasm/debuginfo.test
index 59c36979b4b..2566b74d93b 100644
--- a/lld/test/wasm/debuginfo.test
+++ b/lld/test/wasm/debuginfo.test
@@ -45,7 +45,7 @@ CHECK-NEXT: DW_AT_name ("hi_foo.c")
CHECK: DW_TAG_variable
CHECK-NEXT: DW_AT_name ("y")
-CHECK-NEXT: DW_AT_type (0x000000a1 "int[2]")
+CHECK-NEXT: DW_AT_type (0x000000a7 "int[2]")
yury:~/Work/wasmtime$ cat t.c
#include <stdlib.h>
struct Test
{
int i;
int j;
};
struct Test t[2] = { {1, 2}, {3, 4}};

This document shows how to embed the wasmtime and run a simple wasm code.

Create wasm

Let's create a simple WebAssembly file with a single exported function that returns an integer:

(;; wat2wasm hello.wat -o $WASM_FILES/hello.wasm ;;)
(module
 (func (export "answer") (result i32)
diff --git a/bench/vm/bencher/project/BenchTestGenerator.py b/bench/vm/bencher/project/BenchTestGenerator.py
index a7b8ff41..933e6f2b 100644
--- a/bench/vm/bencher/project/BenchTestGenerator.py
+++ b/bench/vm/bencher/project/BenchTestGenerator.py
@@ -47,7 +47,7 @@ class BenchTestGenerator:
generated_tests_dir_full_path = join(out_dir, self.generated_tests_dir)
test_mv_cmd = "mv {} {}".format(
- join(out_dir, "wasm32-unknown-unknown", "release", "{}.wasm"),
+ join(out_dir, "wasm32-unknown-unknown", "release", "{}_wasm.wasm"),
@yurydelendik
yurydelendik / hello2.expanded.rs
Last active October 15, 2019 21:27
helloS.expanded.rs
#![feature(prelude_import)]
#![no_std]
#![doc = " Translation of hello example"]
#[prelude_import]
use ::std::prelude::v1::*;
#[macro_use]
extern crate std as std;
use failure::{bail, format_err, Error};
use std::cell::Ref;
use std::fs::read;
@yurydelendik
yurydelendik / node-wasi-sassc.patch
Created June 12, 2019 17:49
some fixes to node-wasi
diff --git a/run.js b/run.js
index 87928f1..94f353d 100755
--- a/run.js
+++ b/run.js
@@ -30,9 +30,11 @@ USAGE:
const bin = fs.readFileSync(process.argv[2]);
const mod = new WebAssembly.Module(bin);
+const preopenDirectories = {};
+preopenDirectories[process.cwd()] = process.cwd();
@yurydelendik
yurydelendik / lldb-jit-unwind.diff
Created February 12, 2019 18:31
Trust JIT unwind plan patch for lldb
diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp b/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
index 423b2e53c66..62dedbd75a6 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
+++ b/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
@@ -829,6 +829,22 @@ UnwindPlanSP RegisterContextLLDB::GetFullUnwindPlanForFrame() {
}
}
+ // The JIT generated module may generate their .eh_frame or .debug_frame
+ // sections. It makes sense to trust that unwind plan if it is valid.
@yurydelendik
yurydelendik / sourceURLPrefixes.md
Created August 29, 2018 21:19
sourceURLPrefixes WebAssembly custom section

sourceURLPrefixes WebAssembly custom section

This custom section is created to provide mapping of the local (or remote) file paths to network resources. Currently we can have DWARF sections inside the binary WebAssembly file, however debugger, in most of the cases, cannot retrive local files -- this file paths needs to be mapped to some networks server location.

Format

The custom section has the following format:

@yurydelendik
yurydelendik / x-scopes.md
Created August 1, 2018 19:30
Experimental "x-scopes" source maps extension

Experimental "x-scopes" source maps extension

This is crude attempt to add DWARF-like information to the existing wasm source maps. It is not intendent to be used as a final solution, but provides overview of the information that can be used by a consumer/debugger of wasm code.

The source maps JSON is extended to add the x-scopes field at the top level that will contains all information generated by LLVM's llvm-dwarfdump command. To reduce burden of parsing at the consumer side, the dump will be converted to the JSON using following rules:

  1. DW_TAG_xxx entity will be converted to a JS object with tag field with xxx value.
  2. If the above entry has nested level of children, the children field will be added and will contain JS array.
  3. DW_AT_yyy attributes will be assigned at fields to the enclosing object with yyy name. Theirs values will be: