Skip to content

Instantly share code, notes, and snippets.

@yurydelendik
Created April 7, 2020 21:22
Show Gist options
  • Save yurydelendik/ba86fe491765bfd073c6e08d056c8012 to your computer and use it in GitHub Desktop.
Save yurydelendik/ba86fe491765bfd073c6e08d056c8012 to your computer and use it in GitHub Desktop.
yury:~/Work/wasmtime$ cat t.c
#include <stdlib.h>
struct Test
{
int i;
int j;
};
struct Test t[2] = { {1, 2}, {3, 4}};
int check(size_t i) {
struct Test *y = t + i;
y->i++;
return y->j;
}
yury:~/Work/wasmtime$ ~/bin/wasi-sdk/bin/clang t.c -o t.wasm -nostdlib -Wl,--no-entry,--export=check -g
yury:~/Work/wasmtime$ lldb -- target/debug/wasmtime run --opt-level 0 -g t.wasm --invoke check 1
(lldb) target create "target/debug/wasmtime"
Current executable set to 'target/debug/wasmtime' (x86_64).
(lldb) settings set -- target.run-args "run" "--opt-level" "0" "-g" "t.wasm" "--invoke" "check" "1"
(lldb) b t.c:13
Breakpoint 1: no locations (pending).
WARNING: Unable to resolve breakpoint to any actual locations.
(lldb) r
Process 50051 launched: '/Users/yury/Work/wasmtime/target/debug/wasmtime' (x86_64)
1 location added to breakpoint 1
warning: using `--invoke` with a function that takes arguments is experimental and may break in the future
Process 50051 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x000000010408905d JIT(0x105000000)`check(i=1) at t.c:13:3
10
11 int check(size_t i) {
12 struct Test *y = t + i;
-> 13 y->i++;
14 return y->j;
15 }
16
(lldb) pp *y
(Test) $0 = (i = 3, j = 4)
(lldb) n
Process 50051 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step over
frame #0: 0x000000010408908d JIT(0x105000000)`check(i=1) at t.c:14:10
11 int check(size_t i) {
12 struct Test *y = t + i;
13 y->i++;
-> 14 return y->j;
15 }
16
(lldb) pp y->i
(int) $1 = 4
(lldb) p y
(WebAssemblyPtrWrapper<Test>) $2 = (__ptr = 1032)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment