void GdbServer::handle_q_packet (char *packet, int len) { unsigned long addr, alen; if (!strncmp (packet, "qRcmd,", 6)) { int datalen; /* calculate size and allocate buffer for command */ datalen = (len - 6) / 2; char data [datalen + 1]; /* dehexify command */ unhexify ((unsigned char*) data, (const unsigned char*)packet + 6, datalen); data[datalen] = 0; /* add terminating null */ int c = mon.command (data); if (c < 0) gdb_putpacketz (""); else if (c == 0) gdb_putpacketz ("OK"); else gdb_putpacketz ("E"); } else if (!strncmp (packet, "qSupported", 10)) { /* Query supported protocol features */ gdb_putpacket_f ("PacketSize=%X;qXfer:memory-map:read+;qXfer:features:read+", BUF_SIZE); } else if (strncmp (packet, "qXfer:memory-map:read::", 23) == 0) { /* Read target XML memory map */ if ((!target) || (!target->xml_mem_map)) { gdb_putpacketz ("E01"); return; } handle_q_string_reply (target->xml_mem_map, packet + 23); } else if (strncmp (packet, "qXfer:features:read:target.xml:", 31) == 0) { /* Read target description */ if ((!target) || (!target->tdesc)) { gdb_putpacketz ("E01"); return; } handle_q_string_reply (target->tdesc, packet + 31); } else if (sscanf (packet, "qCRC:%08lx,%08lx", &addr, &alen) == 2) { if (!target) { gdb_putpacketz ("E01"); return; } gdb_putpacket_f ("C%lx", target->generic_crc32 (addr, alen)); } else { debug ("*** Unsupported packet: %s\n", packet); gdb_putpacket ("", 0); } }
static void handle_q_packet(char *packet, int len) { uint32_t addr, alen; if(!strncmp(packet, "qRcmd,", 6)) { char *data; int datalen; /* calculate size and allocate buffer for command */ datalen = (len - 6) / 2; data = alloca(datalen+1); /* dehexify command */ unhexify(data, packet+6, datalen); data[datalen] = 0; /* add terminating null */ int c = command_process(cur_target, data); if(c < 0) gdb_putpacketz(""); else if(c == 0) gdb_putpacketz("OK"); else gdb_putpacketz("E"); } else if (!strncmp (packet, "qSupported", 10)) { /* Query supported protocol features */ gdb_putpacket_f("PacketSize=%X;qXfer:memory-map:read+;qXfer:features:read+", BUF_SIZE); } else if (strncmp (packet, "qXfer:memory-map:read::", 23) == 0) { /* Read target XML memory map */ if((!cur_target) && last_target) { /* Attach to last target if detached. */ cur_target = target_attach(last_target, gdb_target_destroy_callback); } if (!cur_target) { gdb_putpacketz("E01"); return; } handle_q_string_reply(target_mem_map(cur_target), packet + 23); } else if (strncmp (packet, "qXfer:features:read:target.xml:", 31) == 0) { /* Read target description */ if((!cur_target) && last_target) { /* Attach to last target if detached. */ cur_target = target_attach(last_target, gdb_target_destroy_callback); } 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) { if(!cur_target) { gdb_putpacketz("E01"); return; } gdb_putpacket_f("C%lx", generic_crc32(cur_target, addr, alen)); } else { DEBUG("*** Unsupported packet: %s\n", packet); gdb_putpacket("", 0); } }