From 88a6b084c64cecde3d2a6677725d3dbb3397e70d Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 15 Dec 2023 07:50:15 +0900 Subject: [PATCH] libwasi: fix build with tracing --- libwasi/wasi.c | 14 ++++++++------ libwasi/wasi_fdtable.c | 7 ++----- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/libwasi/wasi.c b/libwasi/wasi.c index f46a8482..b487b45e 100644 --- a/libwasi/wasi.c +++ b/libwasi/wasi.c @@ -241,6 +241,9 @@ wasi_fdinfo_close_user(struct wasi_fdinfo *fdinfo) if (ret != 0) { ret = errno; assert(ret > 0); + xlog_trace("failed to close: host fd %" PRIu32 + " with errno %d", + hostfd, ret); } } free(fdinfo->u.u_user.path); @@ -2019,13 +2022,11 @@ wasi_fd_prestat_dir_name(struct exec_context *ctx, struct host_instance *hi, ret = EBADF; goto fail; } - xlog_trace("wasm fd %" PRIu32 " is prestat %s", wasifd, - fdinfo->prestat_path); - const char *prestat_path = fdinfo->u.u_prestat.prestat_path; if (fdinfo->u.u_prestat.wasm_path != NULL) { prestat_path = fdinfo->u.u_prestat.wasm_path; } + xlog_trace("wasm fd %" PRIu32 " is prestat %s", wasifd, prestat_path); size_t len = strlen(prestat_path); if (len > pathlen) { xlog_trace("path buffer too small %zu > %" PRIu32, len, @@ -2605,7 +2606,7 @@ wasi_path_open(struct exec_context *ctx, struct host_instance *hi, if (host_ret != 0 || ret != 0) { goto fail; } - xlog_trace("open %s oflags %x", path.hostpath, oflags); + xlog_trace("open %s oflags %x", pi.hostpath, oflags); /* * TODO: avoid blocking on fifos for wasi-threads. */ @@ -2622,7 +2623,7 @@ wasi_path_open(struct exec_context *ctx, struct host_instance *hi, if (hostfd == -1) { ret = errno; assert(ret > 0); - xlog_trace("open %s oflags %x failed with %d", hostpath, + xlog_trace("open %s oflags %x failed with %d", pi.hostpath, oflags, errno); goto fail; } @@ -3760,7 +3761,8 @@ wasi_instance_prestat_add_common(struct wasi_instance *wasi, const char *path, } wasi_fd_affix(wasi, wasifd, fdinfo); toywasm_mutex_unlock(&wasi->lock); - xlog_trace("prestat added %s (%s)", path, fdinfo->prestat_path); + xlog_trace("prestat added %s (%s)", path, + fdinfo->u.u_prestat.prestat_path); return 0; fail: free(host_path); diff --git a/libwasi/wasi_fdtable.c b/libwasi/wasi_fdtable.c index 3222e6f6..2f634a45 100644 --- a/libwasi/wasi_fdtable.c +++ b/libwasi/wasi_fdtable.c @@ -252,14 +252,11 @@ wasi_fdtable_free(struct wasi_instance *wasi) NO_THREAD_SAFETY_ANALYSIS continue; } assert(fdinfo->refcount == 1); -#if defined(TOYWASM_ENABLE_TRACING) - int hostfd = fdinfo->hostfd; -#endif int ret = wasi_fdinfo_close(fdinfo); if (ret != 0) { xlog_trace("failed to close: wasm fd %" PRIu32 - " host fd %u with errno %d", - i, hostfd, ret); + " with errno %d", + i, ret); } free(fdinfo); }