Skip to content

Commit 2c59939

Browse files
committed
dump wasi parameters
1 parent 04283d6 commit 2c59939

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

lib/host_instance.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <assert.h>
22
#include <errno.h>
3+
#include <inttypes.h>
34
#include <stdlib.h>
45

56
#include "host_instance.h"
@@ -86,3 +87,30 @@ import_object_create_for_host_funcs(const struct host_module *modules,
8687
import_object_destroy(im);
8788
return ret;
8889
}
90+
91+
void
92+
host_func_dump_params(const struct functype *ft, const struct cell *params)
93+
{
94+
const struct resulttype *rt = &ft->parameter;
95+
uint32_t i;
96+
for (i = 0; i < rt->ntypes; i++) {
97+
enum valtype type = rt->types[i];
98+
uint32_t sz = valtype_cellsize(type);
99+
struct val val;
100+
val_from_cells(&val, &params[i], sz);
101+
#if defined(TOYWASM_USE_SMALL_CELLS)
102+
switch (sz) {
103+
case 1:
104+
xlog_trace("param[%" PRIu32 "] = %08" PRIu32, i,
105+
val.u.i32);
106+
break;
107+
case 2:
108+
xlog_trace("param[%" PRIu32 "] = %016" PRIu64, i,
109+
val.u.i64);
110+
break;
111+
}
112+
#else
113+
xlog_trace("param[%" PRIu32 "] = %016" PRIu64, i, val.u.i64);
114+
#endif
115+
}
116+
}

lib/host_instance.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ struct import_object;
3737
int import_object_create_for_host_funcs(const struct host_module *hm, size_t n,
3838
struct host_instance *hi,
3939
struct import_object **impp);
40+
41+
void host_func_dump_params(const struct functype *ft,
42+
const struct cell *params);

lib/wasi_impl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define WASI_TRACE \
99
do { \
1010
xlog_trace("WASI: %s called", __func__); \
11+
host_func_dump_params(ft, params); \
1112
} while (0)
1213
#else
1314
#define WASI_TRACE \

0 commit comments

Comments
 (0)