Skip to content

send an empty/error reply from server #4362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions core/iwasm/libraries/debug-engine/handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,19 @@ process_wasm_global(WASMGDBServer *server, char *args)
os_mutex_unlock(&tmpbuf_lock);
}

/* TODO: let server send an empty/error reply.
Original issue: 4265
Not tested yet, but it should work.
*/
static void
send_reply(WASMGDBServer *server, const char *err)
{
if (!err || !*err)
write_packet(server, "");
else
write_packet(server, err);
}

void
handle_general_query(WASMGDBServer *server, char *payload)
{
Expand Down Expand Up @@ -214,6 +227,7 @@ handle_general_query(WASMGDBServer *server, char *payload)

if (!args) {
LOG_ERROR("payload parse error during handle_general_query");
send_reply(server, "");
return;
}

Expand Down Expand Up @@ -384,7 +398,7 @@ send_thread_stop_status(WASMGDBServer *server, uint32 status, korp_tid tid)
if (status == 0) {
os_mutex_lock(&tmpbuf_lock);
(void)snprintf(tmpbuf, MAX_PACKET_SIZE, "W%02" PRIx32, status);
write_packet(server, tmpbuf);
send_reply(server, tmpbuf);
os_mutex_unlock(&tmpbuf_lock);
return;
}
Expand All @@ -403,13 +417,15 @@ send_thread_stop_status(WASMGDBServer *server, uint32 status, korp_tid tid)
"T%02" PRIx32 "thread:%" PRIx64 ";name:%s;", gdb_status,
(uint64)(uintptr_t)tid, "nobody");
if (len < 0 || len >= MAX_PACKET_SIZE) {
send_reply(server, "E01");
os_mutex_unlock(&tmpbuf_lock);
return;
}

if (tids_count > 0) {
int n = snprintf(tmpbuf + len, MAX_PACKET_SIZE - len, "threads:");
if (n < 0 || n >= MAX_PACKET_SIZE - len) {
send_reply(server, "E01");
os_mutex_unlock(&tmpbuf_lock);
return;
}
Expand All @@ -426,6 +442,7 @@ send_thread_stop_status(WASMGDBServer *server, uint32 status, korp_tid tid)
}

if (n < 0 || n >= MAX_PACKET_SIZE - len) {
send_reply(server, "E01");
os_mutex_unlock(&tmpbuf_lock);
return;
}
Expand All @@ -452,6 +469,7 @@ send_thread_stop_status(WASMGDBServer *server, uint32 status, korp_tid tid)
"thread-pcs:%" PRIx64 ";00:%s;reason:%s;description:", pc,
pc_string, "exception");
if (n < 0 || n >= MAX_PACKET_SIZE - len) {
send_reply(server, "E01");
os_mutex_unlock(&tmpbuf_lock);
return;
}
Expand All @@ -462,6 +480,7 @@ send_thread_stop_status(WASMGDBServer *server, uint32 status, korp_tid tid)
n = snprintf(tmpbuf + len, MAX_PACKET_SIZE - len, "%02x",
exception[i]);
if (n < 0 || n >= MAX_PACKET_SIZE - len) {
send_reply(server, "E01");
os_mutex_unlock(&tmpbuf_lock);
return;
}
Expand Down Expand Up @@ -592,7 +611,7 @@ handle_get_register(WASMGDBServer *server, char *payload)
int32 i = strtol(payload, NULL, 16);

if (i != 0) {
write_packet(server, "E01");
send_reply(server, "E01");
return;
}
regdata = wasm_debug_instance_get_pc(
Expand Down Expand Up @@ -748,7 +767,7 @@ handle_add_break(WASMGDBServer *server, char *payload)
if ((arg_c = sscanf(payload, "%zx,%" SCNx64 ",%zx", &type, &addr, &length))
!= 3) {
LOG_ERROR("Unsupported number of add break arguments %d", arg_c);
write_packet(server, "");
send_reply(server, "");
return;
}

Expand Down Expand Up @@ -783,7 +802,7 @@ handle_remove_break(WASMGDBServer *server, char *payload)
if ((arg_c = sscanf(payload, "%zx,%" SCNx64 ",%zx", &type, &addr, &length))
!= 3) {
LOG_ERROR("Unsupported number of remove break arguments %d", arg_c);
write_packet(server, "");
send_reply(server, "");
return;
}

Expand Down Expand Up @@ -835,6 +854,7 @@ handle_malloc(WASMGDBServer *server, char *payload)
}
else {
LOG_ERROR("Payload parse error during handle malloc");
send_reply(server, "");
return;
}

Expand Down
Loading