]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/tools/debugger/DebuggerClient.h
hello world
[icculus/iodoom3.git] / neo / tools / debugger / DebuggerClient.h
1 /*
2 ===========================================================================
3
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. 
6
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).  
8
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code.  If not, see <http://www.gnu.org/licenses/>.
21
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code.  If not, please request a copy in writing from id Software at the address below.
23
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25
26 ===========================================================================
27 */
28 #ifndef DEBUGGERCLIENT_H_
29 #define DEBUGGERCLIENT_H_
30
31 class rvDebuggerCallstack
32 {
33 public:
34
35         idStr   mFilename;
36         int             mLineNumber;
37         idStr   mFunction;
38 };
39
40 class rvDebuggerThread
41 {
42 public:
43
44         idStr   mName;
45         int             mID;
46         bool    mCurrent;
47         bool    mDying;
48         bool    mWaiting;
49         bool    mDoneProcessing;
50 };
51
52 #ifndef DEBUGGERBREAKPOINT_H_
53 #include "DebuggerBreakpoint.h"
54 #endif
55
56 typedef idList<rvDebuggerCallstack*>    rvDebuggerCallstackList;
57 typedef idList<rvDebuggerThread*>               rvDebuggerThreadList;
58 typedef idList<rvDebuggerBreakpoint*>   rvDebuggerBreakpointList;
59
60 class rvDebuggerClient
61 {
62 public:
63
64         rvDebuggerClient ( );
65         ~rvDebuggerClient ( );
66
67         bool                                            Initialize                              ( void );
68         void                                            Shutdown                                ( void );
69         bool                                            ProcessMessages                 ( void );
70         bool                                            WaitFor                                 ( EDebuggerMessage msg, int time );
71         
72         bool                                            IsConnected                             ( void );
73         bool                                            IsStopped                               ( void );
74         
75         int                                                     GetActiveBreakpointID   ( void );
76         const char*                                     GetBreakFilename                ( void );
77         int                                                     GetBreakLineNumber              ( void );
78         rvDebuggerCallstackList&        GetCallstack                    ( void );
79         rvDebuggerThreadList&           GetThreads                              ( void );
80         const char*                                     GetVariableValue                ( const char* name, int stackDepth );
81         
82         void                                            InspectVariable                 ( const char* name, int callstackDepth );
83         
84         void                                            Break                                   ( void );
85         void                                            Resume                                  ( void );
86         void                                            StepInto                                ( void );
87         void                                            StepOver                                ( void );
88
89         // Breakpoints
90         int                                                     AddBreakpoint                   ( const char* filename, int lineNumber, bool onceOnly = false );
91         bool                                            RemoveBreakpoint                ( int bpID );
92         void                                            ClearBreakpoints                ( void );
93         int                                                     GetBreakpointCount              ( void );
94         rvDebuggerBreakpoint*           GetBreakpoint                   ( int index );
95         rvDebuggerBreakpoint*           FindBreakpoint                  ( const char* filename, int linenumber );
96                 
97 protected:
98
99         void                                            SendMessage                             ( EDebuggerMessage dbmsg );
100         void                                            SendBreakpoints                 ( void );
101         void                                            SendAddBreakpoint               ( rvDebuggerBreakpoint& bp, bool onceOnly = false );
102         void                                            SendRemoveBreakpoint    ( rvDebuggerBreakpoint& bp );
103         void                                            SendPacket                              ( void* data, int datasize );
104
105         bool                                            mConnected;
106         netadr_t                                        mServerAdr;
107         idPort                                          mPort;
108         
109         bool                                            mBreak;
110         int                                                     mBreakID;
111         int                                                     mBreakLineNumber;
112         idStr                                           mBreakFilename;
113         
114         idDict                                          mVariables;
115
116         rvDebuggerCallstackList         mCallstack;
117         rvDebuggerThreadList            mThreads;       
118         rvDebuggerBreakpointList        mBreakpoints;
119
120         EDebuggerMessage                        mWaitFor;
121         
122 private:
123
124         void            ClearCallstack                          ( void );
125         void            ClearThreads                            ( void );
126         
127         void            UpdateWatches                           ( void );
128         
129         // Network message handlers
130         void            HandleBreak                                     ( msg_t* msg );
131         void            HandleInspectCallstack          ( msg_t* msg );
132         void            HandleInspectThreads            ( msg_t* msg );
133         void            HandleInspectVariable           ( msg_t* msg );
134 };
135
136 /*
137 ================
138 rvDebuggerClient::IsConnected
139 ================
140 */
141 ID_INLINE bool rvDebuggerClient::IsConnected ( void )
142 {
143         return mConnected;
144 }
145
146 /*
147 ================
148 rvDebuggerClient::IsStopped
149 ================
150 */
151 ID_INLINE bool rvDebuggerClient::IsStopped ( void )
152 {
153         return mBreak;
154 }
155
156 /*
157 ================
158 rvDebuggerClient::GetActiveBreakpointID
159 ================
160 */
161 ID_INLINE int rvDebuggerClient::GetActiveBreakpointID ( void )
162 {
163         return mBreakID;
164 }
165
166 /*
167 ================
168 rvDebuggerClient::GetBreakFilename
169 ================
170 */
171 ID_INLINE const char* rvDebuggerClient::GetBreakFilename ( void )
172 {
173         return mBreakFilename;
174 }
175
176 /*
177 ================
178 rvDebuggerClient::GetBreakLineNumber
179 ================
180 */
181 ID_INLINE int rvDebuggerClient::GetBreakLineNumber ( void )
182 {
183         return mBreakLineNumber;
184 }
185
186 /*
187 ================
188 rvDebuggerClient::GetCallstack
189 ================
190 */
191 ID_INLINE rvDebuggerCallstackList& rvDebuggerClient::GetCallstack ( void )
192 {
193         return mCallstack;
194 }
195
196 /*
197 ================
198 rvDebuggerClient::GetThreads
199 ================
200 */
201 ID_INLINE rvDebuggerThreadList& rvDebuggerClient::GetThreads ( void )
202 {
203         return mThreads;
204 }
205
206 /*
207 ================
208 rvDebuggerClient::GetVariableValue
209 ================
210 */
211 ID_INLINE const char* rvDebuggerClient::GetVariableValue ( const char* var, int stackDepth )
212 {
213         return mVariables.GetString ( va("%d:%s",stackDepth,var), "" );
214 }
215
216 /*
217 ================
218 rvDebuggerClient::GetBreakpointCount
219 ================
220 */
221 ID_INLINE int rvDebuggerClient::GetBreakpointCount ( void )
222 {
223         return mBreakpoints.Num ( );
224 }
225
226 /*
227 ================
228 rvDebuggerClient::GetBreakpoint
229 ================
230 */
231 ID_INLINE rvDebuggerBreakpoint* rvDebuggerClient::GetBreakpoint ( int index )
232 {
233         return mBreakpoints[index];
234 }
235
236 /*
237 ================
238 rvDebuggerClient::Break
239 ================
240 */
241 ID_INLINE void rvDebuggerClient::Break ( void )
242 {
243         SendMessage ( DBMSG_BREAK );
244 }
245
246 /*
247 ================
248 rvDebuggerClient::Resume
249 ================
250 */
251 ID_INLINE void rvDebuggerClient::Resume ( void )
252 {
253         mBreak = false;
254         SendMessage ( DBMSG_RESUME );
255 }
256
257 /*
258 ================
259 rvDebuggerClient::StepOver
260 ================
261 */
262 ID_INLINE void rvDebuggerClient::StepOver ( void )
263 {
264         mBreak = false;
265         SendMessage ( DBMSG_STEPOVER );
266 }
267
268 /*
269 ================
270 rvDebuggerClient::StepInto
271 ================
272 */
273 ID_INLINE void rvDebuggerClient::StepInto ( void )
274 {
275         mBreak = false;
276         SendMessage ( DBMSG_STEPINTO );
277 }
278
279 /*
280 ================
281 rvDebuggerClient::SendPacket
282 ================
283 */
284 ID_INLINE void rvDebuggerClient::SendPacket ( void* data, int size )
285 {
286         mPort.SendPacket ( mServerAdr, data, size );
287 }
288
289 #endif // DEBUGGERCLIENT_H_