Created
July 3, 2012 08:43
-
-
Save wvdschel/3038553 to your computer and use it in GitHub Desktop.
Dump memory from gdb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned int ReadWord(unsigned int *address) | |
{ | |
return *address; | |
} | |
int DumpMemory(char *fileName, void* address, size_t size) | |
{ | |
int file; | |
int ret = 0; | |
size_t written = 0; | |
do { | |
file = open(fileName, O_RDWR | O_CREAT | O_TRUNC); | |
} while(file == -1 && errno == EINTR); | |
if(file == -1) { | |
TraceErr(m, "Couldn't open %s to dump memory: %s", fileName, strerror(errno)); | |
ret = -1; | |
} | |
while(written < size) | |
{ | |
int w = write(file, address+written, size-written); | |
if(w < 0 && errno != EINTR) | |
{ | |
TraceErr(m, "Write to %s failed: %s", fileName, strerror(errno)); | |
ret = -1; | |
break; | |
} else { | |
written += w; | |
} | |
} | |
if(ret == 0 && close(file) != 0 && errno != EINTR) | |
{ | |
TraceErr(m, "Closing %s failed (%s), file may be wrong or incomplete.", fileName, strerror(errno)); | |
ret = -1; | |
} | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment