2
0

script_debugger_remote.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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. List<String> output_strings;
  80. List<Message> messages;
  81. int max_messages_per_frame;
  82. int n_messages_dropped;
  83. List<OutputError> errors;
  84. int max_errors_per_second;
  85. int max_warnings_per_second;
  86. int n_errors_dropped;
  87. int n_warnings_dropped;
  88. int max_cps;
  89. int char_count;
  90. int err_count;
  91. int warn_count;
  92. uint64_t last_msec;
  93. uint64_t msec_count;
  94. bool locking; //hack to avoid a deadloop
  95. static void _print_handler(void *p_this, const String &p_string, bool p_error);
  96. PrintHandlerList phl;
  97. void _get_output();
  98. void _poll_events();
  99. uint32_t poll_every;
  100. SceneTree *scene_tree;
  101. bool _parse_live_edit(const Array &p_command);
  102. void _set_object_property(ObjectID p_id, const String &p_property, const Variant &p_value);
  103. void _send_object_id(ObjectID p_id);
  104. void _send_video_memory();
  105. Ref<MultiplayerAPI> multiplayer;
  106. ErrorHandlerList eh;
  107. static void _err_handler(void *, const char *, const char *, int p_line, const char *, const char *, ErrorHandlerType p_type);
  108. void _send_profiling_data(bool p_for_frame);
  109. void _send_network_profiling_data();
  110. void _send_network_bandwidth_usage();
  111. struct FrameData {
  112. StringName name;
  113. Array data;
  114. };
  115. Vector<FrameData> profile_frame_data;
  116. void _put_variable(const String &p_name, const Variant &p_variable);
  117. void _save_node(ObjectID id, const String &p_path);
  118. bool skip_breakpoints;
  119. public:
  120. struct ResourceUsage {
  121. String path;
  122. String format;
  123. String type;
  124. RID id;
  125. int vram;
  126. bool operator<(const ResourceUsage &p_img) const { return vram == p_img.vram ? id < p_img.id : vram > p_img.vram; }
  127. };
  128. typedef void (*ResourceUsageFunc)(List<ResourceUsage> *);
  129. static ResourceUsageFunc resource_usage_func;
  130. Error connect_to_host(const String &p_host, uint16_t p_port);
  131. virtual void debug(ScriptLanguage *p_script, bool p_can_continue = true, bool p_is_error_breakpoint = false);
  132. virtual void idle_poll();
  133. virtual void line_poll();
  134. virtual bool is_remote() const { return true; }
  135. virtual void request_quit();
  136. virtual void send_message(const String &p_message, const Array &p_args);
  137. 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);
  138. virtual void set_multiplayer(Ref<MultiplayerAPI> p_multiplayer);
  139. virtual bool is_profiling() const;
  140. virtual void add_profiling_frame_data(const StringName &p_name, const Array &p_data);
  141. virtual void profiling_start();
  142. virtual void profiling_end();
  143. virtual void profiling_set_frame_times(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time);
  144. virtual void set_skip_breakpoints(bool p_skip_breakpoints);
  145. void set_scene_tree(SceneTree *p_scene_tree) { scene_tree = p_scene_tree; };
  146. ScriptDebuggerRemote();
  147. ~ScriptDebuggerRemote();
  148. };
  149. #endif // SCRIPT_DEBUGGER_REMOTE_H