fix unused var / naming
This commit is contained in:
parent
b82ee6bc90
commit
8b52bbd9a9
124
src/gdb_main.c
124
src/gdb_main.c
|
@ -48,6 +48,14 @@ enum gdb_signal {
|
|||
#define ERROR_IF_NO_TARGET() \
|
||||
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 target *cur_target;
|
||||
|
@ -329,43 +337,29 @@ int gdb_main_loop(struct target_controller *tc, bool in_syscall)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
handle_q_string_reply(const char *str, const char *param)
|
||||
bool exec_command(char *packet, int len, const cmd_executer *exec)
|
||||
{
|
||||
unsigned long addr, len;
|
||||
|
||||
if (sscanf(param, "%08lx,%08lx", &addr, &len) != 2) {
|
||||
gdb_putpacketz("E01");
|
||||
return;
|
||||
while(exec->cmd_prefix) {
|
||||
int l=strlen(exec->cmd_prefix);
|
||||
if(!strncmp(packet,exec->cmd_prefix,l)) {
|
||||
exec->func(packet+l,len-l);
|
||||
return true;
|
||||
}
|
||||
if (addr < strlen (str)) {
|
||||
char reply[len+2];
|
||||
reply[0] = 'm';
|
||||
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");
|
||||
exec++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void
|
||||
handle_q_packet(char *packet, int len)
|
||||
static void exec_qRcmd(const char *packet,int len)
|
||||
{
|
||||
uint32_t addr, alen;
|
||||
|
||||
if(!strncmp(packet, "qRcmd,", 6)) {
|
||||
char *data;
|
||||
int datalen;
|
||||
char *data;
|
||||
int datalen;
|
||||
|
||||
/* calculate size and allocate buffer for command */
|
||||
datalen = (len - 6) / 2;
|
||||
datalen = len/ 2;
|
||||
data = alloca(datalen+1);
|
||||
/* dehexify command */
|
||||
unhexify(data, packet+6, datalen);
|
||||
unhexify(data, packet, datalen);
|
||||
data[datalen] = 0; /* add terminating null */
|
||||
|
||||
int c = command_process(cur_target, data);
|
||||
|
@ -376,12 +370,40 @@ handle_q_packet(char *packet, int len)
|
|||
else
|
||||
gdb_putpacket(hexify(pbuf, "Failed\n", strlen("Failed\n")),
|
||||
2 * strlen("Failed\n"));
|
||||
}
|
||||
|
||||
} else if (!strncmp (packet, "qSupported", 10)) {
|
||||
/* Query supported protocol features */
|
||||
static void
|
||||
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);
|
||||
}
|
||||
|
||||
} 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 */
|
||||
if((!cur_target) && last_target) {
|
||||
/* Attach to last target if detached. */
|
||||
|
@ -394,21 +416,29 @@ handle_q_packet(char *packet, int len)
|
|||
}
|
||||
char buf[1024];
|
||||
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 */
|
||||
if((!cur_target) && last_target) {
|
||||
/* Attach to last target if detached. */
|
||||
cur_target = target_attach(last_target,
|
||||
&gdb_controller);
|
||||
cur_target = target_attach(last_target, &gdb_controller);
|
||||
}
|
||||
if (!cur_target) {
|
||||
gdb_putpacketz("E01");
|
||||
return;
|
||||
}
|
||||
handle_q_string_reply(target_tdesc(cur_target), packet + 31);
|
||||
} else if (sscanf(packet, "qCRC:%" PRIx32 ",%" PRIx32, &addr, &alen) == 2) {
|
||||
handle_q_string_reply(target_tdesc(cur_target), packet );
|
||||
}
|
||||
|
||||
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) {
|
||||
gdb_putpacketz("E01");
|
||||
return;
|
||||
|
@ -419,11 +449,27 @@ handle_q_packet(char *packet, int len)
|
|||
gdb_putpacketz("E03");
|
||||
else
|
||||
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);
|
||||
gdb_putpacket("", 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -160,7 +160,6 @@ void gdb_putpacket2(const char *packet1, int size1,const char *packet2, int size
|
|||
{
|
||||
int i;
|
||||
unsigned char csum;
|
||||
unsigned char c;
|
||||
char xmit_csum[3];
|
||||
int tries = 0;
|
||||
|
||||
|
@ -185,7 +184,6 @@ void gdb_putpacket(const char *packet, int size)
|
|||
{
|
||||
int i;
|
||||
unsigned char csum;
|
||||
unsigned char c;
|
||||
char xmit_csum[3];
|
||||
int tries = 0;
|
||||
|
||||
|
@ -219,7 +217,6 @@ void gdb_putpacket_f(const char *fmt, ...)
|
|||
void gdb_out(const char *buf)
|
||||
{
|
||||
char *hexdata;
|
||||
int i;
|
||||
|
||||
int l=strlen(buf);
|
||||
hexdata = alloca(2*l+1);
|
||||
|
|
Loading…
Reference in New Issue