0
|
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".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// e32test\debug\d_codemodifier.cpp
|
|
15 |
// See e32test\debug\t_codemodifier.cpp for details
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
#include "d_codemodifier.h"
|
|
20 |
#include <kernel/kern_priv.h>
|
|
21 |
#include <kernel/cache.h>
|
|
22 |
|
|
23 |
class DCodeModifier : public DLogicalChannelBase
|
|
24 |
{
|
|
25 |
public:
|
|
26 |
DCodeModifier();
|
|
27 |
~DCodeModifier();
|
|
28 |
static TBool Handler (const TDesC8& aText, TTraceSource aTraceSource);
|
|
29 |
protected:
|
|
30 |
virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
|
|
31 |
virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2);
|
|
32 |
private:
|
|
33 |
DThread* iThread[2];
|
|
34 |
};
|
|
35 |
|
|
36 |
DCodeModifier* CodeModifierDriver;
|
|
37 |
|
|
38 |
DCodeModifier::DCodeModifier()
|
|
39 |
{
|
|
40 |
}
|
|
41 |
|
|
42 |
DCodeModifier::~DCodeModifier()
|
|
43 |
{
|
|
44 |
CodeModifierDriver = NULL;
|
|
45 |
}
|
|
46 |
|
|
47 |
|
|
48 |
/**Creates the channel*/
|
|
49 |
TInt DCodeModifier::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& /*aVer*/)
|
|
50 |
{
|
|
51 |
return KErrNone;
|
|
52 |
}
|
|
53 |
|
|
54 |
/**User side request entry point.*/
|
|
55 |
TInt DCodeModifier::Request(TInt aFunction, TAny* a1, TAny* a2)
|
|
56 |
{
|
|
57 |
TInt r = KErrNone;
|
|
58 |
RCodeModifierDevice::TData data;
|
|
59 |
|
|
60 |
kumemget(&data,a1,sizeof(data));
|
|
61 |
switch (aFunction)
|
|
62 |
{
|
|
63 |
case RCodeModifierDevice::EControlThreadId:
|
|
64 |
{
|
|
65 |
DObjectCon* threads=Kern::Containers()[EThread];
|
|
66 |
NKern::ThreadEnterCS();
|
|
67 |
threads->Wait();
|
|
68 |
iThread[data.iServer]=Kern::ThreadFromId(data.iThreadId);
|
|
69 |
if(!iThread[data.iServer])
|
|
70 |
r=KErrNotFound;
|
|
71 |
threads->Signal();
|
|
72 |
NKern::ThreadLeaveCS();
|
|
73 |
}
|
|
74 |
break;
|
|
75 |
|
|
76 |
case RCodeModifierDevice::EControlReadWord:
|
|
77 |
{
|
|
78 |
TInt val;
|
|
79 |
r = Kern::ThreadRawRead(iThread[data.iServer], (const TAny*) data.iAddress, (TAny*) &val, sizeof(TInt));
|
|
80 |
kumemput(a2,&val,sizeof(TInt));
|
|
81 |
}
|
|
82 |
break;
|
|
83 |
|
|
84 |
case RCodeModifierDevice::EControlWriteWord:
|
|
85 |
r = Kern::ThreadRawWrite(iThread[data.iServer], (TAny*)data.iAddress,(const TAny*) &a2, sizeof(TInt));
|
|
86 |
break;
|
|
87 |
|
|
88 |
case RCodeModifierDevice::EControlWriteCode:
|
|
89 |
r = DebugSupport::ModifyCode(iThread[data.iServer], (TLinAddr) data.iAddress, data.iSize, (TUint)a2, DebugSupport::EBreakpointGlobal);
|
|
90 |
if (r == DebugSupport::EBreakpointGlobal)
|
|
91 |
r = KErrNone;
|
|
92 |
break;
|
|
93 |
|
|
94 |
case RCodeModifierDevice::EControlRestoreCode:
|
|
95 |
r = DebugSupport::RestoreCode(iThread[data.iServer], (TLinAddr)data.iAddress);
|
|
96 |
break;
|
|
97 |
|
|
98 |
case RCodeModifierDevice::EInitialiseCodeModifier:
|
|
99 |
{
|
|
100 |
TUint cap;
|
|
101 |
r = DebugSupport::InitialiseCodeModifier(cap,data.iSize);
|
|
102 |
if (r && (cap!=DebugSupport::EBreakpointGlobal))
|
|
103 |
r = KErrGeneral;
|
|
104 |
}
|
|
105 |
break;
|
|
106 |
|
|
107 |
case RCodeModifierDevice::ECloseCodeModifier:
|
|
108 |
DebugSupport::CloseCodeModifier();
|
|
109 |
break;
|
|
110 |
|
|
111 |
case RCodeModifierDevice::EControlAllocShadowPage:
|
|
112 |
NKern::ThreadEnterCS();
|
|
113 |
r = Epoc::AllocShadowPage(data.iAddress & ~(Kern::RoundToPageSize(1)-1));
|
|
114 |
NKern::ThreadLeaveCS();
|
|
115 |
break;
|
|
116 |
|
|
117 |
case RCodeModifierDevice::EControlFreeShadowPage:
|
|
118 |
NKern::ThreadEnterCS();
|
|
119 |
r = Epoc::FreeShadowPage(data.iAddress & ~(Kern::RoundToPageSize(1)-1));
|
|
120 |
NKern::ThreadLeaveCS();
|
|
121 |
break;
|
|
122 |
|
|
123 |
default:
|
|
124 |
r=KErrNotSupported;
|
|
125 |
}
|
|
126 |
return r;
|
|
127 |
}
|
|
128 |
|
|
129 |
//////////////////////////////////////////
|
|
130 |
class DTestFactory : public DLogicalDevice
|
|
131 |
{
|
|
132 |
public:
|
|
133 |
DTestFactory();
|
|
134 |
// from DLogicalDevice
|
|
135 |
virtual TInt Install();
|
|
136 |
virtual void GetCaps(TDes8& aDes) const;
|
|
137 |
virtual TInt Create(DLogicalChannelBase*& aChannel);
|
|
138 |
};
|
|
139 |
|
|
140 |
DTestFactory::DTestFactory()
|
|
141 |
{
|
|
142 |
iParseMask = KDeviceAllowUnit;
|
|
143 |
iUnitsMask = 0x3;
|
|
144 |
}
|
|
145 |
|
|
146 |
TInt DTestFactory::Create(DLogicalChannelBase*& aChannel)
|
|
147 |
{
|
|
148 |
CodeModifierDriver = new DCodeModifier;
|
|
149 |
aChannel = CodeModifierDriver;
|
|
150 |
return (aChannel ? KErrNone : KErrNoMemory);
|
|
151 |
}
|
|
152 |
|
|
153 |
TInt DTestFactory::Install()
|
|
154 |
{
|
|
155 |
return SetName(&KCodeModifierName);
|
|
156 |
}
|
|
157 |
|
|
158 |
void DTestFactory::GetCaps(TDes8& /*aDes*/) const
|
|
159 |
{
|
|
160 |
}
|
|
161 |
|
|
162 |
DECLARE_STANDARD_LDD()
|
|
163 |
{
|
|
164 |
return new DTestFactory;
|
|
165 |
}
|