|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Helper functions for debug |
|
15 |
|
16 #include <e32err.h> |
|
17 #include <e32const.h> |
|
18 #include <e32def.h> |
|
19 #include <e32cmn.h> |
|
20 #include <e32des8.h> |
|
21 #include <kernel/kernel.h> |
|
22 |
|
23 |
|
24 #include "hcr_debug.h" |
|
25 |
|
26 /** |
|
27 Make a classic hexadecimal dump of the content of an memory region. |
|
28 |
|
29 @param aStartAddress Pointer of the first byte of the region |
|
30 aLength Size of the region |
|
31 aAbsolute If it is TRUE then it displays absolute address where the aStartAddress points |
|
32 If it is FALSE then it displays reltive address from aStartAddress |
|
33 |
|
34 @pre Call from thread context (neither NULL, DFC0, DFC1 threads) |
|
35 */ |
|
36 void HexDump(TUint8* aStartAddress, TUint32 aLength, TBool aAbsolute) |
|
37 { |
|
38 TUint32 nIndex; |
|
39 TBuf<128> printBuf; // Buffer for address and values |
|
40 TBuf<32> printBuf2; // Buffer for character representation |
|
41 |
|
42 TUint32 extLength = ((aLength & 0xf) == 0 ? aLength :(aLength & 0xfffffff0)+0x10); |
|
43 |
|
44 for(nIndex = 0; nIndex != extLength ; ++nIndex ) |
|
45 { |
|
46 if(nIndex % 16 == 0) |
|
47 { |
|
48 // A line is ready compose two buffers and print the line out |
|
49 printBuf.Append(_L(" ")); |
|
50 printBuf.Append(printBuf2); |
|
51 Kern::Printf("%S", &printBuf); |
|
52 |
|
53 // Start a new line |
|
54 printBuf.Zero(); |
|
55 printBuf.Append(_L("0x")); |
|
56 if(aAbsolute) |
|
57 { |
|
58 printBuf.AppendNumFixedWidth((TUint)(aStartAddress + nIndex), EHex,8); |
|
59 } |
|
60 else |
|
61 { |
|
62 printBuf.AppendNumFixedWidth((TUint)(nIndex), EHex,8); |
|
63 } |
|
64 |
|
65 printBuf.Append(_L(": ")); |
|
66 printBuf2.Zero(); |
|
67 } |
|
68 |
|
69 if( nIndex < aLength ) |
|
70 { |
|
71 // Active content |
|
72 // Put the value into buffer |
|
73 printBuf.AppendNumFixedWidth(*(aStartAddress + nIndex), EHex,2 ); |
|
74 printBuf.Append(TChar(' ')); |
|
75 |
|
76 // Put the chracter representation into a second buffer |
|
77 if( *(aStartAddress + nIndex) < ' ' ) |
|
78 { |
|
79 printBuf2.Append(TChar('.')); // Control character |
|
80 } |
|
81 else |
|
82 { |
|
83 printBuf2.Append(TChar(*(aStartAddress + nIndex))); |
|
84 } |
|
85 } |
|
86 else |
|
87 { |
|
88 // Fill up content |
|
89 printBuf.Append(_L(" ")); // Fill value place with spaces |
|
90 printBuf2.Append(TChar(' ')); // Fill char representation place with space |
|
91 } |
|
92 } |
|
93 // Print out the rest of the buffer |
|
94 printBuf.Append(_L(" ")); |
|
95 printBuf.Append(printBuf2); |
|
96 Kern::Printf("%S\n", &printBuf); |
|
97 } |
|
98 |