script_debugger_remote.h 5.6 KB

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