Update contrib.
1 // Copyright (c) 2005-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\debug\d_debugapi.cpp
15 // LDD-based debug agent. It uses debugAPI provided by kernel extension
16 // kdebug.dll (ARMv5) or kdebugv6 (ARMv6) to access and display various
17 // kernel objects. It uses debug port as output. See t_DebugAPI.cpp
21 #include <kernel/kern_priv.h>
22 #include "d_debugapi.h"
24 _LIT(KClientPanicCat, "D_DEBUGAPI");
25 #define KMaxNameSize 20
27 TInt DDebugAPIChecker::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
29 //This is the entry point for all debuggers. Super page contains the address of DebuggerInfo instance.
30 iDebugInfo = Kern::SuperPage().iDebuggerInfo;
34 Kern::Printf("Error:Debugger is not installed");
37 return GetOffsets(); //Obtain the copy of offsets.
41 Copies the offset tables from Debug API Kernel extension.
43 TInt DDebugAPIChecker::GetOffsets()
45 //Get the memory-model-specific offset table
46 switch (iDebugInfo->iMemoryModelType)
49 iMMUType = iDebugInfo->iMemoryModelType;
50 if ((iVariantOffsetTable = new TMovingDebugOffsetTable)==NULL)
52 memcpy(iVariantOffsetTable, iDebugInfo->iMemModelObjectOffsetTable, sizeof(TMovingDebugOffsetTable));
56 iMMUType = iDebugInfo->iMemoryModelType;
57 if ((iVariantOffsetTable = new TMultipleDebugOffsetTable)==NULL)
59 memcpy(iVariantOffsetTable, iDebugInfo->iMemModelObjectOffsetTable, sizeof(TMultipleDebugOffsetTable));
63 return KErrNotSupported;
66 //Get the main offset table
67 if ((iOffsetTable = new TDebugOffsetTable)==NULL)
69 delete iVariantOffsetTable;
72 memcpy(iOffsetTable, iDebugInfo->iObjectOffsetTable, sizeof(TDebugOffsetTable));
74 //Get the scheduler's address
75 iScheduler = (TInt*)iDebugInfo->iScheduler;
79 DDebugAPIChecker::~DDebugAPIChecker()
81 delete iVariantOffsetTable;
86 Transfer Symbian-like string into C style string.
87 The magic numbers come from descriptor implementation.
88 @param aSymbianName The address of the symbian-like string (TDesC8 type)
89 @param aCharName The address of the C style string
92 TUint8* DDebugAPIChecker::ExtractName(TInt aSymbianName, TUint8* aCharName)
94 if(!aSymbianName) //zero length case
96 aCharName[0] = '*'; aCharName[1] = 0;
99 TInt nameLen = Read((void*)aSymbianName, 0); //The type & length of the desc. is kept in the first word
101 //We actually need only EBuf type of descriptor in this test.
102 if (nameLen >> 28 != 3)
109 nameLen &= 0x0fffffff;
110 const TUint8* namePtr = (TUint8*)(aSymbianName+8);
112 TInt charNameLen = nameLen<(KMaxNameSize-1) ? nameLen : KMaxNameSize-1;
113 memcpy(aCharName, namePtr, charNameLen);
114 aCharName[charNameLen] = 0;
119 Prints the list of processes
121 TInt DDebugAPIChecker::Process()
123 DObjectCon* processCon;
124 TUint8 charName[KMaxNameSize];
126 //Fetch the address of the object container for processes
127 processCon = iDebugInfo->iContainers[EProcess];
129 //Pend on the container's mutex before accessing any data
130 NKern::ThreadEnterCS();
133 TInt containerCount = Read(processCon, iOffsetTable->iObjectCon_Count);
134 TInt** containerObjects = (TInt**)Read(processCon, iOffsetTable->iObjectCon_Objects);
136 Kern::Printf("PROCESS TABLE:");
137 Kern::Printf("Id attribut codeSeg BccRunAd DatBssSC Name");
138 for (TInt i = 0; i < containerCount; i++)
140 TInt* process = containerObjects[i];
141 TInt processId = Read(process, iOffsetTable->iProcess_Id);
142 TInt processAttributes = Read(process, iOffsetTable->iProcess_Attributes);
143 TInt processCodeSeg = Read(process, iOffsetTable->iProcess_CodeSeg);
144 TInt processCBssRunAddress = Read(process, iOffsetTable->iProcess_DataBssRunAddress);
145 TInt processDataBssStackChunk = Read(process, iOffsetTable->iProcess_DataBssStackChunk);
146 TInt processName = Read(process, iOffsetTable->iProcess_Name);
148 Kern::Printf("%02x %08x %08x %08x %08x %s",
152 processCBssRunAddress,
153 processDataBssStackChunk,
154 ExtractName(processName, charName));
157 //Release container's mutex
158 processCon->Signal();
159 NKern::ThreadLeaveCS();
166 Prints the list of chunks
168 TInt DDebugAPIChecker::Chunk()
172 TInt* owningProcess = (TInt*)-1;
174 DObjectCon* processCon;
175 TUint8 charName[KMaxNameSize];
177 //Fetch the address of the object container for processes
178 processCon = iDebugInfo->iContainers[EChunk];
180 //Pend on the container's mutex before accessing any data.
181 NKern::ThreadEnterCS();
184 TInt containerCount = Read(processCon, iOffsetTable->iObjectCon_Count);
185 TInt** containerObjects = (TInt**)Read(processCon, iOffsetTable->iObjectCon_Objects);
187 Kern::Printf("CHUNK TABLE:");
188 Kern::Printf("size attribut type state HomeBase process");
189 for (TInt i = 0; i < containerCount; i++)
191 TInt* chunk = containerObjects[i];
192 TInt size = Read(chunk, iOffsetTable->iChunk_Size);
193 TInt attributes = Read(chunk, iOffsetTable->iChunk_Attributes);
194 TInt type = Read(chunk, iOffsetTable->iChunk_ChunkType);
196 //This part is memory-model specific
197 switch (iDebugInfo->iMemoryModelType)
201 TMovingDebugOffsetTable* variantOffsets = (TMovingDebugOffsetTable*)iVariantOffsetTable;
202 state = Read(chunk, iOffsetTable->iChunk_ChunkState);//armv5 specific
203 homeBase = Read(chunk, iOffsetTable->iChunk_HomeBase);//armv5 specific
204 owningProcess = (TInt*)Read(chunk, iOffsetTable->iChunk_OwningProcess);//armv5
206 //In moving MM, the specific offsets are provided in both tables. Check the values match.
207 if ( state != Read(chunk, variantOffsets->iChunk_ChunkState)
208 || homeBase != Read(chunk, variantOffsets->iChunk_HomeBase)
209 || owningProcess != (TInt*)Read(chunk, variantOffsets->iChunk_OwningProcess) )
211 Kern::Printf("Error: Offsets in main & specific table do not match");
219 TMultipleDebugOffsetTable* variantOffsets = (TMultipleDebugOffsetTable*)iVariantOffsetTable;
220 owningProcess = (TInt*)Read(chunk, variantOffsets->iChunk_OwningProcess);
224 Kern::Printf("Error: Unsupported memory model");
230 processName = Read(owningProcess, iOffsetTable->iProcess_Name);
234 Kern::Printf("%08x %08x %08x %08x %08x %s",
240 ExtractName(processName, charName));
243 //Release container's mutex
244 processCon->Signal();
245 NKern::ThreadLeaveCS();
251 Prints the list of threads
253 TInt DDebugAPIChecker::Thread()
256 DObjectCon* processCon;
257 TUint8 threadCharName[KMaxNameSize];
258 TUint8 processCharName[KMaxNameSize];
260 //Fetch the address of the object container for threads
261 processCon = iDebugInfo->iContainers[EThread];
263 //Pend on the container's mutex before accessing any data
264 NKern::ThreadEnterCS();
267 TInt containerCount = Read(processCon, iOffsetTable->iObjectCon_Count);
268 TInt** containerObjects = (TInt**)Read(processCon, iOffsetTable->iObjectCon_Objects);
270 Kern::Printf("THREAD TABLE:");
271 Kern::Printf("Id Pri Typ SupStack+Size UsrStack+Size ContType SavedSP ThreadName Process");
273 for (TInt i = 0; i < containerCount; i++)
275 TInt* thread = containerObjects[i];
276 TInt id = Read(thread, iOffsetTable->iThread_Id);
277 TInt supStack = Read(thread, iOffsetTable->iThread_SupervisorStack);
278 TInt supStackSize = Read(thread, iOffsetTable->iThread_SupervisorStackSize);
279 TInt userStackRunAddr = Read(thread, iOffsetTable->iThread_UserStackRunAddress);
280 TInt userStackSize = Read(thread, iOffsetTable->iThread_UserStackSize);
281 TInt userContextType = Read8(thread, iOffsetTable->iThread_UserContextType);
283 TInt savedSP = Read(thread, iOffsetTable->iThread_SavedSupervisorSP);
284 TInt priority = Read8(thread, iOffsetTable->iThread_Priority);
285 TInt type = Read8(thread, iOffsetTable->iThread_ThreadType);
286 TInt name = Read(thread, iOffsetTable->iThread_Name);
287 TInt* owningProcess = (TInt*)Read(thread, iOffsetTable->iThread_OwningProcess);
289 TInt processName = Read(owningProcess, iOffsetTable->iProcess_Name);
291 Kern::Printf("%02x %3x %3x %08x %04x %08x %04x %08x %08x %14s %s",
301 ExtractName(name, threadCharName),
302 ExtractName(processName, processCharName)
306 //Release container's mutex
307 processCon->Signal();
308 NKern::ThreadLeaveCS();
314 Reads memory location that belongs to the other process and compares the value with provided one.
315 The input argument contains the following data:
316 - ProcessId of the process that owns the address space in question
317 - Address of memory location to be read.
318 - The value at the location.
320 TInt DDebugAPIChecker::IPAccess(TAny* a1)
323 TInt otherProcess = 0;
324 TBool processFound = EFalse;
325 TBool currentProcessFound = EFalse;
326 DObjectCon* processCon;
328 RDebugAPIChecker::IPAccessArgs args;
329 kumemget32 (&args, a1, sizeof(args));
331 //Find the addresses of the current nano-thread & SymbianOS-thread
332 TInt currentNThread = Read(iScheduler, iOffsetTable->iScheduler_CurrentThread);
333 TInt currentDThread = currentNThread - iOffsetTable->iThread_NThread;
335 //Find the addresses of the current process
336 TInt currentProcess = Read((void*)currentDThread, iOffsetTable->iThread_OwningProcess);
338 //Find process in the container with given processID
339 processCon = iDebugInfo->iContainers[EProcess];
341 //Pend on the container's mutex before accessing any data
342 NKern::ThreadEnterCS();
345 TInt containerCount = Read(processCon, iOffsetTable->iObjectCon_Count);
346 TInt** containerObjects = (TInt**)Read(processCon, iOffsetTable->iObjectCon_Objects);
348 for (TInt i = 0; i < containerCount; i++)
350 process = containerObjects[i];
351 TInt processId = Read(process, iOffsetTable->iProcess_Id);
353 if (currentProcess == (TInt)process)
354 currentProcessFound = ETrue;
356 if (processId == (TInt)args.iProcessID)
358 otherProcess = (TInt)process;
359 processFound = ETrue;
363 if(!(processFound && currentProcessFound))
365 Kern::Printf("Could not find the-current-process or the-other-process in the process container");
366 processCon->Signal();
367 NKern::ThreadLeaveCS();
371 //Release container's mutex
372 processCon->Signal();
373 NKern::ThreadLeaveCS();
379 TMultipleDebugOffsetTable* variantOffsets = (TMultipleDebugOffsetTable*)iVariantOffsetTable;
380 iCurrentProcess_OsAsid = Read((void*)currentProcess, variantOffsets->iProcess_OsAsid);
381 iCurrentProcess_LocalPageDir = Read((void*)currentProcess, variantOffsets->iProcess_LocalPageDir);
382 iOtherProcess_OsAsid = Read((void*)otherProcess, variantOffsets->iProcess_OsAsid);
383 iOtherProcess_LocalPageDir = Read((void*)otherProcess, variantOffsets->iProcess_LocalPageDir);
384 iAddress = args.iAddress;
386 TUint r = ReadFromOtherProcessArmv6();
388 //Chech if the value we just read matches the provided value.
389 if ( r != args.iValue)
391 Kern::Printf("Returned value does not match");
397 return KErrNotSupported;
403 TInt DDebugAPIChecker::Request(TInt aFunction, TAny* a1, TAny* /*a2*/)
408 case RDebugAPIChecker::ETProcess:
412 case RDebugAPIChecker::ETChunk:
416 case RDebugAPIChecker::ETThread:
420 case RDebugAPIChecker::ETIPAccess:
425 Kern::PanicCurrentThread(KClientPanicCat, __LINE__);
431 //////////////////////////////////////////////////////////////////////////////
433 class DTestFactory : public DLogicalDevice
437 // from DLogicalDevice
438 virtual TInt Install();
439 virtual void GetCaps(TDes8& aDes) const;
440 virtual TInt Create(DLogicalChannelBase*& aChannel);
443 DTestFactory::DTestFactory()
445 iVersion = RDebugAPIChecker::Version();
446 iParseMask = KDeviceAllowUnit;
450 TInt DTestFactory::Create(DLogicalChannelBase*& aChannel)
452 aChannel = new DDebugAPIChecker;
453 return (aChannel ? KErrNone : KErrNoMemory);
456 TInt DTestFactory::Install()
458 return SetName(&KTestLddName);
461 void DTestFactory::GetCaps(TDes8& /*aDes*/) const
465 //////////////////////////////////////////////////////////////////////////////
467 DECLARE_STANDARD_LDD()
469 return new DTestFactory;