Skip to content

Commit d5a7f01

Browse files
yviansulum1n0us
authored andcommitted
send an empty/error reply from server (bytecodealliance#4362)
Signed-off-by: Su Yihan <yihan.su@intel.com>
1 parent 26bde92 commit d5a7f01

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

core/iwasm/libraries/debug-engine/handler.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,19 @@ process_wasm_global(WASMGDBServer *server, char *args)
175175
os_mutex_unlock(&tmpbuf_lock);
176176
}
177177

178+
/* TODO: let server send an empty/error reply.
179+
Original issue: 4265
180+
Not tested yet, but it should work.
181+
*/
182+
static void
183+
send_reply(WASMGDBServer *server, const char *err)
184+
{
185+
if (!err || !*err)
186+
write_packet(server, "");
187+
else
188+
write_packet(server, err);
189+
}
190+
178191
void
179192
handle_general_query(WASMGDBServer *server, char *payload)
180193
{
@@ -214,6 +227,7 @@ handle_general_query(WASMGDBServer *server, char *payload)
214227

215228
if (!args) {
216229
LOG_ERROR("payload parse error during handle_general_query");
230+
send_reply(server, "");
217231
return;
218232
}
219233

@@ -384,7 +398,7 @@ send_thread_stop_status(WASMGDBServer *server, uint32 status, korp_tid tid)
384398
if (status == 0) {
385399
os_mutex_lock(&tmpbuf_lock);
386400
(void)snprintf(tmpbuf, MAX_PACKET_SIZE, "W%02" PRIx32, status);
387-
write_packet(server, tmpbuf);
401+
send_reply(server, tmpbuf);
388402
os_mutex_unlock(&tmpbuf_lock);
389403
return;
390404
}
@@ -403,13 +417,15 @@ send_thread_stop_status(WASMGDBServer *server, uint32 status, korp_tid tid)
403417
"T%02" PRIx32 "thread:%" PRIx64 ";name:%s;", gdb_status,
404418
(uint64)(uintptr_t)tid, "nobody");
405419
if (len < 0 || len >= MAX_PACKET_SIZE) {
420+
send_reply(server, "E01");
406421
os_mutex_unlock(&tmpbuf_lock);
407422
return;
408423
}
409424

410425
if (tids_count > 0) {
411426
int n = snprintf(tmpbuf + len, MAX_PACKET_SIZE - len, "threads:");
412427
if (n < 0 || n >= MAX_PACKET_SIZE - len) {
428+
send_reply(server, "E01");
413429
os_mutex_unlock(&tmpbuf_lock);
414430
return;
415431
}
@@ -426,6 +442,7 @@ send_thread_stop_status(WASMGDBServer *server, uint32 status, korp_tid tid)
426442
}
427443

428444
if (n < 0 || n >= MAX_PACKET_SIZE - len) {
445+
send_reply(server, "E01");
429446
os_mutex_unlock(&tmpbuf_lock);
430447
return;
431448
}
@@ -452,6 +469,7 @@ send_thread_stop_status(WASMGDBServer *server, uint32 status, korp_tid tid)
452469
"thread-pcs:%" PRIx64 ";00:%s;reason:%s;description:", pc,
453470
pc_string, "exception");
454471
if (n < 0 || n >= MAX_PACKET_SIZE - len) {
472+
send_reply(server, "E01");
455473
os_mutex_unlock(&tmpbuf_lock);
456474
return;
457475
}
@@ -462,6 +480,7 @@ send_thread_stop_status(WASMGDBServer *server, uint32 status, korp_tid tid)
462480
n = snprintf(tmpbuf + len, MAX_PACKET_SIZE - len, "%02x",
463481
exception[i]);
464482
if (n < 0 || n >= MAX_PACKET_SIZE - len) {
483+
send_reply(server, "E01");
465484
os_mutex_unlock(&tmpbuf_lock);
466485
return;
467486
}
@@ -592,7 +611,7 @@ handle_get_register(WASMGDBServer *server, char *payload)
592611
int32 i = strtol(payload, NULL, 16);
593612

594613
if (i != 0) {
595-
write_packet(server, "E01");
614+
send_reply(server, "E01");
596615
return;
597616
}
598617
regdata = wasm_debug_instance_get_pc(
@@ -748,7 +767,7 @@ handle_add_break(WASMGDBServer *server, char *payload)
748767
if ((arg_c = sscanf(payload, "%zx,%" SCNx64 ",%zx", &type, &addr, &length))
749768
!= 3) {
750769
LOG_ERROR("Unsupported number of add break arguments %d", arg_c);
751-
write_packet(server, "");
770+
send_reply(server, "");
752771
return;
753772
}
754773

@@ -783,7 +802,7 @@ handle_remove_break(WASMGDBServer *server, char *payload)
783802
if ((arg_c = sscanf(payload, "%zx,%" SCNx64 ",%zx", &type, &addr, &length))
784803
!= 3) {
785804
LOG_ERROR("Unsupported number of remove break arguments %d", arg_c);
786-
write_packet(server, "");
805+
send_reply(server, "");
787806
return;
788807
}
789808

@@ -835,6 +854,7 @@ handle_malloc(WASMGDBServer *server, char *payload)
835854
}
836855
else {
837856
LOG_ERROR("Payload parse error during handle malloc");
857+
send_reply(server, "");
838858
return;
839859
}
840860

0 commit comments

Comments
 (0)