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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Purpose: Kernel-side tracking of debug agent information associated |
|
15 // with each process being debugged. |
|
16 // |
|
17 // |
|
18 |
|
19 #ifndef D_DEBUG_AGENT_H |
|
20 #define D_DEBUG_AGENT_H |
|
21 |
|
22 #include <rm_debug_api.h> |
|
23 #include "d_driver_event_info.h" |
|
24 |
|
25 /** |
|
26 * Handles events from the kernel, filters them according to the debug agent's requests, |
|
27 * and signals these events to the user side in FIFO-style. |
|
28 * @see TKernelEventAction |
|
29 * @see TEventInfo |
|
30 */ |
|
31 class DDebugAgent : public DBase |
|
32 { |
|
33 public: |
|
34 static DDebugAgent* New(TUint64 aId); |
|
35 ~DDebugAgent(); |
|
36 |
|
37 TInt SetEventAction(Debug::TEventType aEvent, Debug::TKernelEventAction aEventAction); |
|
38 void GetEvent(TClientDataRequest<Debug::TEventInfo>* aAsyncGetValueRequest, DThread* aClientThread); |
|
39 TInt EventAction(Debug::TEventType aEvent); |
|
40 |
|
41 TInt CancelGetEvent(void); |
|
42 void NotifyEvent(const TDriverEventInfo& aEventInfo); |
|
43 TUint64 Id(); |
|
44 |
|
45 protected: |
|
46 DDebugAgent(TUint64 aId); |
|
47 TInt Construct(); |
|
48 |
|
49 private: |
|
50 void QueueEvent(const TDriverEventInfo& aEventInfo); |
|
51 TBool BufferEmpty() const; |
|
52 TBool BufferFull() const; |
|
53 TBool BufferCanStoreEvent() const; |
|
54 TBool BufferAtCriticalLevel() const; |
|
55 void IncrementHeadPosition(void); |
|
56 void IncrementTailPosition(void); |
|
57 TInt NumberOfEmptySlots() const; |
|
58 void LockEventQueue(void); |
|
59 void UnlockEventQueue(void); |
|
60 |
|
61 private: |
|
62 |
|
63 TUint64 iId; |
|
64 Debug::TKernelEventAction iEventActions[Debug::EEventsLast]; |
|
65 |
|
66 /** |
|
67 * Object used to write events back to DSS thread |
|
68 * @see TEventInfo |
|
69 */ |
|
70 TClientDataRequest<Debug::TEventInfo>* iRequestGetEventStatus; |
|
71 |
|
72 DThread* iClientThread; |
|
73 |
|
74 /** |
|
75 * Ring buffer of pending events. Access to it is controlled by |
|
76 * @see iEventQueueLock |
|
77 */ |
|
78 RArray<TDriverEventInfo> iEventQueue; |
|
79 |
|
80 /** |
|
81 * Ring buffer head. Points to the next empty slot in iEventQueue |
|
82 * @see iEventQueue |
|
83 */ |
|
84 TInt iHead; |
|
85 |
|
86 /** |
|
87 * Ring buffer tail. Points to the oldest full slot in iEventQueue |
|
88 * @see iEventQueue |
|
89 */ |
|
90 TInt iTail; |
|
91 |
|
92 /** |
|
93 * Control access to event queue. |
|
94 * @see iEventQueue |
|
95 */ |
|
96 DSemaphore* iEventQueueLock; |
|
97 |
|
98 /** |
|
99 * Keeps track of how many free slots are available in the event queue. |
|
100 * @see iEventQueue |
|
101 */ |
|
102 TInt iFreeSlots; |
|
103 |
|
104 /** |
|
105 * Boolean to indicate if we have told the agent that we are ignoring trace events |
|
106 * @see QueueEvent |
|
107 */ |
|
108 TBool iIgnoringTrace; |
|
109 |
|
110 /** |
|
111 * Used to control the delivery of events to the client so that only |
|
112 * when more requests than deliveries have taken place can we deliver the |
|
113 * next event |
|
114 * |
|
115 * Incremented when a request for event takes place |
|
116 * @see GetEvent |
|
117 * |
|
118 * Decremented when an event is delivered. |
|
119 * @see NotifyEvent |
|
120 * |
|
121 * Cleared when event requests are cancelled |
|
122 * @see CancelGetEvent |
|
123 * |
|
124 */ |
|
125 TInt iEventBalance; |
|
126 |
|
127 /** |
|
128 * Length of kernel-event queue. |
|
129 * This is a power of two for efficiency when using the |
|
130 * remainder operator |
|
131 * @see DDebugAgent::iEventQueue |
|
132 */ |
|
133 static const TUint KNumberOfEventsToQueue = 128; |
|
134 |
|
135 /** |
|
136 * This determines the number of events at which we stop accepting |
|
137 * low priority events into the event queue. |
|
138 * @see DDebugAgent::BufferAtCriticalLevel |
|
139 * @see DDebugAgent::iEventQueue |
|
140 */ |
|
141 static const TUint KCriticalBufferSize = 64; |
|
142 |
|
143 /** |
|
144 * If we encounter an event that will take down the agent (eg a process critical thread crashing) |
|
145 * we use this flag to stop trying to deliver thread death notifications to it. |
|
146 */ |
|
147 TBool iAgentDying; |
|
148 }; |
|
149 |
|
150 #endif // D_DEBUG_AGENT_H |
|
151 |
|