author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 02 Sep 2010 21:54:16 +0300 | |
changeset 259 | 57b9594f5772 |
parent 0 | a41df078684a |
child 257 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1 |
// Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 |
// Stop-mode debug interface implementation as defined in sm_debug_api.h |
|
15 |
// |
|
16 |
||
17 |
/** |
|
18 |
* @file |
|
19 |
* @internalComponent |
|
20 |
* @prototype |
|
21 |
*/ |
|
22 |
||
23 |
#include <sm_debug_api.h> |
|
24 |
||
25 |
using namespace Debug; |
|
26 |
||
27 |
/** |
|
28 |
* Stop Mode routine to retrieve the code seg list and place it in the response buffer |
|
29 |
* @param aItem List item describing the list |
|
30 |
* @return One of the system wide error codes |
|
31 |
*/ |
|
32 |
TInt StopModeDebug::GetCodeSegList(const TListItem* aItem, bool aCheckConsistent) |
|
33 |
{ |
|
34 |
if(aCheckConsistent) |
|
35 |
{ |
|
36 |
DMutex* codeMutex = Kern::CodeSegLock(); |
|
37 |
if(!codeMutex || codeMutex->iHoldCount) |
|
38 |
{ |
|
39 |
return ExitPoint(KErrNotReady); |
|
40 |
} |
|
41 |
} |
|
42 |
||
43 |
TUint8* bufferInitial = (TUint8*)aItem->iBufferAddress; |
|
44 |
TUint8* buffer = (TUint8*)aItem->iBufferAddress + 12; |
|
45 |
TUint32 bufferSize = aItem->iBufferSize; |
|
46 |
||
47 |
TUint32* buffer32 = (TUint32*)aItem->iBufferAddress; |
|
48 |
*buffer32 = (TUint32)aItem; |
|
49 |
TUint32* size = buffer32+1; |
|
50 |
*size = 12; |
|
51 |
TUint32* nextElementSize = buffer32+2; |
|
52 |
*nextElementSize = 0; |
|
53 |
TUint32 start = aItem->iStartElement; |
|
54 |
||
55 |
while(1) |
|
56 |
{ |
|
57 |
DEpocCodeSeg* codeSeg = GetNextCodeSeg(start, aItem->iListScope, aItem->iScopeData); |
|
58 |
if(!codeSeg) |
|
59 |
{ |
|
60 |
*size = buffer-bufferInitial; |
|
61 |
return KErrNone; // we're done |
|
62 |
} |
|
63 |
start = (TUint32)codeSeg + 1; |
|
64 |
||
65 |
TInt ret = ProcessCodeSeg(buffer, bufferSize, codeSeg); |
|
66 |
if(KErrNone != ret) |
|
67 |
{ |
|
68 |
if(ret > 0) |
|
69 |
{ |
|
70 |
Kern::Printf("Next element is %d bytes big\n", ret); |
|
71 |
*nextElementSize = ret; |
|
72 |
ret = KErrTooBig; |
|
73 |
} |
|
74 |
*size = buffer-bufferInitial; |
|
75 |
return ret; |
|
76 |
} |
|
77 |
} |
|
78 |
} |
|
79 |
||
80 |
DEpocCodeSeg* StopModeDebug::GetNextCodeSeg(const TUint32 aStart, const TListScope aListScope, const TUint64 aScopeData) |
|
81 |
{ |
|
82 |
switch(aListScope) |
|
83 |
{ |
|
84 |
case EScopeGlobal: |
|
85 |
return GetNextGlobalCodeSeg(aStart); |
|
86 |
case EScopeThreadSpecific: |
|
87 |
return GetNextThreadSpecificCodeSeg(aStart, aScopeData); |
|
88 |
default: |
|
89 |
return NULL; |
|
90 |
} |
|
91 |
} |
|
92 |
||
93 |
DEpocCodeSeg* StopModeDebug::GetNextThreadSpecificCodeSeg(const TUint32 aStart, const TUint64 aThreadId) |
|
94 |
{ |
|
95 |
return NULL; |
|
96 |
} |
|
97 |
||
98 |
DEpocCodeSeg* StopModeDebug::GetNextGlobalCodeSeg(const TUint32 aStart) |
|
99 |
{ |
|
100 |
//get global code seg list |
|
101 |
SDblQue* codeSegList = Kern::CodeSegList(); |
|
102 |
||
103 |
DEpocCodeSeg* codeSeg = NULL; |
|
104 |
for (SDblQueLink* codeSegPtr= codeSegList->First(); codeSegPtr!=(SDblQueLink*) (codeSegList); codeSegPtr=codeSegPtr->iNext) |
|
105 |
{ |
|
106 |
DEpocCodeSeg* tempCodeSeg = (DEpocCodeSeg*)_LOFF(codeSegPtr,DCodeSeg, iLink); |
|
107 |
if((TUint32)tempCodeSeg >= aStart) |
|
108 |
{ |
|
109 |
if(!codeSeg || tempCodeSeg < codeSeg) |
|
110 |
{ |
|
111 |
codeSeg = tempCodeSeg; |
|
112 |
} |
|
113 |
} |
|
114 |
} |
|
115 |
return codeSeg; |
|
116 |
} |
|
117 |
||
118 |
TInt StopModeDebug::ProcessCodeSeg(TUint8*& aBuffer, TUint32& aBufferSize, DEpocCodeSeg* aCodeSeg) |
|
119 |
{ |
|
120 |
//create a memory info object for use in the loop |
|
121 |
TModuleMemoryInfo memoryInfo; |
|
122 |
||
123 |
//get the memory info |
|
124 |
TInt err = aCodeSeg->GetMemoryInfo(memoryInfo, NULL); |
|
125 |
if(err != KErrNone) |
|
126 |
{ |
|
127 |
//there's been an error so return it |
|
128 |
return err; |
|
129 |
} |
|
130 |
//calculate data values |
|
131 |
TFileName fileName(aCodeSeg->iFileName->Ptr()); |
|
132 |
TBool isXip = (aCodeSeg->iXIP) ? ETrue : EFalse; |
|
133 |
||
134 |
//get the code seg type |
|
135 |
TCodeSegType type = |
|
136 |
aCodeSeg->IsExe() ? EExeCodeSegType : |
|
137 |
aCodeSeg->IsDll() ? EDllCodeSegType : |
|
138 |
EUnknownCodeSegType; |
|
139 |
||
140 |
//append data to buffer |
|
141 |
return AppendCodeSegData(aBuffer, aBufferSize, memoryInfo, isXip, type, fileName, aCodeSeg); |
|
142 |
} |
|
143 |
||
144 |
TInt StopModeDebug::AppendCodeSegData(TUint8*& aBuffer, TUint32& aBufferSize, const TModuleMemoryInfo& aMemoryInfo, const TBool aIsXip, const TCodeSegType aCodeSegType, const TDesC8& aFileName, DEpocCodeSeg* aCodeSeg) |
|
145 |
{ |
|
146 |
//get some data elements to put in buffer |
|
147 |
TUint16 fileNameLength = aFileName.Length(); |
|
148 |
||
149 |
//calculate the resultant size |
|
150 |
TUint dataSize = Align4(sizeof(TCodeSegListEntry) + (2*fileNameLength) - sizeof(TUint16)); |
|
151 |
if(dataSize > aBufferSize) |
|
152 |
{ |
|
153 |
// data won't fit in the buffer so quit |
|
154 |
return dataSize; |
|
155 |
} |
|
156 |
//Create a TCodeSegListEntry which references the buffer. |
|
157 |
TCodeSegListEntry& entry = *(TCodeSegListEntry*)aBuffer; |
|
158 |
entry.iCodeBase = aMemoryInfo.iCodeBase; |
|
159 |
entry.iCodeSize = aMemoryInfo.iCodeSize; |
|
160 |
entry.iConstDataSize = aMemoryInfo.iConstDataSize; |
|
161 |
entry.iInitialisedDataBase = aMemoryInfo.iInitialisedDataBase; |
|
162 |
entry.iInitialisedDataSize = aMemoryInfo.iInitialisedDataSize; |
|
163 |
entry.iUninitialisedDataSize = aMemoryInfo.iUninitialisedDataSize; |
|
164 |
entry.iIsXip = aIsXip; |
|
165 |
entry.iCodeSegType = aCodeSegType; |
|
166 |
entry.iNameLength = fileNameLength; |
|
167 |
//entry.iSpare1 = (TUint32)aCodeSeg; |
|
168 |
||
169 |
//have to convert the stored name to 16 bit Unicode |
|
170 |
TPtr name = TPtr((TUint8*)&(entry.iName[0]), fileNameLength*2, fileNameLength*2); |
|
171 |
TInt err = CopyAndExpandDes(aFileName, name); |
|
172 |
if(err != KErrNone) |
|
173 |
{ |
|
174 |
return KErrGeneral; |
|
175 |
} |
|
176 |
||
177 |
//increase length |
|
178 |
aBufferSize-=dataSize; |
|
179 |
aBuffer+=dataSize; |
|
180 |
return KErrNone; |
|
181 |
} |
|
182 |