Skip to content

Commit

Permalink
Add coredump function for calling in the debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed May 12, 2019
1 parent 29744d3 commit e4c6e55
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions emu/memory.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <string.h>
Expand Down Expand Up @@ -247,3 +248,33 @@ size_t real_page_size;
__attribute__((constructor)) static void get_real_page_size() {
real_page_size = sysconf(_SC_PAGESIZE);
}

void mem_coredump(struct mem *mem, const char *file) {
int fd = open(file, O_CREAT | O_RDWR | O_TRUNC, 0666);
if (fd < 0) {
perror("open");
return;
}
if (ftruncate(fd, 0xffffffff) < 0) {
perror("ftruncate");
return;
}

int pages = 0;
for (page_t page = 0; page < MEM_PAGES; page++) {
struct pt_entry *entry = mem_pt(mem, page);
if (entry == NULL)
continue;
pages++;
if (lseek(fd, page << PAGE_BITS, SEEK_SET) < 0) {
perror("lseek");
return;
}
if (write(fd, entry->data->data, PAGE_SIZE) < 0) {
perror("write");
return;
}
}
printk("dumped %d pages\n", pages);
close(fd);
}

0 comments on commit e4c6e55

Please sign in to comment.