Little memdump
Jeff McGlynn
d at jeffrules.com
Thu Mar 15 01:38:36 PDT 2007
On 2007-03-12 17:40:16 -0700, Tom <tom at nospam.com> said:
> 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,
Here is the code that I use:
import std.stdio;
import std.ctype;
void debug_dump(ubyte[] data) {
uint len = data.length;
writefln("=== GOT %d BYTES:", len);
for(uint offset = 0; offset < len; offset += 20) {
uint end = offset + 20;
if (end > len) end = len;
for(uint ix = offset; ix < end; ++ix) {
writef("%02X ", data[ix]);
}
if (offset + 20 > len) {
char[] space = new char[3 * (offset + 20 - len)];
space[] = ' ';
writef(space);
}
writef("| ");
for(uint ix = offset; ix < end; ++ix) {
if (isprint(data[ix])) {
writef("%s", cast(char) data[ix]);
} else {
writef(".");
}
}
writefln();
}
writefln();
}
--
Jeff McGlynn
More information about the Digitalmars-d
mailing list