Skip to content

WASM/Debugger: improve `show` commands to print values in multiple fashion

Pierrick Couderc requested to merge picdc@wasm-debugger-better-inspection into master

Context

Improves the show memory and show keys commands to print values in multiple format:

  • show memory at <address> for <length> bytes as string to print the value as their ascii representation
  • show memory at <address> as int32 to read the 4 bytes at the given address and print them as an int32
  • show memory at <address> as int64 to read the 8 bytes at the given address and print them as an int64
  • and similarly for show key <key> as <kind> where kind can be either int32, int64, string or hex.

The existing commands still exist, and return the hexadecimal representation.

Note that the commands accepts i32 (resp. i64) as a synonym for int32 (resp. i64) to respect WASM nomenclature.

Fixes #4209 (closed)

Manually testing the MR

You can try with the following kernel and an empty inbox (echo "[[]]" > inputs.json for example):

`kernel.wast`
(module
 (import "smart_rollup_core" "store_write"
         (func $store_write (param i32 i32 i32 i32 i32) (result i32)))
 (data (i32.const 100) "hello")
 (data (i32.const 120) "\63\6f\75\63\6f\75")
 (data (i32.const 140) "/value/string")
 (data (i32.const 160) "/value/hexadecimal")
 (data (i32.const 180) "/value/i32")
 (data (i32.const 190) "/value/i64")

 (memory 1)
 (export "mem" (memory 0))

 (func (export "kernel_run")
       (i32.store (i32.const 200) (i32.const 55128613))
       (i64.store (i32.const 300) (i64.const 11000000000))

       ;; store "hello"
       (call $store_write
             (i32.const 140)
             (i32.const 13)
             (i32.const 0) ;; value at offset 0 in the durable storage
             (i32.const 100)
             (i32.const 5))
       (drop)

       ;; store "\63\6f\75\63\6f\75"
       (call $store_write
             (i32.const 160)
             (i32.const 18)
             (i32.const 0) ;; value at offset 0 in the durable storage
             (i32.const 120)
             (i32.const 6))
       (drop)

       ;; store 55128613 (int32)
       (call $store_write
             (i32.const 180)
             (i32.const 10)
             (i32.const 0) ;; value at offset 0 in the durable storage
             (i32.const 200)
             (i32.const 4))
       (drop)

       ;; store 11000000000 (int64)
       (call $store_write
             (i32.const 190)
             (i32.const 10)
             (i32.const 0) ;; value at offset 0 in the durable storage
             (i32.const 300)
             (i32.const 8))
       (drop)
       )
 )

and the following commands:

> load inbox
...
> step result

Stopping the execution at the end of the evaluation (before the padding) allows inspecting the memory, otherwise it will be wiped out.

Then (for the show key commands):

> show key /value/string as string
hello
> show key /value/hexadecimal
636f75636f75
> show key /value/i32 as i32
55128613
> show key /value/i64 as i64
11000000000
> show key /value/string as i64
Error: int64 values must be 8 bytes long. Defaulting to hexadecimal value
68656c6c6f

and for the memory commands:

> show memory at 100 for 5 bytes as string
hello
> show memory at 120 for 6 bytes
636f75636f75
> show memory at 200 as i32
55128613
> show memory at 300 as i64
11000000000

Checklist

  • Document the interface of any function added or modified (see the coding guidelines)
  • Document any change to the user interface, including configuration parameters (see node configuration)
  • Provide automatic testing (see the testing guide).
  • For new features and bug fixes, add an item in the appropriate changelog (docs/protocols/alpha.rst for the protocol and the environment, CHANGES.rst at the root of the repository for everything else).
  • Select suitable reviewers using the Reviewers field below.
  • Select as Assignee the next person who should take action on that MR

Merge request reports