 |
Changeset 3539
- Timestamp:
- 05/31/08 10:36:28
(6 months ago)
- Author:
- keinfarbton
- Message:
Add Trace.memory. This closes ticket #773.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r2809 |
r3539 |
|
| 9 | 9 | author: Kris |
|---|
| 10 | 10 | |
|---|
| 11 | | Synchronized, formatted console output. This can be used in lieu |
|---|
| | 11 | Synchronized, formatted console output. This can be used in lieu |
|---|
| 12 | 12 | of true logging where appropriate. |
|---|
| 13 | 13 | |
|---|
| … | … | |
| 21 | 21 | Special character sequences, such as "\n", are written directly to |
|---|
| 22 | 22 | the output without any translation (though an output-filter could |
|---|
| 23 | | be inserted to perform translation as required). Platform-specific |
|---|
| 24 | | newlines are generated instead via the formatln() method, which also |
|---|
| | 23 | be inserted to perform translation as required). Platform-specific |
|---|
| | 24 | newlines are generated instead via the formatln() method, which also |
|---|
| 25 | 25 | flushes the output when configured to do so: |
|---|
| 26 | 26 | --- |
|---|
| … | … | |
| 32 | 32 | Trace.format ("hello {}", "world").flush; |
|---|
| 33 | 33 | --- |
|---|
| 34 | | |
|---|
| | 34 | |
|---|
| 35 | 35 | *******************************************************************************/ |
|---|
| 36 | 36 | |
|---|
| … | … | |
| 58 | 58 | |
|---|
| 59 | 59 | /******************************************************************************* |
|---|
| 60 | | |
|---|
| | 60 | |
|---|
| 61 | 61 | Intended for internal use only |
|---|
| 62 | | |
|---|
| | 62 | |
|---|
| 63 | 63 | *******************************************************************************/ |
|---|
| 64 | 64 | |
|---|
| … | … | |
| 143 | 143 | return output.write (s); |
|---|
| 144 | 144 | } |
|---|
| | 145 | |
|---|
| | 146 | /********************************************************************** |
|---|
| | 147 | |
|---|
| | 148 | Print a range of raw memory as a hex dump. |
|---|
| | 149 | Characters in range 0x20..0xFE are printed, all others are |
|---|
| | 150 | shown as dots. |
|---|
| | 151 | |
|---|
| | 152 | ---- |
|---|
| | 153 | 000000: 47 49 46 38 39 61 10 00 10 00 80 00 00 48 5D 8C GIF89a.......H]. |
|---|
| | 154 | 000010: FF FF FF 21 F9 04 01 00 00 01 00 2C 00 00 00 00 ...!.......,.... |
|---|
| | 155 | 000020: 10 00 10 00 00 02 11 8C 8F A9 CB ED 0F A3 84 C0 ................ |
|---|
| | 156 | 000030: D4 70 A7 DE BC FB 8F 14 00 3B .p.......; |
|---|
| | 157 | ---- |
|---|
| | 158 | |
|---|
| | 159 | **********************************************************************/ |
|---|
| | 160 | |
|---|
| | 161 | final SyncPrint memory (void[] mem) |
|---|
| | 162 | { |
|---|
| | 163 | auto data = cast(ubyte[]) mem; |
|---|
| | 164 | synchronized (mutex) |
|---|
| | 165 | { |
|---|
| | 166 | for( int row = 0; row < data.length; row += 16 ) |
|---|
| | 167 | { |
|---|
| | 168 | // print relative offset |
|---|
| | 169 | convert.convert (&sink, "{:X6}: ", row ); |
|---|
| | 170 | |
|---|
| | 171 | // print data bytes |
|---|
| | 172 | for( int idx = 0; idx < 16 ; idx++ ) |
|---|
| | 173 | { |
|---|
| | 174 | // print byte or stuffing spaces |
|---|
| | 175 | if ( idx + row < data.length ) |
|---|
| | 176 | convert (&sink, "{:X2} ", data[ row + idx ] ); |
|---|
| | 177 | else |
|---|
| | 178 | output.write (" "); |
|---|
| | 179 | |
|---|
| | 180 | // after each 4 bytes group an extra space |
|---|
| | 181 | if (( idx & 0x03 ) == 3 ) |
|---|
| | 182 | output.write (" "); |
|---|
| | 183 | } |
|---|
| | 184 | |
|---|
| | 185 | // ascii view |
|---|
| | 186 | // all char 0x20..0x7e are OK for printing, |
|---|
| | 187 | // other values are printed as a dot |
|---|
| | 188 | ubyte[16] ascii = void; |
|---|
| | 189 | int asciiIdx; |
|---|
| | 190 | for ( asciiIdx = 0; |
|---|
| | 191 | (asciiIdx<16) && (asciiIdx+row < data.length); |
|---|
| | 192 | asciiIdx++ ) |
|---|
| | 193 | { |
|---|
| | 194 | ubyte c = data[ row + asciiIdx ]; |
|---|
| | 195 | if ( c < 0x20 || c > 0x7E ) |
|---|
| | 196 | c = '.'; |
|---|
| | 197 | ascii[asciiIdx] = c; |
|---|
| | 198 | } |
|---|
| | 199 | output.write (ascii[ 0 .. asciiIdx ]); |
|---|
| | 200 | output.write (Eol); |
|---|
| | 201 | } |
|---|
| | 202 | if (flushLines) |
|---|
| | 203 | output.flush; |
|---|
| | 204 | } |
|---|
| | 205 | return this; |
|---|
| | 206 | } |
|---|
| 145 | 207 | } |
|---|
Download in other formats:
|
 |
 |
|
 |
Copyright © 2006-2008 Tango. All Rights Reserved. | Page Width:
Static or
Dynamic