1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "MemSpyDriverUtils.h" |
|
19 |
|
20 // System includes |
|
21 #include <kern_priv.h> |
|
22 #include <nk_plat.h> |
|
23 #ifdef __MARM__ |
|
24 #include <arm.h> |
|
25 #endif |
|
26 #include <memspy/driver/memspydriverobjectsshared.h> |
|
27 |
|
28 // User includes |
|
29 #include "MemSpyDriverOSAdaption.h" |
|
30 |
|
31 // Constants |
|
32 static const char KFault[] = "MemSpy-Bug"; |
|
33 |
|
34 |
|
35 |
|
36 void MemSpyDriverUtils::DataDump( const char* aFmt, const TUint8* aAddress, TInt aLength, TInt aMaxLength) |
|
37 { |
|
38 const TInt maxLen = aMaxLength; |
|
39 TInt len = aLength; |
|
40 const TUint8* pDataAddr = aAddress; |
|
41 |
|
42 TBuf8<81> out; |
|
43 TBuf8<20> ascii; |
|
44 TInt offset = 0; |
|
45 const TUint8* a = pDataAddr; |
|
46 // |
|
47 while(len>0) |
|
48 { |
|
49 out.Zero(); |
|
50 ascii.Zero(); |
|
51 out.AppendNumFixedWidth((TUint) a, EHex, 8); |
|
52 out.Append(_L(": ")); |
|
53 |
|
54 TUint b; |
|
55 for (b=0; b<16; b++) |
|
56 { |
|
57 TUint8 c = ' '; |
|
58 if ((pDataAddr + offset + b) < pDataAddr + maxLen) |
|
59 { |
|
60 c = *(pDataAddr + offset + b); |
|
61 out.AppendNumFixedWidth(c, EHex, 2); |
|
62 } |
|
63 else |
|
64 { |
|
65 out.Append(_L(" ")); |
|
66 } |
|
67 out.Append(' '); |
|
68 if (c<=0x20 || c == 0x27 || c>=0x7f || c=='%') |
|
69 c=0x2e; |
|
70 ascii.Append(TChar(c)); |
|
71 } |
|
72 out.Append(ascii); |
|
73 out.Append(TChar(0)); |
|
74 |
|
75 Kern::Printf(aFmt, &out); |
|
76 |
|
77 a += 16; |
|
78 offset += 16; |
|
79 len -= 16; |
|
80 } |
|
81 } |
|
82 |
|
83 |
|
84 void MemSpyDriverUtils::PanicThread( DThread& aThread, TMemSpyDriverPanic aPanicType ) |
|
85 { |
|
86 Kern::ThreadKill( &aThread, EExitPanic, aPanicType, KMemSpyClientPanic ); |
|
87 } |
|
88 |
|
89 |
|
90 void MemSpyDriverUtils::Fault( TInt aReason ) |
|
91 { |
|
92 Kern::Fault( KFault, aReason ); |
|
93 } |
|
94 |
|
95 |
|
96 void MemSpyDriverUtils::GetThreadRegisters( NThread* aThread, TMemSpyDriverRegSet& aInfo ) |
|
97 { |
|
98 DThread* dThread = Kern::NThreadToDThread( aThread ); |
|
99 TRACE( Kern::Printf( "MemSpyDriverUtils::GetThreadRegisters() - START - aThread: %O", dThread )); |
|
100 memclr( &aInfo, sizeof( TMemSpyDriverRegSet ) ); |
|
101 TRACE( Kern::Printf( "MemSpyDriverUtils::GetThreadRegisters() - cleared" )); |
|
102 |
|
103 #ifdef __MARM__ |
|
104 if ( aThread != NULL ) |
|
105 { |
|
106 TArmRegSet regSet; |
|
107 memclr( ®Set, sizeof(TArmRegSet) ); |
|
108 // |
|
109 TUint32 unused; |
|
110 TRACE( Kern::Printf( "MemSpyDriverUtils::GetThreadRegisters() - getting user context..." )); |
|
111 NKern::ThreadGetUserContext( aThread, ®Set, unused); |
|
112 TRACE( Kern::Printf( "MemSpyDriverUtils::GetThreadRegisters() - got user context" )); |
|
113 // |
|
114 aInfo.iRn[ 0] = regSet.iR0; |
|
115 aInfo.iRn[ 1] = regSet.iR1; |
|
116 aInfo.iRn[ 2] = regSet.iR2; |
|
117 aInfo.iRn[ 3] = regSet.iR3; |
|
118 aInfo.iRn[ 4] = regSet.iR4; |
|
119 aInfo.iRn[ 5] = regSet.iR5; |
|
120 aInfo.iRn[ 6] = regSet.iR6; |
|
121 aInfo.iRn[ 7] = regSet.iR7; |
|
122 aInfo.iRn[ 8] = regSet.iR8; |
|
123 aInfo.iRn[ 9] = regSet.iR9; |
|
124 aInfo.iRn[10] = regSet.iR10; |
|
125 aInfo.iRn[11] = regSet.iR11; |
|
126 aInfo.iRn[12] = regSet.iR12; |
|
127 aInfo.iRn[13] = regSet.iR13; |
|
128 aInfo.iRn[14] = regSet.iR14; |
|
129 aInfo.iRn[15] = regSet.iR15; |
|
130 // |
|
131 aInfo.iCpsr = regSet.iFlags; |
|
132 } |
|
133 #else |
|
134 (void) aThread; |
|
135 #endif |
|
136 |
|
137 TRACE( Kern::Printf( "MemSpyDriverUtils::GetThreadRegisters() - END" )); |
|
138 } |
|
139 |
|
140 |
|
141 TThreadPriority MemSpyDriverUtils::MapToUserThreadPriority( TInt aPriority ) |
|
142 { |
|
143 TThreadPriority tp = EPriorityNormal; |
|
144 // |
|
145 switch(aPriority) |
|
146 { |
|
147 case EThrdPriorityMuchLess: |
|
148 tp=EPriorityMuchLess; |
|
149 break; |
|
150 case EThrdPriorityLess: |
|
151 tp=EPriorityLess; |
|
152 break; |
|
153 default: |
|
154 case EThrdPriorityNormal: |
|
155 tp=EPriorityNormal; |
|
156 break; |
|
157 case EThrdPriorityMore: |
|
158 tp=EPriorityMore; |
|
159 break; |
|
160 case EThrdPriorityMuchMore: |
|
161 tp=EPriorityMuchMore; |
|
162 break; |
|
163 case EThrdPriorityRealTime: |
|
164 tp=EPriorityRealTime; |
|
165 break; |
|
166 case EThrdPriorityAbsoluteVeryLow: |
|
167 tp=EPriorityAbsoluteVeryLow; |
|
168 break; |
|
169 case EThrdPriorityAbsoluteLow: |
|
170 tp=EPriorityAbsoluteLow; |
|
171 break; |
|
172 case EThrdPriorityAbsoluteBackground: |
|
173 tp=EPriorityAbsoluteBackground; |
|
174 break; |
|
175 case EThrdPriorityAbsoluteForeground: |
|
176 tp=EPriorityAbsoluteForeground; |
|
177 break; |
|
178 case EThrdPriorityAbsoluteHigh: |
|
179 tp=EPriorityAbsoluteHigh; |
|
180 break; |
|
181 } |
|
182 // |
|
183 return tp; |
|
184 } |
|
185 |
|
186 |
|
187 TInt MemSpyDriverUtils::MapToAbsoluteThreadPriority( TThreadPriority aPriority ) |
|
188 { |
|
189 TInt tp = KErrNotSupported; |
|
190 switch( aPriority ) |
|
191 { |
|
192 case EPriorityAbsoluteVeryLow: |
|
193 tp=EThrdPriorityAbsoluteVeryLow; break; |
|
194 case EPriorityAbsoluteLowNormal: |
|
195 tp=EThrdPriorityAbsoluteLowNormal; break; |
|
196 case EPriorityAbsoluteLow: |
|
197 tp=EThrdPriorityAbsoluteLow; break; |
|
198 case EPriorityAbsoluteBackgroundNormal: |
|
199 tp=EThrdPriorityAbsoluteBackgroundNormal; break; |
|
200 case EPriorityAbsoluteBackground: |
|
201 tp=EThrdPriorityAbsoluteBackground; break; |
|
202 case EPriorityAbsoluteForegroundNormal: |
|
203 tp=EThrdPriorityAbsoluteForegroundNormal; break; |
|
204 case EPriorityAbsoluteForeground: |
|
205 tp=EThrdPriorityAbsoluteForeground; break; |
|
206 case EPriorityAbsoluteHighNormal: |
|
207 tp=EThrdPriorityAbsoluteHighNormal; break; |
|
208 case EPriorityAbsoluteHigh: |
|
209 tp=EThrdPriorityAbsoluteHigh; break; |
|
210 case EPriorityAbsoluteRealTime1: |
|
211 tp=EThrdPriorityAbsoluteRealTime1; break; |
|
212 case EPriorityAbsoluteRealTime2: |
|
213 tp=EThrdPriorityAbsoluteRealTime2; break; |
|
214 case EPriorityAbsoluteRealTime3: |
|
215 tp=EThrdPriorityAbsoluteRealTime3; break; |
|
216 case EPriorityAbsoluteRealTime4: |
|
217 tp=EThrdPriorityAbsoluteRealTime4; break; |
|
218 case EPriorityAbsoluteRealTime5: |
|
219 tp=EThrdPriorityAbsoluteRealTime5; break; |
|
220 case EPriorityAbsoluteRealTime6: |
|
221 tp=EThrdPriorityAbsoluteRealTime6; break; |
|
222 case EPriorityAbsoluteRealTime7: |
|
223 tp=EThrdPriorityAbsoluteRealTime7; break; |
|
224 case EPriorityAbsoluteRealTime8: |
|
225 tp=EThrdPriorityAbsoluteRealTime8; break; |
|
226 default: |
|
227 break; |
|
228 } |
|
229 |
|
230 return tp; |
|
231 } |
|
232 |
|
233 |
|
234 void MemSpyDriverUtils::PrintChunkInfo( DChunk& aChunk, DMemSpyDriverOSAdaption& aOSAdaption ) |
|
235 { |
|
236 DMemSpyDriverOSAdaptionDChunk& chunkAdaption = aOSAdaption.DChunk(); |
|
237 // |
|
238 TRACE( Kern::Printf( "MemSpyDriverUtils::PrintChunkInfo() - aChunk->Name: %O", &aChunk ) ); |
|
239 TRACE( Kern::Printf( "MemSpyDriverUtils::PrintChunkInfo() - sizeof(DChunk): %d", sizeof(DChunk) ) ); |
|
240 TRACE( Kern::Printf( "MemSpyDriverUtils::PrintChunkInfo() - aChunk*: 0x%08x", &aChunk ) ); |
|
241 |
|
242 DObject* owner = chunkAdaption.GetOwner( aChunk ); |
|
243 TRACE( Kern::Printf( "MemSpyDriverUtils::PrintChunkInfo() - aChunk->Owner(): 0x%08x", owner ) ); |
|
244 |
|
245 if ( owner ) |
|
246 { |
|
247 const TObjectType objectType = chunkAdaption.GetObjectType( *owner ); |
|
248 if ( objectType == EProcess ) |
|
249 { |
|
250 DProcess* ownerProc = (DProcess*) owner; |
|
251 const TUint pid = aOSAdaption.DProcess().GetId( *ownerProc ); |
|
252 TRACE( Kern::Printf( "MemSpyDriverUtils::PrintChunkInfo() - aChunk->Owner()->Id: %d (%O)", pid, ownerProc ) ); |
|
253 } |
|
254 } |
|
255 |
|
256 DProcess* owningProcess = chunkAdaption.GetOwningProcess( aChunk ); |
|
257 TRACE( Kern::Printf( "MemSpyDriverUtils::PrintChunkInfo() - iOwningProcess: 0x%08x (%O)", owningProcess, owningProcess ) ); |
|
258 |
|
259 const TUint controllingOwner = chunkAdaption.GetControllingOwnerId( aChunk ); |
|
260 TRACE( Kern::Printf( "MemSpyDriverUtils::PrintChunkInfo() - iControllingOwner: %d", controllingOwner ) ); |
|
261 |
|
262 const TInt attribs = chunkAdaption.GetAttributes( aChunk ); |
|
263 TRACE( Kern::Printf( "MemSpyDriverUtils::PrintChunkInfo() - iAttributes: 0x%08x", attribs ) ); |
|
264 |
|
265 const TChunkType type = chunkAdaption.GetType( aChunk ); |
|
266 TRACE( Kern::Printf( "MemSpyDriverUtils::PrintChunkInfo() - iChunkType: %d", type ) ); |
|
267 |
|
268 const TUint8* base = chunkAdaption.GetBase( aChunk ); |
|
269 TRACE( Kern::Printf( "MemSpyDriverUtils::PrintChunkInfo() - aChunk->Base: 0x%08x", base ) ); |
|
270 |
|
271 const TInt size = chunkAdaption.GetSize( aChunk ); |
|
272 TRACE( Kern::Printf( "MemSpyDriverUtils::PrintChunkInfo() - aChunk->Size: 0x%08x", size ) ); |
|
273 // |
|
274 const TInt mapType = attribs & 0x00c00000; // DMemModelChunk::EMapTypeMask |
|
275 switch( mapType ) |
|
276 { |
|
277 case 0x00000000: // EMapTypeLocal |
|
278 TRACE( Kern::Printf( "MemSpyDriverUtils::PrintChunkInfo() - map type: DMemModelChunk::EMapTypeLocal" ) ); |
|
279 break; |
|
280 case 0x00400000: // EMapTypeGlobal |
|
281 TRACE( Kern::Printf( "MemSpyDriverUtils::PrintChunkInfo() - map type: DMemModelChunk::EMapTypeGlobal" ) ); |
|
282 break; |
|
283 case 0x00800000: // EMapTypeShared |
|
284 TRACE( Kern::Printf( "MemSpyDriverUtils::PrintChunkInfo() - map type: DMemModelChunk::EMapTypeShared" ) ); |
|
285 break; |
|
286 default: |
|
287 TRACE( Kern::Printf( "MemSpyDriverUtils::PrintChunkInfo() - map type: UNKNOWN!" ) ); |
|
288 break; |
|
289 } |
|
290 // |
|
291 const TInt addressRange = ( attribs & 0x0f000000 ); // EAddressRangeMask |
|
292 switch (addressRange) |
|
293 { |
|
294 case 0x00000000: //EAddressLocal |
|
295 TRACE( Kern::Printf( "MemSpyDriverUtils::PrintChunkInfo() - address range: DMemModelChunk::EAddressLocal" ) ); |
|
296 break; |
|
297 case 0x01000000: //EAddressShared |
|
298 TRACE( Kern::Printf( "MemSpyDriverUtils::PrintChunkInfo() - address range: DMemModelChunk::EAddressShared" ) ); |
|
299 break; |
|
300 case 0x02000000: //EAddressUserGlobal |
|
301 TRACE( Kern::Printf( "MemSpyDriverUtils::PrintChunkInfo() - address range: DMemModelChunk::EAddressUserGlobal" ) ); |
|
302 break; |
|
303 case 0x03000000: //EAddressKernel |
|
304 TRACE( Kern::Printf( "MemSpyDriverUtils::PrintChunkInfo() - address range: DMemModelChunk::EAddressKernel" ) ); |
|
305 break; |
|
306 case 0x04000000: //EAddressFixed |
|
307 TRACE( Kern::Printf( "MemSpyDriverUtils::PrintChunkInfo() - address range: DMemModelChunk::EAddressFixed" ) ); |
|
308 break; |
|
309 default: |
|
310 TRACE( Kern::Printf( "MemSpyDriverUtils::PrintChunkInfo() - address range: UNKNOWN!" ) ); |
|
311 break; |
|
312 } |
|
313 } |
|
314 |
|