sl@0
|
1 |
// Copyright (c) 2004-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 |
// Kernel Event handler for Run Mode Debug.
|
sl@0
|
15 |
//
|
sl@0
|
16 |
|
sl@0
|
17 |
#include <e32def.h>
|
sl@0
|
18 |
#include <e32def_private.h>
|
sl@0
|
19 |
#include <e32cmn.h>
|
sl@0
|
20 |
#include <e32cmn_private.h>
|
sl@0
|
21 |
#include <kernel/arm/arm.h>
|
sl@0
|
22 |
#include <kernel/kernel.h>
|
sl@0
|
23 |
#include <kernel/kern_priv.h>
|
sl@0
|
24 |
#include <nk_trace.h>
|
sl@0
|
25 |
|
sl@0
|
26 |
#include <rm_debug_api.h>
|
sl@0
|
27 |
#include "debug_logging.h"
|
sl@0
|
28 |
#include "d_process_tracker.h"
|
sl@0
|
29 |
#include "d_rmd_stepping.h"
|
sl@0
|
30 |
#include "rm_debug_kerneldriver.h"
|
sl@0
|
31 |
#include "rm_debug_driver.h"
|
sl@0
|
32 |
#include "rm_debug_eventhandler.h"
|
sl@0
|
33 |
|
sl@0
|
34 |
|
sl@0
|
35 |
DRM_DebugEventHandler::DRM_DebugEventHandler()
|
sl@0
|
36 |
: DKernelEventHandler(EventHandler, this)
|
sl@0
|
37 |
{
|
sl@0
|
38 |
LOG_MSG("DRM_DebugEventHandler::DRM_DebugEventHandler()");
|
sl@0
|
39 |
|
sl@0
|
40 |
for(TInt i=0; i<EEventLimit; i++)
|
sl@0
|
41 |
{
|
sl@0
|
42 |
iEventHandlers[i] = &DRM_DebugChannel::HandleUnsupportedEvent;
|
sl@0
|
43 |
}
|
sl@0
|
44 |
iEventHandlers[EEventUserTrace] = &DRM_DebugChannel::HandleUserTrace;
|
sl@0
|
45 |
iEventHandlers[EEventRemoveLibrary] = &DRM_DebugChannel::RemoveLibrary;
|
sl@0
|
46 |
iEventHandlers[EEventAddLibrary] = &DRM_DebugChannel::AddLibrary;
|
sl@0
|
47 |
iEventHandlers[EEventRemoveProcess] = &DRM_DebugChannel::RemoveProcess;
|
sl@0
|
48 |
iEventHandlers[EEventStartThread] = &DRM_DebugChannel::StartThread;
|
sl@0
|
49 |
iEventHandlers[EEventSwExc] = &DRM_DebugChannel::HandleSwException;
|
sl@0
|
50 |
iEventHandlers[EEventHwExc] = &DRM_DebugChannel::HandleHwException;
|
sl@0
|
51 |
iEventHandlers[EEventKillThread] = &DRM_DebugChannel::HandleEventKillThread;
|
sl@0
|
52 |
iEventHandlers[EEventAddProcess] = &DRM_DebugChannel::HandleAddProcessEvent;
|
sl@0
|
53 |
iEventHandlers[EEventRemoveProcess] = &DRM_DebugChannel::HandleRemoveProcessEvent;
|
sl@0
|
54 |
}
|
sl@0
|
55 |
|
sl@0
|
56 |
TInt DRM_DebugEventHandler::Create(DLogicalDevice* aDevice, DLogicalChannel* aChannel, DThread* aClient)
|
sl@0
|
57 |
{
|
sl@0
|
58 |
LOG_MSG("DRM_DebugEventHandler::Create()");
|
sl@0
|
59 |
|
sl@0
|
60 |
TInt err;
|
sl@0
|
61 |
err = aDevice->Open();
|
sl@0
|
62 |
if (err != KErrNone)
|
sl@0
|
63 |
return err;
|
sl@0
|
64 |
iDevice = aDevice;
|
sl@0
|
65 |
|
sl@0
|
66 |
iChannel = (DRM_DebugChannel*)aChannel; //Don't add ref the channel, since channel closes the event handler before it ever gets destroyed.
|
sl@0
|
67 |
|
sl@0
|
68 |
err = aClient->Open();
|
sl@0
|
69 |
if (err != KErrNone)
|
sl@0
|
70 |
return err;
|
sl@0
|
71 |
iClientThread = aClient;
|
sl@0
|
72 |
|
sl@0
|
73 |
// Use a semaphore to protect our data structures from concurrent access.
|
sl@0
|
74 |
err = Kern::SemaphoreCreate(iLock, _L("RM_DebugEventHandlerLock"), 1 /* Initial count */);
|
sl@0
|
75 |
if (err != KErrNone)
|
sl@0
|
76 |
return err;
|
sl@0
|
77 |
|
sl@0
|
78 |
|
sl@0
|
79 |
return Add();
|
sl@0
|
80 |
}
|
sl@0
|
81 |
|
sl@0
|
82 |
|
sl@0
|
83 |
DRM_DebugEventHandler::~DRM_DebugEventHandler()
|
sl@0
|
84 |
{
|
sl@0
|
85 |
LOG_MSG("DRM_DebugEventHandler::~DRM_DebugEventHandler()");
|
sl@0
|
86 |
|
sl@0
|
87 |
if (iLock)
|
sl@0
|
88 |
iLock->Close(NULL);
|
sl@0
|
89 |
|
sl@0
|
90 |
if (iDevice)
|
sl@0
|
91 |
iDevice->Close(NULL);
|
sl@0
|
92 |
|
sl@0
|
93 |
if (iClientThread)
|
sl@0
|
94 |
Kern::SafeClose((DObject*&)iClientThread, NULL);
|
sl@0
|
95 |
|
sl@0
|
96 |
}
|
sl@0
|
97 |
|
sl@0
|
98 |
|
sl@0
|
99 |
TInt DRM_DebugEventHandler::Start()
|
sl@0
|
100 |
{
|
sl@0
|
101 |
LOG_MSG("DRM_DebugEventHandler::Start()");
|
sl@0
|
102 |
|
sl@0
|
103 |
iTracking = ETrue;
|
sl@0
|
104 |
|
sl@0
|
105 |
return KErrNone;
|
sl@0
|
106 |
}
|
sl@0
|
107 |
|
sl@0
|
108 |
|
sl@0
|
109 |
TInt DRM_DebugEventHandler::Stop()
|
sl@0
|
110 |
{
|
sl@0
|
111 |
LOG_MSG("DRM_DebugEventHandler::Stop()");
|
sl@0
|
112 |
|
sl@0
|
113 |
iTracking = EFalse;
|
sl@0
|
114 |
|
sl@0
|
115 |
return KErrNone;
|
sl@0
|
116 |
}
|
sl@0
|
117 |
|
sl@0
|
118 |
|
sl@0
|
119 |
TUint DRM_DebugEventHandler::EventHandler(TKernelEvent aType, TAny* a1, TAny* a2, TAny* aThis)
|
sl@0
|
120 |
{
|
sl@0
|
121 |
return ((DRM_DebugEventHandler*)aThis)->HandleEvent(aType, a1, a2);
|
sl@0
|
122 |
}
|
sl@0
|
123 |
|
sl@0
|
124 |
|
sl@0
|
125 |
|
sl@0
|
126 |
TUint DRM_DebugEventHandler::HandleEvent(TKernelEvent aType, TAny* a1, TAny* a2)
|
sl@0
|
127 |
{
|
sl@0
|
128 |
if((!iTracking) || (aType > (TUint32)EEventLimit))
|
sl@0
|
129 |
{
|
sl@0
|
130 |
return ERunNext;
|
sl@0
|
131 |
}
|
sl@0
|
132 |
return HandleSpecificEvent(aType,a1,a2) ? EExcHandled : ERunNext;
|
sl@0
|
133 |
}
|
sl@0
|
134 |
|
sl@0
|
135 |
TBool DRM_DebugEventHandler::HandleSpecificEvent(TKernelEvent aType, TAny* a1, TAny* a2)
|
sl@0
|
136 |
{
|
sl@0
|
137 |
TBool ret = EFalse;
|
sl@0
|
138 |
|
sl@0
|
139 |
NKern::ThreadEnterCS();
|
sl@0
|
140 |
Kern::SemaphoreWait(*iLock);
|
sl@0
|
141 |
|
sl@0
|
142 |
if (iChannel)
|
sl@0
|
143 |
{
|
sl@0
|
144 |
ret = (iChannel->*(iEventHandlers[aType]))(a1, a2);
|
sl@0
|
145 |
}
|
sl@0
|
146 |
|
sl@0
|
147 |
Kern::SemaphoreSignal(*iLock);
|
sl@0
|
148 |
NKern::ThreadLeaveCS();
|
sl@0
|
149 |
|
sl@0
|
150 |
switch(aType)
|
sl@0
|
151 |
{
|
sl@0
|
152 |
case EEventHwExc:
|
sl@0
|
153 |
case EEventKillThread:
|
sl@0
|
154 |
{
|
sl@0
|
155 |
LOG_MSG2("DRM_DebugEventHandler::HandleEvent() -> FSWait(), kernel event type: %d", (TUint32)aType);
|
sl@0
|
156 |
TheDProcessTracker.FSWait();
|
sl@0
|
157 |
LOG_MSG("DRM_DebugEventHandler::HandleEvent() <- FSWait()");
|
sl@0
|
158 |
break;
|
sl@0
|
159 |
}
|
sl@0
|
160 |
default:
|
sl@0
|
161 |
break;
|
sl@0
|
162 |
}
|
sl@0
|
163 |
return ret;
|
sl@0
|
164 |
}
|
sl@0
|
165 |
|