gdbstub: implemented 'm' 'M' memory commands
This commit is contained in:
parent
629fa5fc56
commit
afc68c1c96
@ -1,6 +1,8 @@
|
|||||||
#include "gdbstub.h"
|
#include "gdbstub.h"
|
||||||
|
|
||||||
#include "cpu/rv32cpu.h"
|
#include "cpu/rv32cpu.h"
|
||||||
|
#include "memory/memory.h"
|
||||||
|
#include "memory/mmu/mmu.h"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -218,6 +220,43 @@ void gdbstub_thread_gdb()
|
|||||||
|
|
||||||
gdbstub_send_packet("OK", 2);
|
gdbstub_send_packet("OK", 2);
|
||||||
}
|
}
|
||||||
|
else if(packet[0] == 'm')
|
||||||
|
{
|
||||||
|
// m : read memory at address,length
|
||||||
|
uint32_t address;
|
||||||
|
uint32_t length;
|
||||||
|
sscanf(packet + 1, "%x,%x", &address, &length);
|
||||||
|
|
||||||
|
char data[length * 2 + 1];
|
||||||
|
for(size_t i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
uint32_t value = memory[mmu_translate(address + i)];
|
||||||
|
snprintf(data + i * 2, 3, "%02x", value);
|
||||||
|
}
|
||||||
|
|
||||||
|
gdbstub_send_packet(data, length * 2);
|
||||||
|
}
|
||||||
|
else if(packet[0] == 'M')
|
||||||
|
{
|
||||||
|
// M : write memory at address,length:data
|
||||||
|
uint32_t address;
|
||||||
|
uint32_t length;
|
||||||
|
sscanf(packet + 1, "%x,%x:", &address, &length);
|
||||||
|
|
||||||
|
uint32_t data_start = 1;
|
||||||
|
while(*(packet + data_start) != ':')
|
||||||
|
data_start++;
|
||||||
|
data_start++;
|
||||||
|
|
||||||
|
for(size_t i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
uint32_t value;
|
||||||
|
sscanf(packet + data_start + i * 2, "%02x", &value);
|
||||||
|
memory[mmu_translate(address + i)] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
gdbstub_send_packet("OK", 2);
|
||||||
|
}
|
||||||
else if(packet[0] == 's')
|
else if(packet[0] == 's')
|
||||||
{
|
{
|
||||||
// s : single-step
|
// s : single-step
|
||||||
|
Loading…
x
Reference in New Issue
Block a user