script_debugger_remote.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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 ScriptDebuggerRemote : public ScriptDebugger {
  38. struct Message {
  39. String message;
  40. Array data;
  41. };
  42. struct ProfileInfoSort {
  43. bool operator()(ScriptLanguage::ProfilingInfo *A, ScriptLanguage::ProfilingInfo *B) const {
  44. return A->total_time < B->total_time;
  45. }
  46. };
  47. Vector<ScriptLanguage::ProfilingInfo> profile_info;
  48. Vector<ScriptLanguage::ProfilingInfo *> profile_info_ptrs;
  49. Map<StringName, int> profiler_function_signature_map;
  50. float frame_time, idle_time, physics_time, physics_frame_time;
  51. bool profiling;
  52. int max_frame_functions;
  53. bool skip_profile_frame;
  54. bool reload_all_scripts;
  55. Ref<StreamPeerTCP> tcp_client;
  56. Ref<PacketPeerStream> packet_peer_stream;
  57. uint64_t last_perf_time;
  58. Object *performance;
  59. bool requested_quit;
  60. Mutex *mutex;
  61. struct OutputError {
  62. int hr;
  63. int min;
  64. int sec;
  65. int msec;
  66. String source_file;
  67. String source_func;
  68. int source_line;
  69. String error;
  70. String error_descr;
  71. bool warning;
  72. Array callstack;
  73. };
  74. List<String> output_strings;
  75. List<Message> messages;
  76. int max_messages_per_frame;
  77. int n_messages_dropped;
  78. List<OutputError> errors;
  79. int max_errors_per_frame;
  80. int n_errors_dropped;
  81. int max_cps;
  82. int char_count;
  83. uint64_t last_msec;
  84. uint64_t msec_count;
  85. OS::ProcessID allow_focus_steal_pid;
  86. bool locking; //hack to avoid a deadloop
  87. static void _print_handler(void *p_this, const String &p_string, bool p_error);
  88. PrintHandlerList phl;
  89. void _get_output();
  90. void _poll_events();
  91. uint32_t poll_every;
  92. bool _parse_live_edit(const Array &p_command);
  93. RequestSceneTreeMessageFunc request_scene_tree;
  94. void *request_scene_tree_ud;
  95. void _set_object_property(ObjectID p_id, const String &p_property, const Variant &p_value);
  96. void _send_object_id(ObjectID p_id);
  97. void _send_video_memory();
  98. LiveEditFuncs *live_edit_funcs;
  99. ErrorHandlerList eh;
  100. static void _err_handler(void *, const char *, const char *, int p_line, const char *, const char *, ErrorHandlerType p_type);
  101. void _send_profiling_data(bool p_for_frame);
  102. struct FrameData {
  103. StringName name;
  104. Array data;
  105. };
  106. Vector<FrameData> profile_frame_data;
  107. void _put_variable(const String &p_name, const Variant &p_variable);
  108. void _save_node(ObjectID id, const String &p_path);
  109. public:
  110. struct ResourceUsage {
  111. String path;
  112. String format;
  113. String type;
  114. RID id;
  115. int vram;
  116. bool operator<(const ResourceUsage &p_img) const { return vram == p_img.vram ? id < p_img.id : vram > p_img.vram; }
  117. };
  118. typedef void (*ResourceUsageFunc)(List<ResourceUsage> *);
  119. static ResourceUsageFunc resource_usage_func;
  120. Error connect_to_host(const String &p_host, uint16_t p_port);
  121. virtual void debug(ScriptLanguage *p_script, bool p_can_continue = true);
  122. virtual void idle_poll();
  123. virtual void line_poll();
  124. virtual bool is_remote() const { return true; }
  125. virtual void request_quit();
  126. virtual void send_message(const String &p_message, const Array &p_args);
  127. 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);
  128. virtual void set_request_scene_tree_message_func(RequestSceneTreeMessageFunc p_func, void *p_udata);
  129. virtual void set_live_edit_funcs(LiveEditFuncs *p_funcs);
  130. virtual bool is_profiling() const;
  131. virtual void add_profiling_frame_data(const StringName &p_name, const Array &p_data);
  132. virtual void profiling_start();
  133. virtual void profiling_end();
  134. virtual void profiling_set_frame_times(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time);
  135. void set_allow_focus_steal_pid(OS::ProcessID p_pid);
  136. ScriptDebuggerRemote();
  137. ~ScriptDebuggerRemote();
  138. };
  139. #endif // SCRIPT_DEBUGGER_REMOTE_H