Clean up ancient bad typing and malloc madness.

This commit is contained in:
Gareth McMullin 2012-11-03 19:52:09 +13:00
parent 50b6c623d6
commit dac1f60dc2
1 changed files with 25 additions and 30 deletions

View File

@ -73,7 +73,7 @@ void
gdb_main(void)
{
int size;
static uint8_t single_step = 0;
bool single_step = false;
DEBUG("Entring GDB protocol main loop\n");
/* GDB protocol main loop */
@ -91,13 +91,11 @@ gdb_main(void)
break;
}
case 'm': { /* 'm addr,len': Read len bytes from addr */
unsigned long addr, len;
char *mem;
uint32_t addr, len;
ERROR_IF_NO_TARGET();
sscanf(pbuf, "m%08lX,%08lX", &addr, &len);
DEBUG("m packet: addr = %08lX, len = %08lX\n", addr, len);
mem = malloc(len);
if(!mem) break;
uint8_t mem[len];
if(((addr & 3) == 0) && ((len & 3) == 0))
target_mem_read_words(cur_target, (void*)mem, addr, len);
else
@ -106,7 +104,6 @@ gdb_main(void)
gdb_putpacket("E01", 3);
else
gdb_putpacket(hexify(pbuf, mem, len), len*2);
free(mem);
break;
}
case 'G': { /* 'G XX': Write general registers */
@ -118,13 +115,12 @@ gdb_main(void)
break;
}
case 'M': { /* 'M addr,len:XX': Write len bytes to addr */
unsigned long addr, len;
uint32_t addr, len;
int hex;
char *mem;
ERROR_IF_NO_TARGET();
sscanf(pbuf, "M%08lX,%08lX:%n", &addr, &len, &hex);
DEBUG("M packet: addr = %08lX, len = %08lX\n", addr, len);
mem = malloc(len);
uint8_t mem[len];
unhexify(mem, pbuf + hex, len);
if(((addr & 3) == 0) && ((len & 3) == 0))
target_mem_write_words(cur_target, addr, (void*)mem, len);
@ -134,11 +130,10 @@ gdb_main(void)
gdb_putpacket("E01", 3);
else
gdb_putpacket("OK", 2);
free(mem);
break;
}
case 's': /* 's [addr]': Single step [start at addr] */
single_step = 1;
single_step = true;
// Fall through to resume target
case 'c': /* 'c [addr]': Continue [at addr] */
if(!cur_target) {
@ -148,7 +143,7 @@ gdb_main(void)
target_halt_resume(cur_target, single_step);
SET_RUN_STATE(1);
single_step = 0;
single_step = false;
// Fall through to wait for target halt
case '?': { /* '?': Request reason for target halt */
/* This packet isn't documented as being mandatory,
@ -219,7 +214,7 @@ gdb_main(void)
break;
case 'X': { /* 'X addr,len:XX': Write binary data to addr */
unsigned long addr, len;
uint32_t addr, len;
int bin;
ERROR_IF_NO_TARGET();
sscanf(pbuf, "X%08lX,%08lX:%n", &addr, &len, &bin);
@ -248,7 +243,7 @@ gdb_main(void)
case 'z': { /* z type,addr,len: Clear breakpoint packet */
uint8_t set = (pbuf[0]=='Z')?1:0;
int type, len;
unsigned long addr;
uint32_t addr;
int ret;
ERROR_IF_NO_TARGET();
/* I have no idea why this doesn't work. Seems to work