script_debugger_remote.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*************************************************************************/
  2. /* script_debugger_remote.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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 SCRIPT_DEBUGGER_REMOTE_H
  31. #define SCRIPT_DEBUGGER_REMOTE_H
  32. #include "core/io/packet_peer.h"
  33. #include "core/io/stream_peer_tcp.h"
  34. #include "core/list.h"
  35. #include "core/os/os.h"
  36. #include "core/script_language.h"
  37. class SceneTree;
  38. class ScriptDebuggerRemote : public ScriptDebugger {
  39. struct Message {
  40. String message;
  41. Array data;
  42. };
  43. struct ProfileInfoSort {
  44. bool operator()(ScriptLanguage::ProfilingInfo *A, ScriptLanguage::ProfilingInfo *B) const {
  45. return A->total_time < B->total_time;
  46. }
  47. };
  48. Vector<ScriptLanguage::ProfilingInfo> profile_info;
  49. Vector<ScriptLanguage::ProfilingInfo *> profile_info_ptrs;
  50. Vector<MultiplayerAPI::ProfilingInfo> network_profile_info;
  51. Map<StringName, int> profiler_function_signature_map;
  52. float frame_time, idle_time, physics_time, physics_frame_time;
  53. bool profiling;
  54. bool profiling_network;
  55. int max_frame_functions;
  56. bool skip_profile_frame;
  57. bool reload_all_scripts;
  58. Ref<StreamPeerTCP> tcp_client;
  59. Ref<PacketPeerStream> packet_peer_stream;
  60. uint64_t last_perf_time;
  61. uint64_t last_net_prof_time;
  62. uint64_t last_net_bandwidth_time;
  63. Object *performance;
  64. bool requested_quit;
  65. Mutex mutex;
  66. struct OutputError {
  67. int hr;
  68. int min;
  69. int sec;
  70. int msec;
  71. String source_file;
  72. String source_func;
  73. int source_line;
  74. String error;
  75. String error_descr;
  76. bool warning;
  77. Array callstack;
  78. };
  79. struct OutputString {
  80. String message;
  81. int type;
  82. };
  83. List<OutputString> output_strings;
  84. List<Message> messages;
  85. int max_messages_per_frame;
  86. int n_messages_dropped;
  87. List<OutputError> errors;
  88. int max_errors_per_second;
  89. int max_warnings_per_second;
  90. int n_errors_dropped;
  91. int n_warnings_dropped;
  92. int max_cps;
  93. int char_count;
  94. int err_count;
  95. int warn_count;
  96. uint64_t last_msec;
  97. uint64_t msec_count;
  98. OS::ProcessID allow_focus_steal_pid;
  99. bool locking; //hack to avoid a deadloop
  100. static void _print_handler(void *p_this, const String &p_string, bool p_error);
  101. PrintHandlerList phl;
  102. void _get_output();
  103. void _poll_events();
  104. uint32_t poll_every;
  105. SceneTree *scene_tree;
  106. bool _parse_live_edit(const Array &p_command);
  107. void _set_object_property(ObjectID p_id, const String &p_property, const Variant &p_value);
  108. void _send_object_id(ObjectID p_id);
  109. void _send_video_memory();
  110. Ref<MultiplayerAPI> multiplayer;
  111. ErrorHandlerList eh;
  112. static void _err_handler(void *, const char *, const char *, int p_line, const char *, const char *, ErrorHandlerType p_type);
  113. void _send_profiling_data(bool p_for_frame);
  114. void _send_network_profiling_data();
  115. void _send_network_bandwidth_usage();
  116. struct FrameData {
  117. StringName name;
  118. Array data;
  119. };
  120. Vector<FrameData> profile_frame_data;
  121. void _put_variable(const String &p_name, const Variant &p_variable);
  122. void _save_node(ObjectID id, const String &p_path);
  123. bool skip_breakpoints;
  124. public:
  125. enum MessageType {
  126. MESSAGE_TYPE_LOG,
  127. MESSAGE_TYPE_ERROR,
  128. };
  129. struct ResourceUsage {
  130. String path;
  131. String format;
  132. String type;
  133. RID id;
  134. int vram;
  135. bool operator<(const ResourceUsage &p_img) const { return vram == p_img.vram ? id < p_img.id : vram > p_img.vram; }
  136. };
  137. typedef void (*ResourceUsageFunc)(List<ResourceUsage> *);
  138. static ResourceUsageFunc resource_usage_func;
  139. Error connect_to_host(const String &p_host, uint16_t p_port);
  140. virtual void debug(ScriptLanguage *p_script, bool p_can_continue = true, bool p_is_error_breakpoint = false);
  141. virtual void idle_poll();
  142. virtual void line_poll();
  143. virtual bool is_remote() const { return true; }
  144. virtual void request_quit();
  145. virtual void send_message(const String &p_message, const Array &p_args);
  146. virtual void send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type, const Vector<ScriptLanguage::StackInfo> &p_stack_info);
  147. virtual void set_multiplayer(Ref<MultiplayerAPI> p_multiplayer);
  148. virtual bool is_profiling() const;
  149. virtual void add_profiling_frame_data(const StringName &p_name, const Array &p_data);
  150. virtual void profiling_start();
  151. virtual void profiling_end();
  152. virtual void profiling_set_frame_times(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time);
  153. virtual void set_skip_breakpoints(bool p_skip_breakpoints);
  154. void set_scene_tree(SceneTree *p_scene_tree) { scene_tree = p_scene_tree; };
  155. void set_allow_focus_steal_pid(OS::ProcessID p_pid);
  156. ScriptDebuggerRemote();
  157. ~ScriptDebuggerRemote();
  158. };
  159. #endif // SCRIPT_DEBUGGER_REMOTE_H