Use logger for runtime error/debug prints (#3097)

Change runtime internal error/debug prints from using `os_printf()`
to using `LOG_ERROR()`/`LOG_DEBUG()`.
This commit is contained in:
Enrico Loparco 2024-02-06 06:02:54 +01:00 committed by GitHub
parent f359b51525
commit cfa90ca44f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 35 additions and 35 deletions

View File

@ -3335,7 +3335,7 @@ load(const uint8 *buf, uint32 size, AOTModule *module, char *error_buf,
{ {
uint32 i; uint32 i;
for (i = 0; i < module->func_count; i++) { for (i = 0; i < module->func_count; i++) {
os_printf("AOT func %u, addr: %p\n", i, module->func_ptrs[i]); LOG_VERBOSE("AOT func %u, addr: %p\n", i, module->func_ptrs[i]);
} }
} }
#endif #endif

View File

@ -376,7 +376,7 @@ runtime_exception_handler(EXCEPTION_POINTERS *exce_info)
#endif #endif
} }
os_printf("Unhandled exception thrown: exception code: 0x%lx, " LOG_ERROR("Unhandled exception thrown: exception code: 0x%lx, "
"exception address: %p, exception information: %p\n", "exception address: %p, exception information: %p\n",
ExceptionRecord->ExceptionCode, ExceptionRecord->ExceptionAddress, ExceptionRecord->ExceptionCode, ExceptionRecord->ExceptionAddress,
sig_addr); sig_addr);

View File

@ -160,10 +160,10 @@ jit_compiler_compile(WASMModule *module, uint32 func_idx)
#if WASM_ENABLE_CUSTOM_NAME_SECTION != 0 #if WASM_ENABLE_CUSTOM_NAME_SECTION != 0
char *function_name = cc->cur_wasm_func->field_name; char *function_name = cc->cur_wasm_func->field_name;
os_printf("fast jit compilation failed: %s (function_name=%s)\n", LOG_ERROR("fast jit compilation failed: %s (function_name=%s)\n",
last_error ? last_error : "unknown error", function_name); last_error ? last_error : "unknown error", function_name);
#else #else
os_printf("fast jit compilation failed: %s\n", LOG_ERROR("fast jit compilation failed: %s\n",
last_error ? last_error : "unknown error"); last_error ? last_error : "unknown error");
#endif #endif

View File

@ -1093,7 +1093,7 @@ init_func_translation(JitCompContext *cc)
|| !(jit_frame = jit_calloc(offsetof(JitFrame, lp) || !(jit_frame = jit_calloc(offsetof(JitFrame, lp)
+ sizeof(*jit_frame->lp) + sizeof(*jit_frame->lp)
* (max_locals + max_stacks)))) { * (max_locals + max_stacks)))) {
os_printf("allocate jit frame failed\n"); LOG_ERROR("allocate jit frame failed\n");
return NULL; return NULL;
} }

View File

