Update contrib.
1 // Copyright (c) 2006-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 // Provides the debug agent server implementation.
19 #include <e32base_private.h>
21 #include <trkkerneldriver.h>
22 #include "d_rmdebugserver.h"
23 #include "d_rmdebugclient.h"
24 #include "t_rmdebug.h"
27 CDebugServServer::CDebugServServer(CActive::TPriority aActiveObjectPriority)
28 : CServer2(aActiveObjectPriority)
35 CSession2* CDebugServServer::NewSessionL(const TVersion& /*aVersion*/, const RMessage2& /*aMessage*/) const
37 // Session constructor
40 // make sure the kernel side device driver is not already loaded
42 err = User::LoadLogicalDevice(KDebugDriverFileName);
43 if ((KErrNone == err) || (KErrAlreadyExists == err))
45 return new(ELeave) CDebugServSession();
53 CDebugServSession::CDebugServSession()
54 // Session implementation
57 TMetroTrkDriverInfo info;
58 info.iUserLibraryEnd = 0;
59 err = iKernelDriver.Open(info);
66 CDebugServSession::~CDebugServSession()
71 // stop the kernel side driver
72 iKernelDriver.Close();
74 User::FreeLogicalDevice(KDebugDriverName);
78 void CDebugServSession::ServiceL(const RMessage2& aMessage)
80 // Session service handler
85 switch(aMessage.Function())
87 case EDebugServResumeThread:
88 res = ResumeThread(aMessage);
91 case EDebugServSuspendThread:
92 res = SuspendThread(aMessage);
95 // case EDebugServReadProcessInfo:
96 // res = ReadProcessInfo(aMessage);
99 // case EDebugServReadThreadInfo:
100 // res = ReadThreadInfo(aMessage);
103 case EDebugServReadMemory:
104 res = ReadMemory(aMessage);
107 case EDebugServWriteMemory:
108 res = WriteMemory(aMessage);
112 User::Leave(KErrNotSupported);
116 aMessage.Complete(res);
121 TInt CDebugServSession::SuspendThread(const RMessage2& aMessage)
123 // Session suspend thread
128 err = iKernelDriver.SuspendThread(aMessage.Int0());
133 TInt CDebugServSession::ResumeThread(const RMessage2& aMessage)
135 // Server resume thread
140 err = iKernelDriver.ResumeThread(aMessage.Int0());
145 //TInt CDebugServSession::ReadProcessInfo(const RMessage2& aMessage)
147 //// Server read process information
151 // TProcessInfo procinfo;
152 // TMetroTrkTaskInfo processInfo(0);
154 // err = iKernelDriver.GetProcessInfo(aMessage.Int0(), processInfo);
156 // if (KErrNone == err)
158 // procinfo.iProcessID = processInfo.iId;
159 // procinfo.iPriority = processInfo.iPriority;
160 // procinfo.iName.Copy(processInfo.iName);
162 // TPckgBuf<TProcessInfo> p(procinfo);
163 // aMessage.WriteL(1,p);
169 //TInt CDebugServSession::ReadThreadInfo(const RMessage2& aMessage)
171 //// Server read thread information
175 // TThreadInfo thrdinfo;
176 // TMetroTrkTaskInfo threadInfo(aMessage.Int1()); // Sets OtherID to the second input parameter in aMessage
178 // // aMessage.Int0 is the index into the thread list for the process
179 // err = iKernelDriver.GetThreadInfo(aMessage.Int0(), threadInfo);
181 // if (KErrNone == err)
183 // thrdinfo.iThreadID = threadInfo.iId;
184 // thrdinfo.iPriority = threadInfo.iPriority;
185 // thrdinfo.iName.Copy(threadInfo.iName);
186 // thrdinfo.iOwningProcessID = threadInfo.iOtherId;
188 // TPckgBuf<TThreadInfo> p(thrdinfo);
190 // // Write out the results to the third argument passed in (pointer to the threadinfo structure)
191 // aMessage.WriteL(2,p);
197 TInt CDebugServSession::ReadMemory(const RMessage2& aMessage)
199 // Server read process memory
203 TUint32 threadId = aMessage.Int0();
204 TPckgBuf<TMemoryInfo> pckg = *(TPckgBuf<TMemoryInfo> *)(aMessage.Ptr1());
205 TMemoryInfo* InputMemoryInfo = &pckg();
207 TPtr8 *ptrtst = InputMemoryInfo->iDataPtr;
209 err = iKernelDriver.ReadMemory(threadId, InputMemoryInfo->iAddress, InputMemoryInfo->iSize, *ptrtst);
214 TInt CDebugServSession::WriteMemory(const RMessage2& aMessage)
216 // Server write process memory
220 TUint32 threadId = aMessage.Int0();
221 TPckgBuf<TMemoryInfo> pckg = *(TPckgBuf<TMemoryInfo> *)(aMessage.Ptr1());
222 TMemoryInfo* InputMemoryInfo = &pckg();
224 TPtr8 *ptrtst = InputMemoryInfo->iDataPtr;
226 err = iKernelDriver.WriteMemory(threadId, InputMemoryInfo->iAddress, InputMemoryInfo->iSize, *ptrtst);
232 GLDEF_C TInt CDebugServServer::ThreadFunction(TAny*)
234 // Server thread function, continues until active scheduler stops
237 CTrapCleanup* cleanup=CTrapCleanup::New();
240 User::Leave(KErrNoMemory);
243 CActiveScheduler *pA=new CActiveScheduler;
244 CDebugServServer *pS=new CDebugServServer(EPriorityStandard);
246 CActiveScheduler::Install(pA);
248 TInt err = pS->Start(KDebugServerName);
251 User::Leave(KErrNone);
254 RThread::Rendezvous(KErrNone);
256 CActiveScheduler::Start();
267 EXPORT_C TInt StartThread(RThread& aServerThread)
269 // Start the server thread
274 TFindServer finddebugserver(KDebugServerName);
277 if (finddebugserver.Next(name) != KErrNone)
279 res = aServerThread.Create( KDebugServerName,
280 CDebugServServer::ThreadFunction,
289 TRequestStatus rendezvousStatus;
291 aServerThread.SetPriority(EPriorityNormal);
292 aServerThread.Rendezvous(rendezvousStatus);
293 aServerThread.Resume();
294 User::WaitForRequest(rendezvousStatus);
298 aServerThread.Close();
307 RDebugServSession::RDebugServSession()
309 // Server session constructor
314 TInt RDebugServSession::Open()
319 TInt r = StartThread(iServerThread);
322 r=CreateSession(KDebugServerName, Version(), KDefaultMessageSlots);
329 TVersion RDebugServSession::Version(void) const
334 return (TVersion(KDebugServMajorVersionNumber, KDebugServMinorVersionNumber, KDebugServBuildVersionNumber));
337 TInt RDebugServSession::SuspendThread(const TInt aThreadID)
339 // Session suspend thread request
342 TIpcArgs args(aThreadID);
344 res = SendReceive(EDebugServSuspendThread, args);
349 TInt RDebugServSession::ResumeThread(const TInt aThreadID)
351 // Session resume thread request
354 TIpcArgs args(aThreadID);
356 res = SendReceive(EDebugServResumeThread, args);
362 //TInt RDebugServSession::ReadProcessInfo(const TInt aIndex, TProcessInfo* aInfo)
364 //// Session read process information request
367 // TPckgBuf<TProcessInfo> pckg;
370 // TIpcArgs args(aIndex, &pckg);
374 // res = SendReceive(EDebugServReadProcessInfo, args);
382 //TInt RDebugServSession::ReadThreadInfo(const TInt aIndex, const TInt aProc, TThreadInfo* aInfo)
384 //// Session read thread information request
387 // TPckgBuf<TThreadInfo> pckg;
390 // TIpcArgs args(aIndex, aProc, &pckg);
394 // res = SendReceive(EDebugServReadThreadInfo, args);
403 TInt RDebugServSession::ReadMemory(const TUint32 aThreadID, TMemoryInfo* aInfo)
405 // Session read thread memory request
408 TPckgBuf<TMemoryInfo> pckg;
411 TIpcArgs args(aThreadID, &pckg);
415 res = SendReceive(EDebugServReadMemory, args);
424 TInt RDebugServSession::WriteMemory(const TUint32 aThreadID, TMemoryInfo* aInfo)
426 // Session write thread memory request
429 TPckgBuf<TMemoryInfo> pckg;
432 TIpcArgs args(aThreadID, &pckg);
436 res = SendReceive(EDebugServWriteMemory, args);
443 TInt RDebugServSession::Close()
445 // Session close the session and thread
448 RSessionBase::Close();
449 iServerThread.Close();