Skip to content

Commit

Permalink
Merge pull request #88 from kwolekr/master
Browse files Browse the repository at this point in the history
debugger: Add dumpmem command
  • Loading branch information
richard42 authored Dec 5, 2024
2 parents 198eeaa + 16f1380 commit a3a53cc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ write
write <addr> w <value> Write a word value (4 bytes) to <addr>
write <addr> d <value> Write a double-word value (8 bytes) to <addr>

dumpmem <addr> <n> <filename>
Dump <n> bytes of RDRAM memory starting at <addr> to <filename>.

translate
Translates virtual memory addresses to physical memory addresses. Memory
read/write breakpoints must operate on physical addresses, in contrast to the
Expand Down
41 changes: 41 additions & 0 deletions src/debugger.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,47 @@ int debugger_loop(void *arg) {
printf("\n");
}
}
else if (strncmp(input, "dumpmem", 7) == 0) {
uint32_t addr;
uint32_t len;
char filename[64];

uint8_t *membase;
FILE *f;

if (sscanf(input, "dumpmem %x 0x%x %63s", &addr, &len, filename) != 3 &&
sscanf(input, "dumpmem %x %u %63s", &addr, &len, filename) != 3) {
printf("Improperly formatted dumpmem command: '%s'\n", input);
continue;
}

filename[sizeof(filename) - 1] = '\0';

addr = (*DebugVirtualToPhysical)(addr);
if (addr >= 0x800000) {
printf("Requested address must be within RDRAM region\n");
continue;
}

// 8 MB is the upper limit
if (len > 0x800000 - addr)
len = 0x800000 - addr;

membase = (*DebugMemGetPointer)(M64P_DBG_PTR_RDRAM);

f = fopen(filename, "wb");
if (f == NULL) {
printf("Could not open file '%s' for write\n", filename);
continue;
}

fwrite(membase + addr, len, 1, f);

fclose(f);

printf("Dumped 0x%08x bytes starting at 0x%08x to %s\n",
len, addr, filename);
}
else if (strncmp(input, "translate", 9) == 0) {
uint32_t virt_addr, phys_addr;
if (sscanf(input, "translate %i", &virt_addr) == 1) {
Expand Down

0 comments on commit a3a53cc

Please sign in to comment.