Update contrib.
1 // Copyright (c) 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 // Stop-mode debug interface implementation as defined in sm_debug_api.h
23 #ifdef __LAUNCH_AS_EXTENSION__
25 #include <rm_debug_api.h>
26 #include <sm_debug_api.h>
27 #include "d_rmd_breakpoints.h"
29 using namespace Debug;
32 * Stop Mode routine to retrieve the code seg list and place it in the response buffer
33 * @param aItem List item describing the list
34 * @return One of the system wide error codes
36 TInt StopModeDebug::GetCodeSegList(const TListItem* aItem, bool aCheckConsistent)
40 DMutex* codeMutex = Kern::CodeSegLock();
41 if(!codeMutex || codeMutex->iHoldCount)
43 return ExitPoint(KErrNotReady);
47 TUint8* bufferInitial = (TUint8*)aItem->iBufferAddress;
48 TUint8* buffer = (TUint8*)aItem->iBufferAddress + 12;
49 TUint32 bufferSize = aItem->iBufferSize;
51 TUint32* buffer32 = (TUint32*)aItem->iBufferAddress;
52 *buffer32 = (TUint32)aItem;
53 TUint32* size = buffer32+1;
55 TUint32* nextElementSize = buffer32+2;
57 TUint32 start = aItem->iStartElement;
61 DEpocCodeSeg* codeSeg = GetNextCodeSeg(start, aItem->iListScope, aItem->iScopeData);
64 *size = buffer-bufferInitial;
65 return KErrNone; // we're done
67 start = (TUint32)codeSeg + 1;
69 TInt ret = ProcessCodeSeg(buffer, bufferSize, codeSeg);
74 Kern::Printf("Next element is %d bytes big\n", ret);
75 *nextElementSize = ret;
78 *size = buffer-bufferInitial;
84 DEpocCodeSeg* StopModeDebug::GetNextCodeSeg(const TUint32 aStart, const TListScope aListScope, const TUint64 aScopeData)
89 return GetNextGlobalCodeSeg(aStart);
90 case EScopeThreadSpecific:
91 return GetNextThreadSpecificCodeSeg(aStart, aScopeData);
97 DEpocCodeSeg* StopModeDebug::GetNextThreadSpecificCodeSeg(const TUint32 aStart, const TUint64 aThreadId)
102 DEpocCodeSeg* StopModeDebug::GetNextGlobalCodeSeg(const TUint32 aStart)
104 //get global code seg list
105 SDblQue* codeSegList = Kern::CodeSegList();
107 DEpocCodeSeg* codeSeg = NULL;
108 for (SDblQueLink* codeSegPtr= codeSegList->First(); codeSegPtr!=(SDblQueLink*) (codeSegList); codeSegPtr=codeSegPtr->iNext)
110 DEpocCodeSeg* tempCodeSeg = (DEpocCodeSeg*)_LOFF(codeSegPtr,DCodeSeg, iLink);
111 if((TUint32)tempCodeSeg >= aStart)
113 if(!codeSeg || tempCodeSeg < codeSeg)
115 codeSeg = tempCodeSeg;
122 TInt StopModeDebug::ProcessCodeSeg(TUint8*& aBuffer, TUint32& aBufferSize, DEpocCodeSeg* aCodeSeg)
124 //create a memory info object for use in the loop
125 TModuleMemoryInfo memoryInfo;
127 //get the memory info
128 TInt err = aCodeSeg->GetMemoryInfo(memoryInfo, NULL);
131 //there's been an error so return it
134 //calculate data values
135 TFileName fileName(aCodeSeg->iFileName->Ptr());
136 TBool isXip = (aCodeSeg->iXIP) ? ETrue : EFalse;
138 //get the code seg type
140 aCodeSeg->IsExe() ? EExeCodeSegType :
141 aCodeSeg->IsDll() ? EDllCodeSegType :
144 //append data to buffer
145 return AppendCodeSegData(aBuffer, aBufferSize, memoryInfo, isXip, type, fileName, aCodeSeg);
148 TInt StopModeDebug::AppendCodeSegData(TUint8*& aBuffer, TUint32& aBufferSize, const TModuleMemoryInfo& aMemoryInfo, const TBool aIsXip, const TCodeSegType aCodeSegType, const TDesC8& aFileName, DEpocCodeSeg* aCodeSeg)
150 //get some data elements to put in buffer
151 TUint16 fileNameLength = aFileName.Length();
153 //calculate the resultant size
154 TUint dataSize = Align4(sizeof(TCodeSegListEntry) + (2*fileNameLength) - sizeof(TUint16));
155 if(dataSize > aBufferSize)
157 // data won't fit in the buffer so quit
160 //Create a TCodeSegListEntry which references the buffer.
161 TCodeSegListEntry& entry = *(TCodeSegListEntry*)aBuffer;
162 entry.iCodeBase = aMemoryInfo.iCodeBase;
163 entry.iCodeSize = aMemoryInfo.iCodeSize;
164 entry.iConstDataSize = aMemoryInfo.iConstDataSize;
165 entry.iInitialisedDataBase = aMemoryInfo.iInitialisedDataBase;
166 entry.iInitialisedDataSize = aMemoryInfo.iInitialisedDataSize;
167 entry.iUninitialisedDataSize = aMemoryInfo.iUninitialisedDataSize;
168 entry.iIsXip = aIsXip;
169 entry.iCodeSegType = aCodeSegType;
170 entry.iNameLength = fileNameLength;
171 //entry.iSpare1 = (TUint32)aCodeSeg;
173 //have to convert the stored name to 16 bit Unicode
174 TPtr name = TPtr((TUint8*)&(entry.iName[0]), fileNameLength*2, fileNameLength*2);
175 TInt err = CopyAndExpandDes(aFileName, name);
182 aBufferSize-=dataSize;