DebuggerClient.h 6.9 KB

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