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