On crash, dump the entire memory to a file

This commit is contained in:
Toby Jaffey 2025-12-11 00:22:19 +00:00
parent 15806b592b
commit 1fa58ed800

View file

@ -62,6 +62,7 @@ static uint8_t *read_file(const char* filename, int *len) {
fclose(f); fclose(f);
return NULL; return NULL;
} }
fclose(f);
*len = file_size; *len = file_size;
return buf; return buf;
@ -119,6 +120,23 @@ void hexdump(const uint8_t *p, int len) {
} }
} }
bool memdump(const char *filename, const uint8_t *buf, int len) {
FILE* f = fopen(filename, "wb");
if (f == NULL) {
fprintf(stderr, "error: can't open file '%s'.\n", filename);
return false;
}
size_t result = fwrite(buf, sizeof(uint8_t), len, f);
if (result != len) {
fprintf(stderr, "error: while writing file '%s'\n", filename);
return false;
}
fclose(f);
return true;
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
uvm32_state_t vmst; uvm32_state_t vmst;
uint32_t max_instrs_per_run = 500000; uint32_t max_instrs_per_run = 500000;
@ -174,6 +192,7 @@ int main(int argc, char *argv[]) {
uvm32_clearError(&vmst); // allow to continue uvm32_clearError(&vmst); // allow to continue
} else { } else {
isrunning = false; isrunning = false;
memdump("host-ram.dump", vmst.memory, UVM32_MEMORY_SIZE);
} }
break; break;
case UVM32_EVT_SYSCALL: case UVM32_EVT_SYSCALL: