Little memdump
Jeff McGlynn
d at jeffrules.com
Thu Mar 15 02:14:07 PDT 2007
On 2007-03-15 02:03:44 -0700, Bill Baxter <dnewsgroup at billbaxter.com> said:
> Jeff McGlynn wrote:
>> 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();
>> }
>>
>
>
> Just curious -- what are you guys doing that you have to dump memory so often?
>
> --bb
I recently wrote a FastCGI server, which uses a binary protocol. Using
this allowed me to debug protocol errors without adding new code each
time.
--
Jeff McGlynn
More information about the Digitalmars-d
mailing list