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