Merge commit 'cedd9f9ac4fc02cc5ac152eb67024f714c6f95ab' into sam-update
This commit is contained in:
commit
b096e95488
184
src/gdb_main.c
184
src/gdb_main.c
@ -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,6 +337,40 @@ int gdb_main_loop(struct target_controller *tc, bool in_syscall)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
bool exec_command(char *packet, int len, const cmd_executer *exec)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
exec++;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void exec_q_rcmd(const char *packet,int len)
|
||||||
|
{
|
||||||
|
char *data;
|
||||||
|
int datalen;
|
||||||
|
|
||||||
|
/* calculate size and allocate buffer for command */
|
||||||
|
datalen = len/ 2;
|
||||||
|
data = alloca(datalen+1);
|
||||||
|
/* dehexify command */
|
||||||
|
unhexify(data, packet, 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_putpacket(hexify(pbuf, "Failed\n", strlen("Failed\n")),
|
||||||
|
2 * strlen("Failed\n"));
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
handle_q_string_reply(const char *str, const char *param)
|
handle_q_string_reply(const char *str, const char *param)
|
||||||
@ -339,76 +381,64 @@ handle_q_string_reply(const char *str, const char *param)
|
|||||||
gdb_putpacketz("E01");
|
gdb_putpacketz("E01");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (addr < strlen (str)) {
|
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");
|
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_q_supported(const char *packet, int len)
|
||||||
|
{
|
||||||
|
(void)packet;
|
||||||
|
(void)len;
|
||||||
|
gdb_putpacket_f("PacketSize=%X;qXfer:memory-map:read+;qXfer:features:read+", BUF_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void exec_q_memory_map(const char *packet,int len)
|
||||||
handle_q_packet(char *packet, int len)
|
|
||||||
{
|
{
|
||||||
|
(void)packet;
|
||||||
|
(void)len;
|
||||||
|
/* Read target XML memory map */
|
||||||
|
if((!cur_target) && last_target) {
|
||||||
|
/* Attach to last target if detached. */
|
||||||
|
cur_target = target_attach(last_target,
|
||||||
|
&gdb_controller);
|
||||||
|
}
|
||||||
|
if (!cur_target) {
|
||||||
|
gdb_putpacketz("E01");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
char buf[1024];
|
||||||
|
target_mem_map(cur_target, buf, sizeof(buf)); /* Fixme: Check size!*/
|
||||||
|
handle_q_string_reply(buf, packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void exec_q_feature_read(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);
|
||||||
|
}
|
||||||
|
if (!cur_target) {
|
||||||
|
gdb_putpacketz("E01");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
handle_q_string_reply(target_tdesc(cur_target), packet );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void exec_q_crc(const char *packet, int len)
|
||||||
|
{
|
||||||
|
(void)len;
|
||||||
uint32_t addr, alen;
|
uint32_t addr, alen;
|
||||||
|
if (sscanf(packet, "%" PRIx32 ",%" PRIx32, &addr, &alen) == 2) {
|
||||||
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_putpacket(hexify(pbuf, "Failed\n", strlen("Failed\n")),
|
|
||||||
2 * strlen("Failed\n"));
|
|
||||||
|
|
||||||
} 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_controller);
|
|
||||||
}
|
|
||||||
if (!cur_target) {
|
|
||||||
gdb_putpacketz("E01");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
char buf[1024];
|
|
||||||
target_mem_map(cur_target, buf, sizeof(buf)); /* Fixme: Check size!*/
|
|
||||||
handle_q_string_reply(buf, 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_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) {
|
|
||||||
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);
|
||||||
|
|
||||||
} else {
|
|
||||||
DEBUG_GDB("*** Unsupported packet: %s\n", packet);
|
|
||||||
gdb_putpacket("", 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static const cmd_executer q_commands[]=
|
||||||
|
{
|
||||||
|
{"qRcmd,", exec_q_rcmd},
|
||||||
|
{"qSupported", exec_q_supported},
|
||||||
|
{"qXfer:memory-map:read::", exec_q_memory_map},
|
||||||
|
{"qXfer:features:read:target.xml:",exec_q_feature_read},
|
||||||
|
{"qCRC:", exec_q_crc},
|
||||||
|
|
||||||
|
{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
|
static void
|
||||||
handle_v_packet(char *packet, int plen)
|
handle_v_packet(char *packet, int plen)
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
int gdb_getpacket(char *packet, int size);
|
int gdb_getpacket(char *packet, int size);
|
||||||
void gdb_putpacket(const char *packet, int size);
|
void gdb_putpacket(const char *packet, int size);
|
||||||
|
void gdb_putpacket2(const char *packet1, int size1,const char *packet2, int size2);
|
||||||
#define gdb_putpacketz(packet) gdb_putpacket((packet), strlen(packet))
|
#define gdb_putpacketz(packet) gdb_putpacket((packet), strlen(packet))
|
||||||
void gdb_putpacket_f(const char *packet, ...);
|
void gdb_putpacket_f(const char *packet, ...);
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ int usbuart_debug_write(const char *buf, size_t len);
|
|||||||
#define USBUSART_DMA_CLK RCC_DMA1
|
#define USBUSART_DMA_CLK RCC_DMA1
|
||||||
#define USBUSART_DMA_TX_CHAN DMA_CHANNEL4
|
#define USBUSART_DMA_TX_CHAN DMA_CHANNEL4
|
||||||
#define USBUSART_DMA_TX_IRQ NVIC_DMA1_CHANNEL4_IRQ
|
#define USBUSART_DMA_TX_IRQ NVIC_DMA1_CHANNEL4_IRQ
|
||||||
//#define USBUSART_DMA_TX_ISR(x) dma1_channel4_isr(x)
|
#define USBUSART_DMA_TX_ISR(x) dma1_channel4_isr(x)
|
||||||
#define USBUSART_DMA_RX_CHAN DMA_CHANNEL5
|
#define USBUSART_DMA_RX_CHAN DMA_CHANNEL5
|
||||||
#define USBUSART_DMA_RX_IRQ NVIC_DMA1_CHANNEL5_IRQ
|
#define USBUSART_DMA_RX_IRQ NVIC_DMA1_CHANNEL5_IRQ
|
||||||
#define USBUSART_DMA_RX_ISR(x) dma1_channel5_isr(x)
|
#define USBUSART_DMA_RX_ISR(x) dma1_channel5_isr(x)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user