telnetDebugger.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _TELNETDEBUGGER_H_
  23. #define _TELNETDEBUGGER_H_
  24. class CodeBlock;
  25. /// Telnet debug service implementation.
  26. ///
  27. /// This is the C++ side of the built-in Torque debugger.
  28. ///
  29. /// To use the debugger, use dbgSetParameters(port, password); in the console
  30. /// of the server to enable debugger connections. Then on some other system,
  31. /// start up the app (you don't have to start a game or connect to the
  32. /// server) and exec("common/debugger/debugger.cs"); in the console. Then use
  33. /// the debugger GUI to connect to the server with the right port and password.
  34. ///
  35. /// @see http://www.planettribes.com/tribes2/editing.shtml for more thorough discussion.
  36. class TelnetDebugger
  37. {
  38. S32 mAcceptPort;
  39. NetSocket mAcceptSocket;
  40. NetSocket mDebugSocket;
  41. enum {
  42. // We should only change this is we truely
  43. // break the protocol in a future version.
  44. Version = 2,
  45. PasswordMaxLength = 32,
  46. MaxCommandSize = 2048
  47. };
  48. char mDebuggerPassword[PasswordMaxLength+1];
  49. enum State
  50. {
  51. NotConnected,
  52. PasswordTry,
  53. Initialize,
  54. Connected
  55. };
  56. S32 mState;
  57. char mLineBuffer[MaxCommandSize];
  58. S32 mCurPos;
  59. bool mWaitForClient;
  60. TelnetDebugger();
  61. ~TelnetDebugger();
  62. struct Breakpoint
  63. {
  64. StringTableEntry fileName;
  65. CodeBlock *code;
  66. U32 lineNumber;
  67. S32 passCount;
  68. S32 curCount;
  69. char *testExpression;
  70. bool clearOnHit;
  71. Breakpoint *next;
  72. };
  73. Breakpoint *mBreakpoints;
  74. Breakpoint **findBreakpoint(StringTableEntry fileName, S32 lineNumber);
  75. bool mProgramPaused;
  76. bool mBreakOnNextStatement;
  77. S32 mStackPopBreakIndex;
  78. void addVariableBreakpoint(const char *varName, S32 passCount, const char *evalString);
  79. void removeVariableBreakpoint(const char *varName);
  80. void addBreakpoint(const char *fileName, S32 line, bool clear, S32 passCount, const char *evalString);
  81. void removeBreakpoint(const char *fileName, S32 line);
  82. void removeAllBreakpoints();
  83. void debugBreakNext();
  84. void debugContinue();
  85. void debugStepIn();
  86. void debugStepOver();
  87. void debugStepOut();
  88. void evaluateExpression(const char *tag, S32 frame, const char *evalBuffer);
  89. void dumpFileList();
  90. void dumpBreakableList(const char *fileName);
  91. void removeBreakpointsFromCode(CodeBlock *code);
  92. void checkDebugRecv();
  93. void processLineBuffer(S32);
  94. void breakProcess();
  95. void sendBreak();
  96. void setBreakOnNextStatement( bool enabled );
  97. public:
  98. static void create();
  99. static void destroy();
  100. void disconnect();
  101. bool isConnected() const { return mState == Connected; }
  102. void process();
  103. void popStackFrame();
  104. void pushStackFrame();
  105. void addAllBreakpoints(CodeBlock *code);
  106. void clearCodeBlockPointers(CodeBlock *code);
  107. virtual void executionStopped(CodeBlock *code, U32 lineNumber);
  108. void send(const char *s);
  109. void setDebugParameters(S32 port, const char *password, bool waitForClient);
  110. void processConsoleLine(const char *consoleLine);
  111. };
  112. extern TelnetDebugger *TelDebugger;
  113. #endif