@@ -79,10 +79,12 @@ control_thread_routine(void *arg)
7979 control_thread -> debug_instance = debug_inst ;
8080 bh_strcpy_s (control_thread -> ip_addr , sizeof (control_thread -> ip_addr ),
8181 g_debug_engine -> ip_addr );
82- control_thread -> port =
83- (g_debug_engine -> process_base_port == 0 )
84- ? 0
85- : g_debug_engine -> process_base_port + debug_inst -> id - 1 ;
82+ if (control_thread -> port == -1 ) {
83+ control_thread -> port =
84+ (g_debug_engine -> process_base_port == 0 )
85+ ? 0
86+ : g_debug_engine -> process_base_port + debug_inst -> id - 1 ;
87+ }
8688
8789 LOG_WARNING ("control thread of debug object %p start\n" , debug_inst );
8890
@@ -91,6 +93,7 @@ control_thread_routine(void *arg)
9193
9294 if (!control_thread -> server ) {
9395 LOG_ERROR ("Failed to create debug server\n" );
96+ control_thread -> port = 0 ;
9497 os_cond_signal (& debug_inst -> wait_cond );
9598 os_mutex_unlock (& debug_inst -> wait_lock );
9699 return NULL ;
@@ -176,7 +179,7 @@ control_thread_routine(void *arg)
176179}
177180
178181static WASMDebugControlThread *
179- wasm_debug_control_thread_create (WASMDebugInstance * debug_instance )
182+ wasm_debug_control_thread_create (WASMDebugInstance * debug_instance , int32 port )
180183{
181184 WASMDebugControlThread * control_thread ;
182185
@@ -186,6 +189,7 @@ wasm_debug_control_thread_create(WASMDebugInstance *debug_instance)
186189 return NULL ;
187190 }
188191 memset (control_thread , 0 , sizeof (WASMDebugControlThread ));
192+ control_thread -> port = port ;
189193
190194 if (os_mutex_init (& control_thread -> wait_lock ) != 0 )
191195 goto fail ;
@@ -309,7 +313,7 @@ wasm_debug_engine_init(char *ip_addr, int32 process_port)
309313/* A debug Instance is a debug "process" in gdb remote protocol
310314 and bound to a runtime cluster */
311315WASMDebugInstance *
312- wasm_debug_instance_create (WASMCluster * cluster )
316+ wasm_debug_instance_create (WASMCluster * cluster , int32 port )
313317{
314318 WASMDebugInstance * instance ;
315319 WASMExecEnv * exec_env = NULL ;
@@ -359,7 +363,7 @@ wasm_debug_instance_create(WASMCluster *cluster)
359363 }
360364 instance -> exec_mem_info .current_pos = instance -> exec_mem_info .start_offset ;
361365
362- if (!wasm_debug_control_thread_create (instance )) {
366+ if (!wasm_debug_control_thread_create (instance , port )) {
363367 LOG_ERROR ("WASM Debug Engine error: failed to create control thread" );
364368 goto fail3 ;
365369 }
0 commit comments