@ -3300,7 +3300,7 @@ orcjit_thread_callback(void *arg)
/* Compile fast jit funcitons of this group */ /* Compile fast jit funcitons of this group */
for (i = group_idx; i < func_count; i += group_stride) { for (i = group_idx; i < func_count; i += group_stride) {
if (!jit_compiler_compile(module, i + module->import_function_count)) { if (!jit_compiler_compile(module, i + module->import_function_count)) {
os_printf("failed to compile fast jit function %u\n", i); LOG_ERROR("failed to compile fast jit function %u\n", i);
break; break;
} }
@ -3327,7 +3327,7 @@ orcjit_thread_callback(void *arg)
if (!jit_compiler_set_call_to_fast_jit( if (!jit_compiler_set_call_to_fast_jit(
module, module,
i + j * group_stride + module->import_function_count)) { i + j * group_stride + module->import_function_count)) {
os_printf( LOG_ERROR(
"failed to compile call_to_fast_jit for func %u\n", "failed to compile call_to_fast_jit for func %u\n",
i + j * group_stride + module->import_function_count); i + j * group_stride + module->import_function_count);
module->orcjit_stop_compiling = true; module->orcjit_stop_compiling = true;
@ -3377,7 +3377,7 @@ orcjit_thread_callback(void *arg)
LLVMOrcLLLazyJITLookup(comp_ctx->orc_jit, &func_addr, func_name); LLVMOrcLLLazyJITLookup(comp_ctx->orc_jit, &func_addr, func_name);
if (error != LLVMErrorSuccess) { if (error != LLVMErrorSuccess) {
char *err_msg = LLVMGetErrorMessage(error); char *err_msg = LLVMGetErrorMessage(error);
os_printf("failed to compile llvm jit function %u: %s", i, err_msg); LOG_ERROR("failed to compile llvm jit function %u: %s", i, err_msg);
LLVMDisposeErrorMessage(err_msg); LLVMDisposeErrorMessage(err_msg);
break; break;
} }
@ -3398,7 +3398,7 @@ orcjit_thread_callback(void *arg)
func_name); func_name);
if (error != LLVMErrorSuccess) { if (error != LLVMErrorSuccess) {
char *err_msg = LLVMGetErrorMessage(error); char *err_msg = LLVMGetErrorMessage(error);
os_printf("failed to compile llvm jit function %u: %s", i, LOG_ERROR("failed to compile llvm jit function %u: %s", i,
err_msg); err_msg);
LLVMDisposeErrorMessage(err_msg); LLVMDisposeErrorMessage(err_msg);
/* Ignore current llvm jit func, as its func ptr is /* Ignore current llvm jit func, as its func ptr is

View File

@ -2024,7 +2024,7 @@ orcjit_thread_callback(void *arg)
/* Compile fast jit funcitons of this group */ /* Compile fast jit funcitons of this group */
for (i = group_idx; i < func_count; i += group_stride) { for (i = group_idx; i < func_count; i += group_stride) {
if (!jit_compiler_compile(module, i + module->import_function_count)) { if (!jit_compiler_compile(module, i + module->import_function_count)) {
os_printf("failed to compile fast jit function %u\n", i); LOG_ERROR("failed to compile fast jit function %u\n", i);
break; break;
} }
@ -2051,7 +2051,7 @@ orcjit_thread_callback(void *arg)
if (!jit_compiler_set_call_to_fast_jit( if (!jit_compiler_set_call_to_fast_jit(
module, module,
i + j * group_stride + module->import_function_count)) { i + j * group_stride + module->import_function_count)) {
os_printf( LOG_ERROR(
"failed to compile call_to_fast_jit for func %u\n", "failed to compile call_to_fast_jit for func %u\n",
i + j * group_stride + module->import_function_count); i + j * group_stride + module->import_function_count);
module->orcjit_stop_compiling = true; module->orcjit_stop_compiling = true;
@ -2101,7 +2101,7 @@ orcjit_thread_callback(void *arg)
LLVMOrcLLLazyJITLookup(comp_ctx->orc_jit, &func_addr, func_name); LLVMOrcLLLazyJITLookup(comp_ctx->orc_jit, &func_addr, func_name);
if (error != LLVMErrorSuccess) { if (error != LLVMErrorSuccess) {
char *err_msg = LLVMGetErrorMessage(error); char *err_msg = LLVMGetErrorMessage(error);
os_printf("failed to compile llvm jit function %u: %s", i, err_msg); LOG_ERROR("failed to compile llvm jit function %u: %s", i, err_msg);
LLVMDisposeErrorMessage(err_msg); LLVMDisposeErrorMessage(err_msg);
break; break;
} }
@ -2122,7 +2122,7 @@ orcjit_thread_callback(void *arg)
func_name); func_name);
if (error != LLVMErrorSuccess) { if (error != LLVMErrorSuccess) {
char *err_msg = LLVMGetErrorMessage(error); char *err_msg = LLVMGetErrorMessage(error);
os_printf("failed to compile llvm jit function %u: %s", i, LOG_ERROR("failed to compile llvm jit function %u: %s", i,
err_msg); err_msg);
LLVMDisposeErrorMessage(err_msg); LLVMDisposeErrorMessage(err_msg);
/* Ignore current llvm jit func, as its func ptr is /* Ignore current llvm jit func, as its func ptr is

View File

@ -269,14 +269,14 @@ getentropy_wrapper(wasm_exec_env_t exec_env, void *buffer, uint32 length)
static int static int
setjmp_wrapper(wasm_exec_env_t exec_env, void *jmp_buf) setjmp_wrapper(wasm_exec_env_t exec_env, void *jmp_buf)
{ {
os_printf("setjmp() called\n"); LOG_DEBUG("setjmp() called\n");
return 0; return 0;
} }
static void static void
longjmp_wrapper(wasm_exec_env_t exec_env, void *jmp_buf, int val) longjmp_wrapper(wasm_exec_env_t exec_env, void *jmp_buf, int val)
{ {
os_printf("longjmp() called\n"); LOG_DEBUG("longjmp() called\n");
} }
#if !defined(BH_PLATFORM_LINUX_SGX) #if !defined(BH_PLATFORM_LINUX_SGX)

View File

@ -199,7 +199,7 @@ unlink_hmu(gc_heap_t *heap, hmu_t *hmu)
} }
if (!node) { if (!node) {
os_printf("[GC_ERROR]couldn't find the node in the normal list\n"); LOG_ERROR("[GC_ERROR]couldn't find the node in the normal list\n");
} }
} }
else { else {
@ -504,7 +504,7 @@ gc_alloc_vo_internal(void *vheap, gc_size_t size, const char *file, int line)
#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 #if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (heap->is_heap_corrupted) { if (heap->is_heap_corrupted) {
os_printf("[GC_ERROR]Heap is corrupted, allocate memory failed.\n"); LOG_ERROR("[GC_ERROR]Heap is corrupted, allocate memory failed.\n");
return NULL; return NULL;
} }
#endif #endif
@ -566,7 +566,7 @@ gc_realloc_vo_internal(void *vheap, void *ptr, gc_size_t size, const char *file,
#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 #if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (heap->is_heap_corrupted) { if (heap->is_heap_corrupted) {
os_printf("[GC_ERROR]Heap is corrupted, allocate memory failed.\n"); LOG_ERROR("[GC_ERROR]Heap is corrupted, allocate memory failed.\n");
return NULL; return NULL;
} }
#endif #endif
@ -693,7 +693,7 @@ gc_free_vo_internal(void *vheap, gc_object_t obj, const char *file, int line)
#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 #if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (heap->is_heap_corrupted) { if (heap->is_heap_corrupted) {
os_printf("[GC_ERROR]Heap is corrupted, free memory failed.\n"); LOG_ERROR("[GC_ERROR]Heap is corrupted, free memory failed.\n");
return GC_ERROR; return GC_ERROR;
} }
#endif #endif
@ -815,7 +815,7 @@ gci_dump(gc_heap_t *heap)
#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 #if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (size == 0 || size > (uint32)((uint8 *)end - (uint8 *)cur)) { if (size == 0 || size > (uint32)((uint8 *)end - (uint8 *)cur)) {
os_printf("[GC_ERROR]Heap is corrupted, heap dump failed.\n"); LOG_ERROR("[GC_ERROR]Heap is corrupted, heap dump failed.\n");
heap->is_heap_corrupted = true; heap->is_heap_corrupted = true;
return; return;
} }
@ -838,7 +838,7 @@ gci_dump(gc_heap_t *heap)
#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 #if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (cur != end) { if (cur != end) {
os_printf("[GC_ERROR]Heap is corrupted, heap dump failed.\n"); LOG_ERROR("[GC_ERROR]Heap is corrupted, heap dump failed.\n");
heap->is_heap_corrupted = true; heap->is_heap_corrupted = true;
} }
#else #else

View File

@ -80,7 +80,7 @@ hmu_verify(void *vheap, hmu_t *hmu)
} }
if (!is_padding_ok) { if (!is_padding_ok) {
os_printf("Invalid padding for object created at %s:%d\n", LOG_ERROR("Invalid padding for object created at %s:%d\n",
(prefix->file_name ? prefix->file_name : ""), (prefix->file_name ? prefix->file_name : ""),
prefix->line_no); prefix->line_no);
#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 #if BH_ENABLE_GC_CORRUPTION_CHECK != 0

View File

@ -15,7 +15,7 @@ gc_init_internal(gc_heap_t *heap, char *base_addr, gc_size_t heap_max_size)
ret = os_mutex_init(&heap->lock); ret = os_mutex_init(&heap->lock);
if (ret != BHT_OK) { if (ret != BHT_OK) {
os_printf("[GC_ERROR]failed to init lock\n"); LOG_ERROR("[GC_ERROR]failed to init lock\n");
return NULL; return NULL;
} }
@ -61,7 +61,7 @@ gc_init_with_pool(char *buf, gc_size_t buf_size)
gc_size_t heap_max_size; gc_size_t heap_max_size;
if (buf_size < APP_HEAP_SIZE_MIN) { if (buf_size < APP_HEAP_SIZE_MIN) {
os_printf("[GC_ERROR]heap init buf size (%" PRIu32 ") < %" PRIu32 "\n", LOG_ERROR("[GC_ERROR]heap init buf size (%" PRIu32 ") < %" PRIu32 "\n",
buf_size, (uint32)APP_HEAP_SIZE_MIN); buf_size, (uint32)APP_HEAP_SIZE_MIN);
return NULL; return NULL;
} }
@ -90,23 +90,23 @@ gc_init_with_struct_and_pool(char *struct_buf, gc_size_t struct_buf_size,
gc_size_t heap_max_size; gc_size_t heap_max_size;
if ((((uintptr_t)struct_buf) & 7) != 0) { if ((((uintptr_t)struct_buf) & 7) != 0) {
os_printf("[GC_ERROR]heap init struct buf not 8-byte aligned\n"); LOG_ERROR("[GC_ERROR]heap init struct buf not 8-byte aligned\n");
return NULL; return NULL;
} }
if (struct_buf_size < sizeof(gc_handle_t)) { if (struct_buf_size < sizeof(gc_handle_t)) {
os_printf("[GC_ERROR]heap init struct buf size (%" PRIu32 ") < %zu\n", LOG_ERROR("[GC_ERROR]heap init struct buf size (%" PRIu32 ") < %zu\n",
struct_buf_size, sizeof(gc_handle_t)); struct_buf_size, sizeof(gc_handle_t));
return NULL; return NULL;
} }
if ((((uintptr_t)pool_buf) & 7) != 0) { if ((((uintptr_t)pool_buf) & 7) != 0) {
os_printf("[GC_ERROR]heap init pool buf not 8-byte aligned\n"); LOG_ERROR("[GC_ERROR]heap init pool buf not 8-byte aligned\n");
return NULL; return NULL;
} }
if (pool_buf_size < APP_HEAP_SIZE_MIN) { if (pool_buf_size < APP_HEAP_SIZE_MIN) {
os_printf("[GC_ERROR]heap init buf size (%" PRIu32 ") < %u\n", LOG_ERROR("[GC_ERROR]heap init buf size (%" PRIu32 ") < %u\n",
pool_buf_size, APP_HEAP_SIZE_MIN); pool_buf_size, APP_HEAP_SIZE_MIN);
return NULL; return NULL;
} }
@ -138,7 +138,7 @@ gc_destroy_with_pool(gc_handle_t handle)
!heap->is_heap_corrupted && !heap->is_heap_corrupted &&
#endif #endif
(hmu_t *)((char *)cur + hmu_get_size(cur)) != end) { (hmu_t *)((char *)cur + hmu_get_size(cur)) != end) {
os_printf("Memory leak detected:\n"); LOG_WARNING("Memory leak detected:\n");
gci_dump(heap); gci_dump(heap);
ret = GC_ERROR; ret = GC_ERROR;
} }
@ -175,14 +175,14 @@ gc_migrate(gc_handle_t handle, char *pool_buf_new, gc_size_t pool_buf_size)
gc_size_t heap_max_size, size; gc_size_t heap_max_size, size;
if ((((uintptr_t)pool_buf_new) & 7) != 0) { if ((((uintptr_t)pool_buf_new) & 7) != 0) {
os_printf("[GC_ERROR]heap migrate pool buf not 8-byte aligned\n"); LOG_ERROR("[GC_ERROR]heap migrate pool buf not 8-byte aligned\n");
return GC_ERROR; return GC_ERROR;
} }
heap_max_size = (uint32)(pool_buf_end - base_addr_new) & (uint32)~7; heap_max_size = (uint32)(pool_buf_end - base_addr_new) & (uint32)~7;
if (pool_buf_end < base_addr_new || heap_max_size < heap->current_size) { if (pool_buf_end < base_addr_new || heap_max_size < heap->current_size) {
os_printf("[GC_ERROR]heap migrate invlaid pool buf size\n"); LOG_ERROR("[GC_ERROR]heap migrate invlaid pool buf size\n");
return GC_ERROR; return GC_ERROR;
} }
@ -191,7 +191,7 @@ gc_migrate(gc_handle_t handle, char *pool_buf_new, gc_size_t pool_buf_size)
#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 #if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (heap->is_heap_corrupted) { if (heap->is_heap_corrupted) {
os_printf("[GC_ERROR]Heap is corrupted, heap migrate failed.\n"); LOG_ERROR("[GC_ERROR]Heap is corrupted, heap migrate failed.\n");
return GC_ERROR; return GC_ERROR;
} }
#endif #endif
@ -218,7 +218,7 @@ gc_migrate(gc_handle_t handle, char *pool_buf_new, gc_size_t pool_buf_size)
#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 #if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (size <= 0 || size > (uint32)((uint8 *)end - (uint8 *)cur)) { if (size <= 0 || size > (uint32)((uint8 *)end - (uint8 *)cur)) {
os_printf("[GC_ERROR]Heap is corrupted, heap migrate failed.\n"); LOG_ERROR("[GC_ERROR]Heap is corrupted, heap migrate failed.\n");
heap->is_heap_corrupted = true; heap->is_heap_corrupted = true;
return GC_ERROR; return GC_ERROR;
} }
@ -247,7 +247,7 @@ gc_migrate(gc_handle_t handle, char *pool_buf_new, gc_size_t pool_buf_size)
#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 #if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (cur != end) { if (cur != end) {
os_printf("[GC_ERROR]Heap is corrupted, heap migrate failed.\n"); LOG_ERROR("[GC_ERROR]Heap is corrupted, heap migrate failed.\n");
heap->is_heap_corrupted = true; heap->is_heap_corrupted = true;
return GC_ERROR; return GC_ERROR;
} }

View File

@ -18,7 +18,7 @@ bh_assert_internal(int64 v, const char *file_name, int line_number,
if (!expr_string) if (!expr_string)
expr_string = "NULL EXPR_STRING"; expr_string = "NULL EXPR_STRING";
os_printf("\nASSERTION FAILED: %s, at file %s, line %d\n", expr_string, LOG_ERROR("\nASSERTION FAILED: %s, at file %s, line %d\n", expr_string,
file_name, line_number); file_name, line_number);
abort(); abort();