telnetDebugger.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 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. #ifndef _PLATFORM_PLATFORMNET_H_
  25. #include "platform/platformNet.h"
  26. #endif
  27. class CodeBlock;
  28. /// Telnet debug service implementation.
  29. ///
  30. /// This is the C++ side of the built-in Torque debugger.
  31. ///
  32. /// To use the debugger, use dbgSetParameters(port, password); in the console
  33. /// of the server to enable debugger connections. Then on some other system,
  34. /// start up the app (you don't have to start a game or connect to the
  35. /// server) and exec("common/debugger/debugger.tscript"); in the console. Then use
  36. /// the debugger GUI to connect to the server with the right port and password.
  37. ///
  38. /// @see http://www.planettribes.com/tribes2/editing.shtml for more thorough discussion.
  39. class TelnetDebugger
  40. {
  41. S32 mAcceptPort;
  42. NetSocket mAcceptSocket;
  43. NetSocket mDebugSocket;
  44. enum {
  45. // We should only change this is we truely
  46. // break the protocol in a future version.
  47. Version = 2,
  48. PasswordMaxLength = 32,
  49. MaxCommandSize = 2048
  50. };
  51. char mDebuggerPassword[PasswordMaxLength+1];
  52. enum State
  53. {
  54. NotConnected,
  55. PasswordTry,
  56. Initialize,
  57. Connected
  58. };
  59. S32 mState;
  60. char mLineBuffer[MaxCommandSize];
  61. S32 mCurPos;
  62. bool mWaitForClient;
  63. TelnetDebugger();
  64. ~TelnetDebugger();
  65. struct Breakpoint
  66. {
  67. StringTableEntry fileName;
  68. CodeBlock *code;
  69. U32 lineNumber;
  70. S32 passCount;
  71. S32 curCount;
  72. char *testExpression;
  73. bool clearOnHit;
  74. Breakpoint *next;
  75. };
  76. Breakpoint *mBreakpoints;
  77. Breakpoint **findBreakpoint(StringTableEntry fileName, S32 lineNumber);
  78. bool mProgramPaused;
  79. bool mBreakOnNextStatement;
  80. S32 mStackPopBreakIndex;
  81. void addVariableBreakpoint(const char *varName, S32 passCount, const char *evalString);
  82. void removeVariableBreakpoint(const char *varName);
  83. void addBreakpoint(const char *fileName, S32 line, bool clear, S32 passCount, const char *evalString);
  84. void removeBreakpoint(const char *fileName, S32 line);
  85. void removeAllBreakpoints();
  86. void debugBreakNext();
  87. void debugContinue();
  88. void debugStepIn();
  89. void debugStepOver();
  90. void debugStepOut();
  91. void evaluateExpression(const char *tag, S32 frame, const char *evalBuffer);
  92. void dumpFileList();
  93. void dumpBreakableList(const char *fileName);
  94. void removeBreakpointsFromCode(CodeBlock *code);
  95. void checkDebugRecv();
  96. void processLineBuffer(S32);
  97. void sendBreak();
  98. void setBreakOnNextStatement( bool enabled );
  99. public:
  100. static void create();
  101. static void destroy();
  102. void disconnect();
  103. bool isConnected() const { return mState == Connected; }
  104. void process();
  105. void popStackFrame();
  106. void pushStackFrame();
  107. void addAllBreakpoints(CodeBlock *code);
  108. void clearCodeBlockPointers(CodeBlock *code);
  109. void breakProcess();
  110. void executionStopped(CodeBlock *code, U32 lineNumber);
  111. void send(const char *s);
  112. void setDebugParameters(S32 port, const char *password, bool waitForClient);
  113. void processConsoleLine(const char *consoleLine);
  114. };
  115. extern TelnetDebugger *TelDebugger;
  116. #endif