Little memdump
Tom
tom at nospam.com
Mon Mar 12 17:40:16 PDT 2007
Hi people,
I just wanted to share with you a *very-humble* memdump procedure
that has been very helpful to me in my tedious D-debugging nights.
Kind regards,
--
Tom;
void memdump(void* from, uint length)
{
uint plen= 0;
ubyte* adr(uint i) { return cast(ubyte*)from+i+plen; }
char chr(uint i) { return cast(char)*(cast(ubyte*)from+i+plen); }
ubyte byt(uint i) { return cast(ubyte)*(cast(ubyte*)from+i+plen); }
while (length>0) {
printf("+-----------+-----------+-----------+-----------+\n|");
for (uint i=0; i<16; i+=4) {
printf("0x%08X |", adr(i));
}
printf("\n|");
for (uint i=0, j=0; i<16; i++, j=(j+1)%4) {
if (i < length) {
if (chr(i) < 14) printf(" "); else printf(" %c", chr(i));
} else
printf(" ");
if (j==3) printf("|"); else printf(" ");
}
printf("\n|");
for (uint i=0, j=0; i<16; i++, j=(j+1)%4) {
if (i < length)
printf("%02X", byt(i));
else
printf(" ");
if (j==3) printf("|"); else printf(" ");
}
printf("\n");
if (length > 16)
length-= 16;
else
length= 0;
plen+= 16;
}
printf("+-----------+-----------+-----------+-----------+\n");
}
More information about the Digitalmars-d
mailing list