fix unused var / naming

This commit is contained in:
mean 2022-03-19 11:06:28 +01:00 committed by Rachel Mant
parent b82ee6bc90
commit 8b52bbd9a9
2 changed files with 115 additions and 72 deletions

View File

@ -48,6 +48,14 @@ enum gdb_signal {
#define ERROR_IF_NO_TARGET() \ #define ERROR_IF_NO_TARGET() \
if(!cur_target) { gdb_putpacketz("EFF"); break; } if(!cur_target) { gdb_putpacketz("EFF"); break; }
typedef struct
{
const char *cmd_prefix;
void (*func)(const char *packet,int len);
}cmd_executer;
static char pbuf[BUF_SIZE+1]; static char pbuf[BUF_SIZE+1];
static target *cur_target; static target *cur_target;
@ -329,43 +337,29 @@ int gdb_main_loop(struct target_controller *tc, bool in_syscall)
} }
} }
} }
bool exec_command(char *packet, int len, const cmd_executer *exec)
static void
handle_q_string_reply(const char *str, const char *param)
{ {
unsigned long addr, len; while(exec->cmd_prefix) {
int l=strlen(exec->cmd_prefix);
if (sscanf(param, "%08lx,%08lx", &addr, &len) != 2) { if(!strncmp(packet,exec->cmd_prefix,l)) {
gdb_putpacketz("E01"); exec->func(packet+l,len-l);
return; return true;
} }
if (addr < strlen (str)) { exec++;
char reply[len+2]; }
reply[0] = 'm'; return false;
strncpy (reply + 1, &str[addr], len);
if(len > strlen(&str[addr]))
len = strlen(&str[addr]);
gdb_putpacket(reply, len + 1);
} else if (addr == strlen (str)) {
gdb_putpacketz("l");
} else
gdb_putpacketz("E01");
} }
static void static void exec_qRcmd(const char *packet,int len)
handle_q_packet(char *packet, int len)
{ {
uint32_t addr, alen;
if(!strncmp(packet, "qRcmd,", 6)) {
char *data; char *data;
int datalen; int datalen;
/* calculate size and allocate buffer for command */ /* calculate size and allocate buffer for command */
datalen = (len - 6) / 2; datalen = len/ 2;
data = alloca(datalen+1); data = alloca(datalen+1);
/* dehexify command */ /* dehexify command */
unhexify(data, packet+6, datalen); unhexify(data, packet, datalen);
data[datalen] = 0; /* add terminating null */ data[datalen] = 0; /* add terminating null */
int c = command_process(cur_target, data); int c = command_process(cur_target, data);
@ -376,12 +370,40 @@ handle_q_packet(char *packet, int len)
else else
gdb_putpacket(hexify(pbuf, "Failed\n", strlen("Failed\n")), gdb_putpacket(hexify(pbuf, "Failed\n", strlen("Failed\n")),
2 * strlen("Failed\n")); 2 * strlen("Failed\n"));
}
} else if (!strncmp (packet, "qSupported", 10)) { static void
/* Query supported protocol features */ handle_q_string_reply(const char *str, const char *param)
{
unsigned long addr, len;
if (sscanf(param, "%08lx,%08lx", &addr, &len) != 2) {
gdb_putpacketz("E01");
return;
}
if (addr > strlen (str)) {
gdb_putpacketz("E01");
return;
}
if(addr== strlen (str)) {
gdb_putpacketz("l");
return;
}
unsigned long output_len=strlen(str)-addr;
if(output_len>len) output_len=len;
gdb_putpacket2("m",1,str+addr,output_len);
}
static void exec_qSupported(const char *packet, int len)
{
(void)packet;
(void)len;
gdb_putpacket_f("PacketSize=%X;qXfer:memory-map:read+;qXfer:features:read+", BUF_SIZE); gdb_putpacket_f("PacketSize=%X;qXfer:memory-map:read+;qXfer:features:read+", BUF_SIZE);
}
} else if (strncmp (packet, "qXfer:memory-map:read::", 23) == 0) { static void exec_qMemoryMap(const char *packet,int len)
{
(void)packet;
(void)len;
/* Read target XML memory map */ /* Read target XML memory map */
if((!cur_target) && last_target) { if((!cur_target) && last_target) {
/* Attach to last target if detached. */ /* Attach to last target if detached. */
@ -394,21 +416,29 @@ handle_q_packet(char *packet, int len)
} }
char buf[1024]; char buf[1024];
target_mem_map(cur_target, buf, sizeof(buf)); /* Fixme: Check size!*/ target_mem_map(cur_target, buf, sizeof(buf)); /* Fixme: Check size!*/
handle_q_string_reply(buf, packet + 23); handle_q_string_reply(buf, packet);
}
} else if (strncmp (packet, "qXfer:features:read:target.xml:", 31) == 0) { static void exec_qFeatureRead(const char *packet, int len)
{
(void)len;
/* Read target description */ /* Read target description */
if((!cur_target) && last_target) { if((!cur_target) && last_target) {
/* Attach to last target if detached. */ /* Attach to last target if detached. */
cur_target = target_attach(last_target, cur_target = target_attach(last_target, &gdb_controller);
&gdb_controller);
} }
if (!cur_target) { if (!cur_target) {
gdb_putpacketz("E01"); gdb_putpacketz("E01");
return; return;
} }
handle_q_string_reply(target_tdesc(cur_target), packet + 31); handle_q_string_reply(target_tdesc(cur_target), packet );
} else if (sscanf(packet, "qCRC:%" PRIx32 ",%" PRIx32, &addr, &alen) == 2) { }
static void exec_qCRC(const char *packet, int len)
{
(void)len;
uint32_t addr, alen;
if (sscanf(packet, "%" PRIx32 ",%" PRIx32, &addr, &alen) == 2) {
if(!cur_target) { if(!cur_target) {
gdb_putpacketz("E01"); gdb_putpacketz("E01");
return; return;
@ -419,12 +449,28 @@ handle_q_packet(char *packet, int len)
gdb_putpacketz("E03"); gdb_putpacketz("E03");
else else
gdb_putpacket_f("C%lx", crc); gdb_putpacket_f("C%lx", crc);
}
}
static const cmd_executer q_commands[]=
{
{"qRcmd,", exec_qRcmd},
{"qSupported", exec_qSupported},
{"qXfer:memory-map:read::", exec_qMemoryMap},
{"qXfer:features:read:target.xml:",exec_qFeatureRead},
{"qCRC:", exec_qCRC},
} else { {NULL,NULL},
};
static void
handle_q_packet(char *packet, int len)
{
if(exec_command(packet,len,q_commands)) {
return;
}
DEBUG_GDB("*** Unsupported packet: %s\n", packet); DEBUG_GDB("*** Unsupported packet: %s\n", packet);
gdb_putpacket("", 0); gdb_putpacket("", 0);
} }
}
static void static void
handle_v_packet(char *packet, int plen) handle_v_packet(char *packet, int plen)

View File

@ -160,7 +160,6 @@ void gdb_putpacket2(const char *packet1, int size1,const char *packet2, int size
{ {
int i; int i;
unsigned char csum; unsigned char csum;
unsigned char c;
char xmit_csum[3]; char xmit_csum[3];
int tries = 0; int tries = 0;
@ -185,7 +184,6 @@ void gdb_putpacket(const char *packet, int size)
{ {
int i; int i;
unsigned char csum; unsigned char csum;
unsigned char c;
char xmit_csum[3]; char xmit_csum[3];
int tries = 0; int tries = 0;
@ -219,7 +217,6 @@ void gdb_putpacket_f(const char *fmt, ...)
void gdb_out(const char *buf) void gdb_out(const char *buf)
{ {
char *hexdata; char *hexdata;
int i;
int l=strlen(buf); int l=strlen(buf);
hexdata = alloca(2*l+1); hexdata = alloca(2*l+1);