gdbstub: ctrl-c command support

master
vhaudiquet 1 year ago
parent 6b9e5c766b
commit 629fa5fc56
  1. 56
      src/gdbstub/gdbstub.c

@ -24,6 +24,7 @@ socket_t gdbstub_server_socket;
socket_t gdb_socket;
void gdbstub_thread_gdb();
static void gdbstub_handle_ctrlc();
/*
* Receive a packet from client gdb
@ -35,9 +36,27 @@ static void gdbstub_recv_packet(char* packet, ssize_t* size)
recv(gdb_socket, &data, 1, 0);
// Start of packet symbol is '$'
// Skip data that is not packet (should only be ACK '+')
// Skip data that is not packet
if(data != '$')
return gdbstub_recv_packet(packet, size);
{
switch(data)
{
case '+':
// '+' : ACK
// We ignore ACK, so read next
return gdbstub_recv_packet(packet, size);
break;
case 0x3:
// 0x3 : COMMAND CTRL-C (interrupt execution)
gdbstub_handle_ctrlc();
return gdbstub_recv_packet(packet, size);
break;
default:
// Ignore unknown data
return gdbstub_recv_packet(packet, size);
break;
}
}
// Receive packet until end of packet '#' symbol
size_t i = 0;
@ -153,6 +172,7 @@ void gdbstub_thread_gdb()
// Analyse packet to respond correctly
if(packet[0] == '?')
{
// Halt Reason : Signal 05 (SIGTRAP)
char* resp = "S05";
gdbstub_send_packet(resp, 3);
}
@ -198,6 +218,38 @@ void gdbstub_thread_gdb()
gdbstub_send_packet("OK", 2);
}
else if(packet[0] == 's')
{
// s : single-step
// Send back halt reason
// Halt Reason : Signal 05 (SIGTRAP)
char* resp = "S05";
gdbstub_send_packet(resp, 3);
}
else if(packet[0] == 'c')
{
// c : continue until something happens
// Send an ACK
send(gdb_socket, "+", 1, 0);
// Continue simulation
}
else gdbstub_send_unsupported();
}
}
/*
* Handles the GDB CTRL+C (^C) command, that
* should interrupt the simulation
*/
static void gdbstub_handle_ctrlc()
{
// Halt the simulation
// Send back halt signal to gdb
// Halt Reason : Signal 05 (SIGTRAP)
char* resp = "S05";
gdbstub_send_packet(resp, 3);
}

Loading…
Cancel
Save