Skip to content

Commit ebcbe0b

Browse files
authored
wasm_application.c: Do not start debug instance automatically (#1407)
Leave the control from wasm_application_execute_main to host embedders, eg. product-mini.
1 parent 1dcc59f commit ebcbe0b

3 files changed

Lines changed: 40 additions & 11 deletions

File tree

core/iwasm/common/wasm_application.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,6 @@ execute_main(WASMModuleInstanceCommon *module_inst, int32 argc, char *argv[])
107107
the actual main function. Directly calling main function
108108
may cause exception thrown. */
109109
if ((func = wasm_runtime_lookup_wasi_start_function(module_inst))) {
110-
#if WASM_ENABLE_DEBUG_INTERP != 0
111-
wasm_runtime_start_debug_instance(exec_env);
112-
#endif
113110
return wasm_runtime_call_wasm(exec_env, func, 0, NULL);
114111
}
115112
#endif /* end of WASM_ENABLE_LIBC_WASI */
@@ -191,10 +188,6 @@ execute_main(WASMModuleInstanceCommon *module_inst, int32 argc, char *argv[])
191188
(uint32)wasm_runtime_addr_native_to_app(module_inst, argv_offsets);
192189
}
193190

194-
#if WASM_ENABLE_DEBUG_INTERP != 0
195-
wasm_runtime_start_debug_instance(exec_env);
196-
#endif
197-
198191
ret = wasm_runtime_call_wasm(exec_env, func, argc1, argv1);
199192
if (ret && func_type->result_count > 0 && argc > 0 && argv)
200193
/* copy the return value */
@@ -618,10 +611,6 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name,
618611
goto fail;
619612
}
620613

621-
#if WASM_ENABLE_DEBUG_INTERP != 0
622-
wasm_runtime_start_debug_instance(exec_env);
623-
#endif
624-
625614
if (!wasm_runtime_call_wasm(exec_env, target_func, argc1, argv1)) {
626615
goto fail;
627616
}

product-mini/platforms/posix/main.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,23 @@ main(int argc, char *argv[])
568568
goto fail3;
569569
}
570570

571+
#if WASM_ENABLE_DEBUG_INTERP != 0
572+
if (ip_addr != NULL) {
573+
wasm_exec_env_t exec_env =
574+
wasm_runtime_get_exec_env_singleton(wasm_module_inst);
575+
uint32_t debug_port;
576+
if (exec_env == NULL) {
577+
printf("%s\n", wasm_runtime_get_exception(wasm_module_inst));
578+
goto fail4;
579+
}
580+
debug_port = wasm_runtime_start_debug_instance(exec_env);
581+
if (debug_port == 0) {
582+
printf("Failed to start debug instance\n");
583+
goto fail4;
584+
}
585+
}
586+
#endif
587+
571588
if (is_repl_mode)
572589
app_instance_repl(wasm_module_inst);
573590
else if (func_name)
@@ -577,6 +594,9 @@ main(int argc, char *argv[])
577594

578595
ret = 0;
579596

597+
#if WASM_ENABLE_DEBUG_INTERP != 0
598+
fail4:
599+
#endif
580600
/* destroy the module instance */
581601
wasm_runtime_deinstantiate(wasm_module_inst);
582602

product-mini/platforms/windows/main.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,23 @@ main(int argc, char *argv[])
435435
goto fail3;
436436
}
437437

438+
#if WASM_ENABLE_DEBUG_INTERP != 0
439+
if (ip_addr != NULL) {
440+
wasm_exec_env_t exec_env =
441+
wasm_runtime_get_exec_env_singleton(wasm_module_inst);
442+
uint32_t debug_port;
443+
if (exec_env == NULL) {
444+
printf("%s\n", wasm_runtime_get_exception(wasm_module_inst));
445+
goto fail4;
446+
}
447+
debug_port = wasm_runtime_start_debug_instance(exec_env);
448+
if (debug_port == 0) {
449+
printf("Failed to start debug instance\n");
450+
goto fail4;
451+
}
452+
}
453+
#endif
454+
438455
if (is_repl_mode)
439456
app_instance_repl(wasm_module_inst);
440457
else if (func_name)
@@ -444,6 +461,9 @@ main(int argc, char *argv[])
444461

445462
ret = 0;
446463

464+
#if WASM_ENABLE_DEBUG_INTERP != 0
465+
fail4:
466+
#endif
447467
/* destroy the module instance */
448468
wasm_runtime_deinstantiate(wasm_module_inst);
449469

0 commit comments

Comments
 (0)