Skip to content

Commit 945f4e1

Browse files
Add debug logs in witapi conditionally
1 parent b1b97d5 commit 945f4e1

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

ext/witapi/witapi-core.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ void *rb_wasm_handle_scan_unwind(void);
2020
void *rb_wasm_handle_fiber_unwind(void (**new_fiber_entry)(void *, void *),
2121
void **arg0, void **arg1,
2222
bool *is_new_fiber_started);
23+
#define RB_WASM_ENABLE_DEBUG_LOG 0
24+
25+
#if RB_WASM_ENABLE_DEBUG_LOG
26+
# define RB_WASM_DEBUG_LOG(...) fprintf(stderr, __VA_ARGS__)
27+
#else
28+
# define RB_WASM_DEBUG_LOG(...) (void)0
29+
#endif
2330

2431
#define RB_WASM_LIB_RT(MAIN_ENTRY) \
2532
{ \
@@ -79,6 +86,7 @@ static VALUE rb_abi_lend_object_internal(VALUE obj) {
7986
return Qundef;
8087
}
8188
static void rb_abi_lend_object(VALUE obj) {
89+
RB_WASM_DEBUG_LOG("rb_abi_lend_object: obj = %p\n", (void *)obj);
8290
int state;
8391
RB_WASM_LIB_RT(rb_protect(rb_abi_lend_object_internal, obj, &state));
8492
assert(state == TAG_NONE && "rb_abi_lend_object_internal failed");
@@ -92,13 +100,16 @@ static VALUE rb_abi_guest_rb_abi_value_dtor_internal(VALUE obj) {
92100
}
93101
if (ref_count == INT2FIX(1)) {
94102
rb_hash_delete(rb_abi_guest_arena_hash, obj);
103+
RB_WASM_DEBUG_LOG("rb_abi_guest_rb_abi_value_dtor: ref_count == 1\n");
95104
} else {
96105
rb_hash_aset(rb_abi_guest_arena_hash, obj, INT2FIX(FIX2INT(ref_count) - 1));
106+
RB_WASM_DEBUG_LOG("rb_abi_guest_rb_abi_value_dtor: ref_count = %d\n", FIX2INT(ref_count));
97107
}
98108
return Qundef;
99109
}
100110

101111
void rb_abi_guest_rb_abi_value_dtor(void *data) {
112+
RB_WASM_DEBUG_LOG("rb_abi_guest_rb_abi_value_dtor: data = %p\n", data);
102113
int state;
103114
RB_WASM_LIB_RT(rb_protect(rb_abi_guest_rb_abi_value_dtor_internal, (VALUE)data, &state));
104115
assert(state == TAG_NONE && "rb_abi_guest_rb_abi_value_dtor_internal failed");
@@ -153,8 +164,10 @@ void rb_abi_guest_rb_eval_string_protect(rb_abi_guest_string_t *str,
153164
rb_abi_guest_rb_abi_value_t *result,
154165
int32_t *state) {
155166
VALUE retval;
167+
RB_WASM_DEBUG_LOG("rb_eval_string_protect: str = %s\n", str->ptr);
156168
RB_WASM_LIB_RT(retval = rb_eval_string_protect(str->ptr, state));
157169
rb_abi_lend_object(retval);
170+
RB_WASM_DEBUG_LOG("rb_eval_string_protect: retval = %p, state = %d\n", (void *)retval, *state);
158171

159172
*result = rb_abi_guest_rb_abi_value_new((void *)retval);
160173
}
@@ -185,6 +198,8 @@ void rb_abi_guest_rb_funcallv_protect(rb_abi_guest_rb_abi_value_t recv,
185198
.recv = r_recv, .mid = mid, .args = args};
186199
RB_WASM_LIB_RT(retval = rb_protect(rb_funcallv_thunk, (VALUE)&ctx, ret1));
187200
rb_abi_lend_object(retval);
201+
RB_WASM_DEBUG_LOG("rb_abi_guest_rb_funcallv_protect: retval = %p, state = %d\n", (void *)retval, *ret1);
202+
188203
*ret0 = rb_abi_guest_rb_abi_value_new((void *)retval);
189204
}
190205

0 commit comments

Comments
 (0)