RemoteDebugger1.cc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 _REMOTE_DEBUGGER1_H_
  23. #include "debug/remote/RemoteDebugger1.h"
  24. #endif
  25. #ifndef _COMPILER_H_
  26. #include "console/compiler.h"
  27. #endif
  28. // Script bindings.
  29. #include "debug/remote/RemoteDebugger1_ScriptBinding.h"
  30. //-----------------------------------------------------------------------------
  31. IMPLEMENT_CONOBJECT(RemoteDebugger1);
  32. //-----------------------------------------------------------------------------
  33. RemoteDebugger1::RemoteDebugger1() :
  34. mBreakPoints( NULL )
  35. {
  36. }
  37. //-----------------------------------------------------------------------------
  38. RemoteDebugger1::~RemoteDebugger1()
  39. {
  40. }
  41. //-----------------------------------------------------------------------------
  42. bool RemoteDebugger1::getCodeFiles( char* pBuffer, S32 bufferSize )
  43. {
  44. // Iterate all code-blocks.
  45. for( CodeBlock* pCodeBlock = CodeBlock::getCodeBlockList(); pCodeBlock != NULL; pCodeBlock = pCodeBlock->nextFile )
  46. {
  47. // Finish if out of buffer.
  48. if ( bufferSize <= 0 )
  49. return false;
  50. // Format code file.
  51. S32 offset = dSprintf( pBuffer, bufferSize, pCodeBlock->nextFile == NULL ? "%s" : "%s,", pCodeBlock->fullPath );
  52. pBuffer += offset;
  53. bufferSize -= offset;
  54. }
  55. // Finish if out of buffer.
  56. if ( bufferSize < 2 )
  57. return false;
  58. // Terminate return buffer.
  59. dSprintf( pBuffer, bufferSize, "\n" );
  60. return true;
  61. }
  62. //-----------------------------------------------------------------------------
  63. const char* RemoteDebugger1::getValidBreakpoints( void )
  64. {
  65. for( CodeBlock* pCodeBlock = CodeBlock::getCodeBlockList(); pCodeBlock != NULL; pCodeBlock = pCodeBlock->nextFile )
  66. {
  67. Con::printf( "%s", pCodeBlock->fullPath );
  68. Con::printSeparator();
  69. for( U32 breakEntry = 0, breakIndex = 0; breakEntry < pCodeBlock->lineBreakPairCount; breakEntry++, breakIndex += 2 )
  70. {
  71. Con::printf( "Line: %d, IP: %d", pCodeBlock->lineBreakPairs[breakIndex] >> 8, pCodeBlock->lineBreakPairs[breakIndex+1] );
  72. }
  73. Con::printSeparator();
  74. }
  75. return NULL;
  76. }
  77. //-----------------------------------------------------------------------------
  78. void RemoteDebugger1::setNextStatementBreak( const bool enabled )
  79. {
  80. if ( enabled )
  81. {
  82. // Apply breaks on all the code blocks.
  83. for(CodeBlock *walk = CodeBlock::getCodeBlockList(); walk; walk = walk->nextFile)
  84. walk->setAllBreaks();
  85. //mBreakOnNextStatement = true;
  86. }
  87. else if ( !enabled )
  88. {
  89. // Clear all the breaks on the code-blocks
  90. // then go reapply the breakpoints.
  91. for(CodeBlock *walk = CodeBlock::getCodeBlockList(); walk; walk = walk->nextFile)
  92. walk->clearAllBreaks();
  93. //mBreakOnNextStatement = false;
  94. }
  95. }
  96. //-----------------------------------------------------------------------------
  97. void RemoteDebugger1::onClientLogin( void )
  98. {
  99. // Call parent.
  100. Parent::onClientLogin();
  101. }