remote_debugger.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**************************************************************************/
  2. /* remote_debugger.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef REMOTE_DEBUGGER_H
  31. #define REMOTE_DEBUGGER_H
  32. #include "core/debugger/debugger_marshalls.h"
  33. #include "core/debugger/engine_debugger.h"
  34. #include "core/debugger/remote_debugger_peer.h"
  35. #include "core/object/class_db.h"
  36. #include "core/string/string_name.h"
  37. #include "core/string/ustring.h"
  38. #include "core/variant/array.h"
  39. class RemoteDebugger : public EngineDebugger {
  40. public:
  41. enum MessageType {
  42. MESSAGE_TYPE_LOG,
  43. MESSAGE_TYPE_ERROR,
  44. MESSAGE_TYPE_LOG_RICH,
  45. };
  46. private:
  47. typedef DebuggerMarshalls::OutputError ErrorMessage;
  48. class PerformanceProfiler;
  49. Ref<PerformanceProfiler> performance_profiler;
  50. Ref<RemoteDebuggerPeer> peer;
  51. struct OutputString {
  52. String message;
  53. MessageType type;
  54. };
  55. List<OutputString> output_strings;
  56. List<ErrorMessage> errors;
  57. int n_messages_dropped = 0;
  58. int max_errors_per_second = 0;
  59. int max_chars_per_second = 0;
  60. int max_warnings_per_second = 0;
  61. int n_errors_dropped = 0;
  62. int n_warnings_dropped = 0;
  63. int char_count = 0;
  64. int err_count = 0;
  65. int warn_count = 0;
  66. int last_reset = 0;
  67. bool reload_all_scripts = false;
  68. // Make handlers and send_message thread safe.
  69. Mutex mutex;
  70. bool flushing = false;
  71. Thread::ID flush_thread = 0;
  72. PrintHandlerList phl;
  73. static void _print_handler(void *p_this, const String &p_string, bool p_error, bool p_rich);
  74. ErrorHandlerList eh;
  75. static void _err_handler(void *p_this, const char *p_func, const char *p_file, int p_line, const char *p_err, const char *p_descr, bool p_editor_notify, ErrorHandlerType p_type);
  76. ErrorMessage _create_overflow_error(const String &p_what, const String &p_descr);
  77. Error _put_msg(String p_message, Array p_data);
  78. bool is_peer_connected() { return peer->is_peer_connected(); }
  79. void flush_output();
  80. void _send_stack_vars(List<String> &p_names, List<Variant> &p_vals, int p_type);
  81. Error _profiler_capture(const String &p_cmd, const Array &p_data, bool &r_captured);
  82. Error _core_capture(const String &p_cmd, const Array &p_data, bool &r_captured);
  83. template <typename T>
  84. void _bind_profiler(const String &p_name, T *p_prof);
  85. Error _try_capture(const String &p_name, const Array &p_data, bool &r_captured);
  86. public:
  87. // Overrides
  88. void poll_events(bool p_is_idle);
  89. void send_message(const String &p_message, const Array &p_args);
  90. void send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, bool p_editor_notify, ErrorHandlerType p_type);
  91. void debug(bool p_can_continue = true, bool p_is_error_breakpoint = false);
  92. explicit RemoteDebugger(Ref<RemoteDebuggerPeer> p_peer);
  93. ~RemoteDebugger();
  94. };
  95. #endif // REMOTE_DEBUGGER_H