mirror of
https://github.com/pezkuwichain/wasm-instrument.git
synced 2026-07-22 22:05:42 +00:00
handle debug info (#16)
This commit is contained in:
@@ -16,6 +16,10 @@ The interface provided to smart contracts will adhere to semver with one excepti
|
|||||||
major version bumps will be backwards compatible with regard to already deployed contracts.
|
major version bumps will be backwards compatible with regard to already deployed contracts.
|
||||||
In other words: Upgrading this pallet will not break pre-existing contracts.
|
In other words: Upgrading this pallet will not break pre-existing contracts.
|
||||||
|
|
||||||
|
## [v0.1.2] 2022-06-06
|
||||||
|
- Adjust debug information (if already parsed) when injecting gas metering
|
||||||
|
[#16](https://github.com/paritytech/wasm-instrument/pull/16)
|
||||||
|
|
||||||
## [v0.1.1] 2022-01-18
|
## [v0.1.1] 2022-01-18
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "wasm-instrument"
|
name = "wasm-instrument"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.56.1"
|
rust-version = "1.56.1"
|
||||||
authors = ["Parity Technologies <admin@parity.io>"]
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
@@ -20,7 +20,7 @@ lto = "fat"
|
|||||||
codegen-units = 1
|
codegen-units = 1
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
parity-wasm = { version = "0.42", default-features = false }
|
parity-wasm = { version = "0.45", default-features = false }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
binaryen = "0.12"
|
binaryen = "0.12"
|
||||||
|
|||||||
+14
-2
@@ -11,7 +11,7 @@ use alloc::{vec, vec::Vec};
|
|||||||
use core::{cmp::min, mem, num::NonZeroU32};
|
use core::{cmp::min, mem, num::NonZeroU32};
|
||||||
use parity_wasm::{
|
use parity_wasm::{
|
||||||
builder,
|
builder,
|
||||||
elements::{self, Instruction, ValueType},
|
elements::{self, IndexMap, Instruction, ValueType},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// An interface that describes instruction costs.
|
/// An interface that describes instruction costs.
|
||||||
@@ -129,7 +129,8 @@ impl Rules for ConstantCostRules {
|
|||||||
///
|
///
|
||||||
/// The above transformations are performed for every function body defined in the module. This
|
/// The above transformations are performed for every function body defined in the module. This
|
||||||
/// function also rewrites all function indices references by code, table elements, etc., since
|
/// function also rewrites all function indices references by code, table elements, etc., since
|
||||||
/// the addition of an imported functions changes the indices of module-defined functions.
|
/// the addition of an imported functions changes the indices of module-defined functions. If the
|
||||||
|
/// the module has a NameSection, added by calling `parse_names`, the indices will also be updated.
|
||||||
///
|
///
|
||||||
/// This routine runs in time linear in the size of the input module.
|
/// This routine runs in time linear in the size of the input module.
|
||||||
///
|
///
|
||||||
@@ -212,6 +213,17 @@ pub fn inject<R: Rules>(
|
|||||||
if *start_idx >= gas_func {
|
if *start_idx >= gas_func {
|
||||||
*start_idx += 1
|
*start_idx += 1
|
||||||
},
|
},
|
||||||
|
elements::Section::Name(s) =>
|
||||||
|
for functions in s.functions_mut() {
|
||||||
|
*functions.names_mut() =
|
||||||
|
IndexMap::from_iter(functions.names().iter().map(|(mut idx, name)| {
|
||||||
|
if idx >= gas_func {
|
||||||
|
idx += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
(idx, name.clone())
|
||||||
|
}));
|
||||||
|
},
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -1,3 +1,4 @@
|
|||||||
|
use parity_wasm::elements::Module;
|
||||||
use std::{
|
use std::{
|
||||||
fs,
|
fs,
|
||||||
io::{self, Read, Write},
|
io::{self, Read, Write},
|
||||||
@@ -101,8 +102,10 @@ mod gas {
|
|||||||
run_diff_test("gas", concat!(stringify!($name), ".wat"), |input| {
|
run_diff_test("gas", concat!(stringify!($name), ".wat"), |input| {
|
||||||
let rules = instrument::gas_metering::ConstantCostRules::default();
|
let rules = instrument::gas_metering::ConstantCostRules::default();
|
||||||
|
|
||||||
let module =
|
let module: Module =
|
||||||
elements::deserialize_buffer(input).expect("Failed to deserialize");
|
elements::deserialize_buffer(input).expect("Failed to deserialize");
|
||||||
|
let module = module.parse_names().expect("Failed to parse names");
|
||||||
|
|
||||||
let instrumented = instrument::gas_metering::inject(module, &rules, "env")
|
let instrumented = instrument::gas_metering::inject(module, &rules, "env")
|
||||||
.expect("Failed to instrument with gas metering");
|
.expect("Failed to instrument with gas metering");
|
||||||
elements::serialize(instrumented).expect("Failed to serialize")
|
elements::serialize(instrumented).expect("Failed to serialize")
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
(module
|
(module
|
||||||
(type (;0;) (func (result i32)))
|
(type (;0;) (func (result i32)))
|
||||||
(type (;1;) (func (param i32)))
|
(type (;1;) (func (param i32)))
|
||||||
(import "env" "gas" (func $fibonacci_with_break (type 1)))
|
(import "env" "gas" (func (;0;) (type 1)))
|
||||||
(func (;1;) (type 0) (result i32)
|
(func $fibonacci_with_break (;1;) (type 0) (result i32)
|
||||||
(local i32 i32)
|
(local i32 i32)
|
||||||
i32.const 13
|
i32.const 13
|
||||||
call $fibonacci_with_break
|
call 0
|
||||||
block ;; label = @1
|
block ;; label = @1
|
||||||
i32.const 0
|
i32.const 0
|
||||||
local.set 0
|
local.set 0
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
i32.const 1
|
i32.const 1
|
||||||
br_if 0 (;@1;)
|
br_if 0 (;@1;)
|
||||||
i32.const 5
|
i32.const 5
|
||||||
call $fibonacci_with_break
|
call 0
|
||||||
local.get 0
|
local.get 0
|
||||||
local.get 1
|
local.get 1
|
||||||
local.tee 0
|
local.tee 0
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
(module
|
(module
|
||||||
(type (;0;) (func (param i32 i32) (result i32)))
|
(type (;0;) (func (param i32 i32) (result i32)))
|
||||||
(type (;1;) (func (param i32)))
|
(type (;1;) (func (param i32)))
|
||||||
(import "env" "gas" (func $add_locals (type 1)))
|
(import "env" "gas" (func (;0;) (type 1)))
|
||||||
(func $add (type 0) (param $x i32) (param $y i32) (result i32)
|
(func $add_locals (;1;) (type 0) (param $x i32) (param $y i32) (result i32)
|
||||||
(local i32)
|
(local i32)
|
||||||
i32.const 5
|
i32.const 5
|
||||||
call $add_locals
|
call 0
|
||||||
local.get $x
|
local.get $x
|
||||||
local.get $y
|
local.get $y
|
||||||
call 2
|
call $add
|
||||||
local.set 2
|
local.set 2
|
||||||
local.get 2
|
local.get 2
|
||||||
)
|
)
|
||||||
(func (;2;) (type 0) (param i32 i32) (result i32)
|
(func $add (;2;) (type 0) (param i32 i32) (result i32)
|
||||||
i32.const 3
|
i32.const 3
|
||||||
call $add_locals
|
call 0
|
||||||
local.get 0
|
local.get 0
|
||||||
local.get 1
|
local.get 1
|
||||||
i32.add
|
i32.add
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
(type (;0;) (func (param i32 i32)))
|
(type (;0;) (func (param i32 i32)))
|
||||||
(type (;1;) (func))
|
(type (;1;) (func))
|
||||||
(type (;2;) (func (param i32)))
|
(type (;2;) (func (param i32)))
|
||||||
(import "env" "ext_return" (func $ext_return (type 0)))
|
(import "env" "ext_return" (func $ext_return (;0;) (type 0)))
|
||||||
(import "env" "memory" (memory (;0;) 1 1))
|
(import "env" "memory" (memory (;0;) 1 1))
|
||||||
(import "env" "gas" (func $start (type 2)))
|
(import "env" "gas" (func (;1;) (type 2)))
|
||||||
(func (;2;) (type 1)
|
(func $start (;2;) (type 1)
|
||||||
i32.const 4
|
i32.const 4
|
||||||
call $start
|
call 1
|
||||||
i32.const 8
|
i32.const 8
|
||||||
i32.const 4
|
i32.const 4
|
||||||
call $ext_return
|
call $ext_return
|
||||||
@@ -15,6 +15,6 @@
|
|||||||
)
|
)
|
||||||
(func (;3;) (type 1))
|
(func (;3;) (type 1))
|
||||||
(export "call" (func 3))
|
(export "call" (func 3))
|
||||||
(start 2)
|
(start $start)
|
||||||
(data (;0;) (i32.const 8) "\01\02\03\04")
|
(data (;0;) (i32.const 8) "\01\02\03\04")
|
||||||
)
|
)
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
(type (;0;) (func))
|
(type (;0;) (func))
|
||||||
(type (;1;) (func (param i32 i32) (result i32)))
|
(type (;1;) (func (param i32 i32) (result i32)))
|
||||||
(type (;2;) (func (param i32)))
|
(type (;2;) (func (param i32)))
|
||||||
(import "env" "foo" (func $foo (type 0)))
|
(import "env" "foo" (func $foo (;0;) (type 0)))
|
||||||
(func $i32.add (type 1) (param i32 i32) (result i32)
|
(func $i32.add (;1;) (type 1) (param i32 i32) (result i32)
|
||||||
local.get 0
|
local.get 0
|
||||||
local.get 1
|
local.get 1
|
||||||
i32.add
|
i32.add
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
i32.sub
|
i32.sub
|
||||||
global.set 1
|
global.set 1
|
||||||
)
|
)
|
||||||
(global $counter (mut i32) i32.const 1)
|
(global $counter (;0;) (mut i32) i32.const 1)
|
||||||
(global (;1;) (mut i32) i32.const 0)
|
(global (;1;) (mut i32) i32.const 0)
|
||||||
(export "i32.add" (func 3))
|
(export "i32.add" (func 3))
|
||||||
)
|
)
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
(module
|
(module
|
||||||
(type (;0;) (func))
|
(type (;0;) (func))
|
||||||
(type (;1;) (func (param i32 i32) (result i32)))
|
(type (;1;) (func (param i32 i32) (result i32)))
|
||||||
(import "env" "foo" (func $foo (type 0)))
|
(import "env" "foo" (func $foo (;0;) (type 0)))
|
||||||
(import "env" "boo" (func $boo (type 0)))
|
(import "env" "boo" (func $boo (;1;) (type 0)))
|
||||||
(func (;2;) (type 1) (param i32 i32) (result i32)
|
(func (;2;) (type 1) (param i32 i32) (result i32)
|
||||||
call $foo
|
call $foo
|
||||||
call $boo
|
call $boo
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
(module
|
(module
|
||||||
(type (;0;) (func))
|
(type (;0;) (func))
|
||||||
(func $one-group-many-locals (type 0)
|
(func $one-group-many-locals (;0;) (type 0)
|
||||||
(local i64 i64 i32)
|
(local i64 i64 i32)
|
||||||
)
|
)
|
||||||
(func $main (type 0)
|
(func $main (;1;) (type 0)
|
||||||
global.get 0
|
global.get 0
|
||||||
i32.const 5
|
i32.const 5
|
||||||
i32.add
|
i32.add
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
(module
|
(module
|
||||||
(type (;0;) (func (param i32 i32)))
|
(type (;0;) (func (param i32 i32)))
|
||||||
(type (;1;) (func))
|
(type (;1;) (func))
|
||||||
(import "env" "ext_return" (func $ext_return (type 0)))
|
(import "env" "ext_return" (func $ext_return (;0;) (type 0)))
|
||||||
(import "env" "memory" (memory (;0;) 1 1))
|
(import "env" "memory" (memory (;0;) 1 1))
|
||||||
(func $start (type 1)
|
(func $start (;1;) (type 1)
|
||||||
(local i32)
|
(local i32)
|
||||||
)
|
)
|
||||||
(func (;2;) (type 1))
|
(func (;2;) (type 1))
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
(type (;0;) (func))
|
(type (;0;) (func))
|
||||||
(type (;1;) (func (param i32)))
|
(type (;1;) (func (param i32)))
|
||||||
(type (;2;) (func (param i32 i32) (result i32)))
|
(type (;2;) (func (param i32 i32) (result i32)))
|
||||||
(import "env" "foo" (func $foo (type 0)))
|
(import "env" "foo" (func $foo (;0;) (type 0)))
|
||||||
(func (;1;) (type 1) (param i32)
|
(func (;1;) (type 1) (param i32)
|
||||||
local.get 0
|
local.get 0
|
||||||
i32.const 0
|
i32.const 0
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
global.set 0
|
global.set 0
|
||||||
drop
|
drop
|
||||||
)
|
)
|
||||||
(func $i32.add (type 2) (param i32 i32) (result i32)
|
(func $i32.add (;2;) (type 2) (param i32 i32) (result i32)
|
||||||
local.get 0
|
local.get 0
|
||||||
local.get 1
|
local.get 1
|
||||||
i32.add
|
i32.add
|
||||||
|
|||||||
Reference in New Issue
Block a user