Fix source debugging issues (#776)

- fix data race issue between debug control thread and main thread
- fix possible memory leaks in breakpoints list
- fix memory uninitialized issues
- remove unused data structures
- add more checks when handling packet and args
- fix mini-loader issues
- fix config_common.cmake fast interp prompt issue
This commit is contained in:
Xu Jun
2021-10-09 15:56:58 +08:00
committed by GitHub
parent 52b6c73d9c
commit 0be1f687af
8 changed files with 205 additions and 97 deletions

View File

@ -66,6 +66,8 @@ wasm_launch_gdbserver(char *host, int port)
return NULL;
}
memset(server, 0, sizeof(WASMGDBServer));
listen_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (listen_fd < 0) {
LOG_ERROR("wasm gdb server error: socket() failed");
@ -114,7 +116,7 @@ wasm_launch_gdbserver(char *host, int port)
return server;
fail:
if (listen_fd > 0) {
if (listen_fd >= 0) {
shutdown(listen_fd, SHUT_RDWR);
close(listen_fd);
}
@ -143,26 +145,41 @@ handler_packet(WASMGDBServer *server, char request, char *payload)
packet_handler_table[(int)request].handler(server, payload);
}
/**
* The packet layout is:
* '$' + payload + '#' + checksum(2bytes)
* ^
* packetend_ptr
*/
static void
process_packet(WASMGDBServer *server)
{
uint8_t *inbuf = server->pkt.buf;
int inbuf_size = server->pkt.end;
int inbuf_size = server->pkt.size;
uint8_t *packetend_ptr = (uint8_t *)memchr(inbuf, '#', inbuf_size);
int packetend = packetend_ptr - inbuf;
bh_assert('$' == inbuf[0]);
char request = inbuf[1];
char *payload = (char *)&inbuf[2];
char *payload = NULL;
uint8_t checksum = 0;
if (packetend == 1) {
LOG_VERBOSE("receive empty request, ignore it\n");
return;
}
bh_assert('$' == inbuf[0]);
inbuf[packetend] = '\0';
uint8_t checksum = 0;
for (int i = 1; i < packetend; i++)
checksum += inbuf[i];
bh_assert(checksum
== (hex(inbuf[packetend + 1]) << 4 | hex(inbuf[packetend + 2])));
payload = (char *)&inbuf[2];
LOG_VERBOSE("receive request:%c %s\n", request, payload);
handler_packet(server, request, payload);
inbuf_erase_head(server, packetend + 3);
}