script_editor_debugger.cpp 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130
  1. /**************************************************************************/
  2. /* script_editor_debugger.cpp */
  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. #include "script_editor_debugger.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/debugger/debugger_marshalls.h"
  33. #include "core/debugger/remote_debugger.h"
  34. #include "core/io/marshalls.h"
  35. #include "core/string/ustring.h"
  36. #include "core/version.h"
  37. #include "editor/debugger/debug_adapter/debug_adapter_protocol.h"
  38. #include "editor/debugger/editor_performance_profiler.h"
  39. #include "editor/debugger/editor_profiler.h"
  40. #include "editor/debugger/editor_visual_profiler.h"
  41. #include "editor/editor_file_system.h"
  42. #include "editor/editor_log.h"
  43. #include "editor/editor_node.h"
  44. #include "editor/editor_property_name_processor.h"
  45. #include "editor/editor_scale.h"
  46. #include "editor/editor_settings.h"
  47. #include "editor/gui/editor_file_dialog.h"
  48. #include "editor/inspector_dock.h"
  49. #include "editor/plugins/canvas_item_editor_plugin.h"
  50. #include "editor/plugins/editor_debugger_plugin.h"
  51. #include "editor/plugins/node_3d_editor_plugin.h"
  52. #include "main/performance.h"
  53. #include "scene/3d/camera_3d.h"
  54. #include "scene/debugger/scene_debugger.h"
  55. #include "scene/gui/dialogs.h"
  56. #include "scene/gui/grid_container.h"
  57. #include "scene/gui/label.h"
  58. #include "scene/gui/line_edit.h"
  59. #include "scene/gui/margin_container.h"
  60. #include "scene/gui/rich_text_label.h"
  61. #include "scene/gui/separator.h"
  62. #include "scene/gui/split_container.h"
  63. #include "scene/gui/tab_container.h"
  64. #include "scene/gui/texture_button.h"
  65. #include "scene/gui/tree.h"
  66. #include "scene/resources/packed_scene.h"
  67. #include "servers/debugger/servers_debugger.h"
  68. #include "servers/display_server.h"
  69. using CameraOverride = EditorDebuggerNode::CameraOverride;
  70. void ScriptEditorDebugger::_put_msg(String p_message, Array p_data, uint64_t p_thread_id) {
  71. ERR_FAIL_COND(p_thread_id == Thread::UNASSIGNED_ID);
  72. if (is_session_active()) {
  73. Array msg;
  74. msg.push_back(p_message);
  75. msg.push_back(p_thread_id);
  76. msg.push_back(p_data);
  77. peer->put_message(msg);
  78. }
  79. }
  80. void ScriptEditorDebugger::debug_copy() {
  81. String msg = reason->get_text();
  82. if (msg.is_empty()) {
  83. return;
  84. }
  85. DisplayServer::get_singleton()->clipboard_set(msg);
  86. }
  87. void ScriptEditorDebugger::debug_skip_breakpoints() {
  88. skip_breakpoints_value = !skip_breakpoints_value;
  89. if (skip_breakpoints_value) {
  90. skip_breakpoints->set_icon(get_theme_icon(SNAME("DebugSkipBreakpointsOn"), SNAME("EditorIcons")));
  91. } else {
  92. skip_breakpoints->set_icon(get_theme_icon(SNAME("DebugSkipBreakpointsOff"), SNAME("EditorIcons")));
  93. }
  94. Array msg;
  95. msg.push_back(skip_breakpoints_value);
  96. _put_msg("set_skip_breakpoints", msg, debugging_thread_id != Thread::UNASSIGNED_ID ? debugging_thread_id : Thread::MAIN_ID);
  97. }
  98. void ScriptEditorDebugger::debug_next() {
  99. ERR_FAIL_COND(!is_breaked());
  100. _put_msg("next", Array(), debugging_thread_id);
  101. _clear_execution();
  102. }
  103. void ScriptEditorDebugger::debug_step() {
  104. ERR_FAIL_COND(!is_breaked());
  105. _put_msg("step", Array(), debugging_thread_id);
  106. _clear_execution();
  107. }
  108. void ScriptEditorDebugger::debug_break() {
  109. ERR_FAIL_COND(is_breaked());
  110. _put_msg("break", Array());
  111. }
  112. void ScriptEditorDebugger::debug_continue() {
  113. ERR_FAIL_COND(!is_breaked());
  114. // Allow focus stealing only if we actually run this client for security.
  115. if (remote_pid && EditorNode::get_singleton()->has_child_process(remote_pid)) {
  116. DisplayServer::get_singleton()->enable_for_stealing_focus(remote_pid);
  117. }
  118. _clear_execution();
  119. _put_msg("continue", Array(), debugging_thread_id);
  120. _put_msg("servers:foreground", Array());
  121. }
  122. void ScriptEditorDebugger::update_tabs() {
  123. if (error_count == 0 && warning_count == 0) {
  124. errors_tab->set_name(TTR("Errors"));
  125. tabs->set_tab_icon(tabs->get_tab_idx_from_control(errors_tab), Ref<Texture2D>());
  126. } else {
  127. errors_tab->set_name(TTR("Errors") + " (" + itos(error_count + warning_count) + ")");
  128. if (error_count >= 1 && warning_count >= 1) {
  129. tabs->set_tab_icon(tabs->get_tab_idx_from_control(errors_tab), get_theme_icon(SNAME("ErrorWarning"), SNAME("EditorIcons")));
  130. } else if (error_count >= 1) {
  131. tabs->set_tab_icon(tabs->get_tab_idx_from_control(errors_tab), get_theme_icon(SNAME("Error"), SNAME("EditorIcons")));
  132. } else {
  133. tabs->set_tab_icon(tabs->get_tab_idx_from_control(errors_tab), get_theme_icon(SNAME("Warning"), SNAME("EditorIcons")));
  134. }
  135. }
  136. }
  137. void ScriptEditorDebugger::clear_style() {
  138. tabs->remove_theme_style_override("panel");
  139. }
  140. void ScriptEditorDebugger::save_node(ObjectID p_id, const String &p_file) {
  141. Array msg;
  142. msg.push_back(p_id);
  143. msg.push_back(p_file);
  144. _put_msg("scene:save_node", msg);
  145. }
  146. void ScriptEditorDebugger::_file_selected(const String &p_file) {
  147. switch (file_dialog_purpose) {
  148. case SAVE_MONITORS_CSV: {
  149. Error err;
  150. Ref<FileAccess> file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  151. if (err != OK) {
  152. ERR_PRINT("Failed to open " + p_file);
  153. return;
  154. }
  155. Vector<String> line;
  156. line.resize(Performance::MONITOR_MAX);
  157. // signatures
  158. for (int i = 0; i < Performance::MONITOR_MAX; i++) {
  159. line.write[i] = Performance::get_singleton()->get_monitor_name(Performance::Monitor(i));
  160. }
  161. file->store_csv_line(line);
  162. // values
  163. Vector<List<float>::Element *> iterators;
  164. iterators.resize(Performance::MONITOR_MAX);
  165. bool continue_iteration = false;
  166. for (int i = 0; i < Performance::MONITOR_MAX; i++) {
  167. iterators.write[i] = performance_profiler->get_monitor_data(Performance::get_singleton()->get_monitor_name(Performance::Monitor(i)))->back();
  168. continue_iteration = continue_iteration || iterators[i];
  169. }
  170. while (continue_iteration) {
  171. continue_iteration = false;
  172. for (int i = 0; i < Performance::MONITOR_MAX; i++) {
  173. if (iterators[i]) {
  174. line.write[i] = String::num_real(iterators[i]->get());
  175. iterators.write[i] = iterators[i]->prev();
  176. } else {
  177. line.write[i] = "";
  178. }
  179. continue_iteration = continue_iteration || iterators[i];
  180. }
  181. file->store_csv_line(line);
  182. }
  183. file->store_string("\n");
  184. Vector<Vector<String>> profiler_data = profiler->get_data_as_csv();
  185. for (int i = 0; i < profiler_data.size(); i++) {
  186. file->store_csv_line(profiler_data[i]);
  187. }
  188. } break;
  189. case SAVE_VRAM_CSV: {
  190. Error err;
  191. Ref<FileAccess> file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  192. if (err != OK) {
  193. ERR_PRINT("Failed to open " + p_file);
  194. return;
  195. }
  196. Vector<String> headers;
  197. headers.resize(vmem_tree->get_columns());
  198. for (int i = 0; i < vmem_tree->get_columns(); ++i) {
  199. headers.write[i] = vmem_tree->get_column_title(i);
  200. }
  201. file->store_csv_line(headers);
  202. if (vmem_tree->get_root()) {
  203. TreeItem *ti = vmem_tree->get_root()->get_first_child();
  204. while (ti) {
  205. Vector<String> values;
  206. values.resize(vmem_tree->get_columns());
  207. for (int i = 0; i < vmem_tree->get_columns(); ++i) {
  208. values.write[i] = ti->get_text(i);
  209. }
  210. file->store_csv_line(values);
  211. ti = ti->get_next();
  212. }
  213. }
  214. } break;
  215. }
  216. }
  217. void ScriptEditorDebugger::request_remote_tree() {
  218. _put_msg("scene:request_scene_tree", Array());
  219. }
  220. const SceneDebuggerTree *ScriptEditorDebugger::get_remote_tree() {
  221. return scene_tree;
  222. }
  223. void ScriptEditorDebugger::update_remote_object(ObjectID p_obj_id, const String &p_prop, const Variant &p_value) {
  224. Array msg;
  225. msg.push_back(p_obj_id);
  226. msg.push_back(p_prop);
  227. msg.push_back(p_value);
  228. _put_msg("scene:set_object_property", msg);
  229. }
  230. void ScriptEditorDebugger::request_remote_object(ObjectID p_obj_id) {
  231. ERR_FAIL_COND(p_obj_id.is_null());
  232. Array msg;
  233. msg.push_back(p_obj_id);
  234. _put_msg("scene:inspect_object", msg);
  235. }
  236. Object *ScriptEditorDebugger::get_remote_object(ObjectID p_id) {
  237. return inspector->get_object(p_id);
  238. }
  239. void ScriptEditorDebugger::_remote_object_selected(ObjectID p_id) {
  240. emit_signal(SNAME("remote_object_requested"), p_id);
  241. }
  242. void ScriptEditorDebugger::_remote_object_edited(ObjectID p_id, const String &p_prop, const Variant &p_value) {
  243. update_remote_object(p_id, p_prop, p_value);
  244. request_remote_object(p_id);
  245. }
  246. void ScriptEditorDebugger::_remote_object_property_updated(ObjectID p_id, const String &p_property) {
  247. emit_signal(SNAME("remote_object_property_updated"), p_id, p_property);
  248. }
  249. void ScriptEditorDebugger::_video_mem_request() {
  250. _put_msg("servers:memory", Array());
  251. }
  252. void ScriptEditorDebugger::_video_mem_export() {
  253. file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
  254. file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  255. file_dialog->clear_filters();
  256. file_dialog_purpose = SAVE_VRAM_CSV;
  257. file_dialog->popup_file_dialog();
  258. }
  259. Size2 ScriptEditorDebugger::get_minimum_size() const {
  260. Size2 ms = MarginContainer::get_minimum_size();
  261. ms.y = MAX(ms.y, 250 * EDSCALE);
  262. return ms;
  263. }
  264. void ScriptEditorDebugger::_thread_debug_enter(uint64_t p_thread_id) {
  265. ERR_FAIL_COND(!threads_debugged.has(p_thread_id));
  266. ThreadDebugged &td = threads_debugged[p_thread_id];
  267. _set_reason_text(td.error, MESSAGE_ERROR);
  268. emit_signal(SNAME("breaked"), true, td.can_debug, td.error, td.has_stackdump);
  269. if (!td.error.is_empty()) {
  270. tabs->set_current_tab(0);
  271. }
  272. inspector->clear_cache(); // Take a chance to force remote objects update.
  273. _put_msg("get_stack_dump", Array(), p_thread_id);
  274. }
  275. void ScriptEditorDebugger::_select_thread(int p_index) {
  276. debugging_thread_id = threads->get_item_metadata(threads->get_selected());
  277. _thread_debug_enter(debugging_thread_id);
  278. }
  279. void ScriptEditorDebugger::_parse_message(const String &p_msg, uint64_t p_thread_id, const Array &p_data) {
  280. emit_signal(SNAME("debug_data"), p_msg, p_data);
  281. if (p_msg == "debug_enter") {
  282. ERR_FAIL_COND(p_data.size() != 4);
  283. ThreadDebugged td;
  284. td.name = p_data[3];
  285. td.error = p_data[1];
  286. td.can_debug = p_data[0];
  287. td.has_stackdump = p_data[2];
  288. td.thread_id = p_thread_id;
  289. static uint32_t order_inc = 0;
  290. td.debug_order = order_inc++;
  291. threads_debugged.insert(p_thread_id, td);
  292. if (threads_debugged.size() == 1) {
  293. // First thread that requests debug
  294. debugging_thread_id = p_thread_id;
  295. _thread_debug_enter(p_thread_id);
  296. can_request_idle_draw = true;
  297. if (is_move_to_foreground()) {
  298. DisplayServer::get_singleton()->window_move_to_foreground();
  299. }
  300. profiler->set_enabled(false, false);
  301. visual_profiler->set_enabled(false);
  302. }
  303. _update_buttons_state();
  304. } else if (p_msg == "debug_exit") {
  305. threads_debugged.erase(p_thread_id);
  306. if (p_thread_id == debugging_thread_id) {
  307. _clear_execution();
  308. if (threads_debugged.size() == 0) {
  309. debugging_thread_id = Thread::UNASSIGNED_ID;
  310. } else {
  311. // Find next thread to debug.
  312. uint32_t min_order = 0xFFFFFFFF;
  313. uint64_t next_thread = Thread::UNASSIGNED_ID;
  314. for (KeyValue<uint64_t, ThreadDebugged> T : threads_debugged) {
  315. if (T.value.debug_order < min_order) {
  316. min_order = T.value.debug_order;
  317. next_thread = T.key;
  318. }
  319. }
  320. debugging_thread_id = next_thread;
  321. }
  322. if (debugging_thread_id == Thread::UNASSIGNED_ID) {
  323. // Nothing else to debug.
  324. profiler->set_enabled(true, false);
  325. profiler->disable_seeking();
  326. visual_profiler->set_enabled(true);
  327. _set_reason_text(TTR("Execution resumed."), MESSAGE_SUCCESS);
  328. emit_signal(SNAME("breaked"), false, false, "", false);
  329. _update_buttons_state();
  330. } else {
  331. _thread_debug_enter(debugging_thread_id);
  332. }
  333. } else {
  334. _update_buttons_state();
  335. }
  336. } else if (p_msg == "set_pid") {
  337. ERR_FAIL_COND(p_data.size() < 1);
  338. remote_pid = p_data[0];
  339. } else if (p_msg == "scene:click_ctrl") {
  340. ERR_FAIL_COND(p_data.size() < 2);
  341. clicked_ctrl->set_text(p_data[0]);
  342. clicked_ctrl_type->set_text(p_data[1]);
  343. } else if (p_msg == "scene:scene_tree") {
  344. scene_tree->nodes.clear();
  345. scene_tree->deserialize(p_data);
  346. emit_signal(SNAME("remote_tree_updated"));
  347. _update_buttons_state();
  348. } else if (p_msg == "scene:inspect_object") {
  349. ObjectID id = inspector->add_object(p_data);
  350. if (id.is_valid()) {
  351. emit_signal(SNAME("remote_object_updated"), id);
  352. }
  353. } else if (p_msg == "servers:memory_usage") {
  354. vmem_tree->clear();
  355. TreeItem *root = vmem_tree->create_item();
  356. ServersDebugger::ResourceUsage usage;
  357. usage.deserialize(p_data);
  358. uint64_t total = 0;
  359. for (const ServersDebugger::ResourceInfo &E : usage.infos) {
  360. TreeItem *it = vmem_tree->create_item(root);
  361. String type = E.type;
  362. int bytes = E.vram;
  363. it->set_text(0, E.path);
  364. it->set_text(1, type);
  365. it->set_text(2, E.format);
  366. it->set_text(3, String::humanize_size(bytes));
  367. total += bytes;
  368. if (has_theme_icon(type, SNAME("EditorIcons"))) {
  369. it->set_icon(0, get_theme_icon(type, SNAME("EditorIcons")));
  370. }
  371. }
  372. vmem_total->set_tooltip_text(TTR("Bytes:") + " " + itos(total));
  373. vmem_total->set_text(String::humanize_size(total));
  374. } else if (p_msg == "servers:drawn") {
  375. can_request_idle_draw = true;
  376. } else if (p_msg == "stack_dump") {
  377. DebuggerMarshalls::ScriptStackDump stack;
  378. stack.deserialize(p_data);
  379. stack_dump->clear();
  380. inspector->clear_stack_variables();
  381. TreeItem *r = stack_dump->create_item();
  382. Array stack_dump_info;
  383. for (int i = 0; i < stack.frames.size(); i++) {
  384. TreeItem *s = stack_dump->create_item(r);
  385. Dictionary d;
  386. d["frame"] = i;
  387. d["file"] = stack.frames[i].file;
  388. d["function"] = stack.frames[i].func;
  389. d["line"] = stack.frames[i].line;
  390. stack_dump_info.push_back(d);
  391. s->set_metadata(0, d);
  392. String line = itos(i) + " - " + String(d["file"]) + ":" + itos(d["line"]) + " - at function: " + String(d["function"]);
  393. s->set_text(0, line);
  394. if (i == 0) {
  395. s->select(0);
  396. }
  397. }
  398. emit_signal(SNAME("stack_dump"), stack_dump_info);
  399. } else if (p_msg == "stack_frame_vars") {
  400. inspector->clear_stack_variables();
  401. ERR_FAIL_COND(p_data.size() != 1);
  402. emit_signal(SNAME("stack_frame_vars"), p_data[0]);
  403. } else if (p_msg == "stack_frame_var") {
  404. inspector->add_stack_variable(p_data);
  405. emit_signal(SNAME("stack_frame_var"), p_data);
  406. } else if (p_msg == "output") {
  407. ERR_FAIL_COND(p_data.size() != 2);
  408. ERR_FAIL_COND(p_data[0].get_type() != Variant::PACKED_STRING_ARRAY);
  409. Vector<String> output_strings = p_data[0];
  410. ERR_FAIL_COND(p_data[1].get_type() != Variant::PACKED_INT32_ARRAY);
  411. Vector<int> output_types = p_data[1];
  412. ERR_FAIL_COND(output_strings.size() != output_types.size());
  413. for (int i = 0; i < output_strings.size(); i++) {
  414. RemoteDebugger::MessageType type = (RemoteDebugger::MessageType)(int)(output_types[i]);
  415. EditorLog::MessageType msg_type;
  416. switch (type) {
  417. case RemoteDebugger::MESSAGE_TYPE_LOG: {
  418. msg_type = EditorLog::MSG_TYPE_STD;
  419. } break;
  420. case RemoteDebugger::MESSAGE_TYPE_LOG_RICH: {
  421. msg_type = EditorLog::MSG_TYPE_STD_RICH;
  422. } break;
  423. case RemoteDebugger::MESSAGE_TYPE_ERROR: {
  424. msg_type = EditorLog::MSG_TYPE_ERROR;
  425. } break;
  426. default: {
  427. WARN_PRINT("Unhandled script debugger message type: " + itos(type));
  428. msg_type = EditorLog::MSG_TYPE_STD;
  429. } break;
  430. }
  431. EditorNode::get_log()->add_message(output_strings[i], msg_type);
  432. emit_signal(SNAME("output"), output_strings[i]);
  433. }
  434. } else if (p_msg == "performance:profile_frame") {
  435. Vector<float> frame_data;
  436. frame_data.resize(p_data.size());
  437. for (int i = 0; i < p_data.size(); i++) {
  438. frame_data.write[i] = p_data[i];
  439. }
  440. performance_profiler->add_profile_frame(frame_data);
  441. } else if (p_msg == "visual:profile_frame") {
  442. ServersDebugger::VisualProfilerFrame frame;
  443. frame.deserialize(p_data);
  444. EditorVisualProfiler::Metric metric;
  445. metric.areas.resize(frame.areas.size());
  446. metric.frame_number = frame.frame_number;
  447. metric.valid = true;
  448. {
  449. EditorVisualProfiler::Metric::Area *areas_ptr = metric.areas.ptrw();
  450. for (int i = 0; i < frame.areas.size(); i++) {
  451. areas_ptr[i].name = frame.areas[i].name;
  452. areas_ptr[i].cpu_time = frame.areas[i].cpu_msec;
  453. areas_ptr[i].gpu_time = frame.areas[i].gpu_msec;
  454. }
  455. }
  456. visual_profiler->add_frame_metric(metric);
  457. } else if (p_msg == "error") {
  458. DebuggerMarshalls::OutputError oe;
  459. ERR_FAIL_COND_MSG(oe.deserialize(p_data) == false, "Failed to deserialize error message");
  460. // Format time.
  461. Array time_vals;
  462. time_vals.push_back(oe.hr);
  463. time_vals.push_back(oe.min);
  464. time_vals.push_back(oe.sec);
  465. time_vals.push_back(oe.msec);
  466. bool e;
  467. String time = String("%d:%02d:%02d:%04d").sprintf(time_vals, &e);
  468. // Rest of the error data.
  469. bool source_is_project_file = oe.source_file.begins_with("res://");
  470. // Metadata to highlight error line in scripts.
  471. Array source_meta;
  472. source_meta.push_back(oe.source_file);
  473. source_meta.push_back(oe.source_line);
  474. // Create error tree to display above error or warning details.
  475. TreeItem *r = error_tree->get_root();
  476. if (!r) {
  477. r = error_tree->create_item();
  478. }
  479. // Also provide the relevant details as tooltip to quickly check without
  480. // uncollapsing the tree.
  481. String tooltip = oe.warning ? TTR("Warning:") : TTR("Error:");
  482. TreeItem *error = error_tree->create_item(r);
  483. if (oe.warning) {
  484. error->set_meta("_is_warning", true);
  485. } else {
  486. error->set_meta("_is_error", true);
  487. }
  488. error->set_collapsed(true);
  489. error->set_icon(0, get_theme_icon(oe.warning ? SNAME("Warning") : SNAME("Error"), SNAME("EditorIcons")));
  490. error->set_text(0, time);
  491. error->set_text_alignment(0, HORIZONTAL_ALIGNMENT_LEFT);
  492. const Color color = get_theme_color(oe.warning ? SNAME("warning_color") : SNAME("error_color"), SNAME("Editor"));
  493. error->set_custom_color(0, color);
  494. error->set_custom_color(1, color);
  495. String error_title;
  496. if (!oe.source_func.is_empty() && source_is_project_file) {
  497. // If source function is inside the project file.
  498. error_title += oe.source_func + ": ";
  499. } else if (oe.callstack.size() > 0) {
  500. // Otherwise, if available, use the script's stack in the error title.
  501. error_title = _format_frame_text(&oe.callstack[0]) + ": ";
  502. } else if (!oe.source_func.is_empty()) {
  503. // Otherwise try to use the C++ source function.
  504. error_title += oe.source_func + ": ";
  505. }
  506. // If we have a (custom) error message, use it as title, and add a C++ Error
  507. // item with the original error condition.
  508. error_title += oe.error_descr.is_empty() ? oe.error : oe.error_descr;
  509. error->set_text(1, error_title);
  510. tooltip += " " + error_title + "\n";
  511. // Find the language of the error's source file.
  512. String source_language_name = "C++"; // Default value is the old hard-coded one.
  513. const String source_file_extension = oe.source_file.get_extension();
  514. for (int i = 0; i < ScriptServer::get_language_count(); ++i) {
  515. ScriptLanguage *script_language = ScriptServer::get_language(i);
  516. if (source_file_extension == script_language->get_extension()) {
  517. source_language_name = script_language->get_name();
  518. break;
  519. }
  520. }
  521. if (!oe.error_descr.is_empty()) {
  522. // Add item for C++ error condition.
  523. TreeItem *cpp_cond = error_tree->create_item(error);
  524. // TRANSLATORS: %s is the name of a language, e.g. C++.
  525. cpp_cond->set_text(0, "<" + vformat(TTR("%s Error"), source_language_name) + ">");
  526. cpp_cond->set_text(1, oe.error);
  527. cpp_cond->set_text_alignment(0, HORIZONTAL_ALIGNMENT_LEFT);
  528. tooltip += vformat(TTR("%s Error:"), source_language_name) + " " + oe.error + "\n";
  529. if (source_is_project_file) {
  530. cpp_cond->set_metadata(0, source_meta);
  531. }
  532. }
  533. Vector<uint8_t> v;
  534. v.resize(100);
  535. // Source of the error.
  536. String source_txt = (source_is_project_file ? oe.source_file.get_file() : oe.source_file) + ":" + itos(oe.source_line);
  537. if (!oe.source_func.is_empty()) {
  538. source_txt += " @ " + oe.source_func;
  539. if (!oe.source_func.ends_with(")")) {
  540. source_txt += "()";
  541. }
  542. }
  543. TreeItem *cpp_source = error_tree->create_item(error);
  544. // TRANSLATORS: %s is the name of a language, e.g. C++.
  545. cpp_source->set_text(0, "<" + vformat(TTR("%s Source"), source_language_name) + ">");
  546. cpp_source->set_text(1, source_txt);
  547. cpp_source->set_text_alignment(0, HORIZONTAL_ALIGNMENT_LEFT);
  548. tooltip += vformat(TTR("%s Source:"), source_language_name) + " " + source_txt + "\n";
  549. // Set metadata to highlight error line in scripts.
  550. if (source_is_project_file) {
  551. error->set_metadata(0, source_meta);
  552. cpp_source->set_metadata(0, source_meta);
  553. }
  554. // Format stack trace.
  555. // stack_items_count is the number of elements to parse, with 3 items per frame
  556. // of the stack trace (script, method, line).
  557. const ScriptLanguage::StackInfo *infos = oe.callstack.ptr();
  558. for (unsigned int i = 0; i < (unsigned int)oe.callstack.size(); i++) {
  559. TreeItem *stack_trace = error_tree->create_item(error);
  560. Array meta;
  561. meta.push_back(infos[i].file);
  562. meta.push_back(infos[i].line);
  563. stack_trace->set_metadata(0, meta);
  564. if (i == 0) {
  565. stack_trace->set_text(0, "<" + TTR("Stack Trace") + ">");
  566. stack_trace->set_text_alignment(0, HORIZONTAL_ALIGNMENT_LEFT);
  567. if (!source_is_project_file) {
  568. // Only override metadata if the source is not inside the project.
  569. error->set_metadata(0, meta);
  570. }
  571. tooltip += TTR("Stack Trace:") + "\n";
  572. }
  573. String frame_txt = _format_frame_text(&infos[i]);
  574. tooltip += frame_txt + "\n";
  575. stack_trace->set_text(1, frame_txt);
  576. }
  577. error->set_tooltip_text(0, tooltip);
  578. error->set_tooltip_text(1, tooltip);
  579. if (warning_count == 0 && error_count == 0) {
  580. expand_all_button->set_disabled(false);
  581. collapse_all_button->set_disabled(false);
  582. clear_button->set_disabled(false);
  583. }
  584. if (oe.warning) {
  585. warning_count++;
  586. } else {
  587. error_count++;
  588. }
  589. } else if (p_msg == "servers:function_signature") {
  590. // Cache a profiler signature.
  591. ServersDebugger::ScriptFunctionSignature sig;
  592. sig.deserialize(p_data);
  593. profiler_signature[sig.id] = sig.name;
  594. } else if (p_msg == "servers:profile_frame" || p_msg == "servers:profile_total") {
  595. EditorProfiler::Metric metric;
  596. ServersDebugger::ServersProfilerFrame frame;
  597. frame.deserialize(p_data);
  598. metric.valid = true;
  599. metric.frame_number = frame.frame_number;
  600. metric.frame_time = frame.frame_time;
  601. metric.process_time = frame.process_time;
  602. metric.physics_time = frame.physics_time;
  603. metric.physics_frame_time = frame.physics_frame_time;
  604. if (frame.servers.size()) {
  605. EditorProfiler::Metric::Category frame_time;
  606. frame_time.signature = "category_frame_time";
  607. frame_time.name = "Frame Time";
  608. frame_time.total_time = metric.frame_time;
  609. EditorProfiler::Metric::Category::Item item;
  610. item.calls = 1;
  611. item.line = 0;
  612. item.name = "Physics Time";
  613. item.total = metric.physics_time;
  614. item.self = item.total;
  615. item.signature = "physics_time";
  616. frame_time.items.push_back(item);
  617. item.name = "Process Time";
  618. item.total = metric.process_time;
  619. item.self = item.total;
  620. item.signature = "process_time";
  621. frame_time.items.push_back(item);
  622. item.name = "Physics Frame Time";
  623. item.total = metric.physics_frame_time;
  624. item.self = item.total;
  625. item.signature = "physics_frame_time";
  626. frame_time.items.push_back(item);
  627. metric.categories.push_back(frame_time);
  628. }
  629. for (int i = 0; i < frame.servers.size(); i++) {
  630. const ServersDebugger::ServerInfo &srv = frame.servers[i];
  631. EditorProfiler::Metric::Category c;
  632. const String name = srv.name;
  633. c.name = EditorPropertyNameProcessor::get_singleton()->process_name(name, EditorPropertyNameProcessor::STYLE_CAPITALIZED);
  634. c.items.resize(srv.functions.size());
  635. c.total_time = 0;
  636. c.signature = "categ::" + name;
  637. for (int j = 0; j < srv.functions.size(); j++) {
  638. EditorProfiler::Metric::Category::Item item;
  639. item.calls = 1;
  640. item.line = 0;
  641. item.name = srv.functions[j].name;
  642. item.self = srv.functions[j].time;
  643. item.total = item.self;
  644. item.signature = "categ::" + name + "::" + item.name;
  645. item.name = EditorPropertyNameProcessor::get_singleton()->process_name(item.name, EditorPropertyNameProcessor::STYLE_CAPITALIZED);
  646. c.total_time += item.total;
  647. c.items.write[j] = item;
  648. }
  649. metric.categories.push_back(c);
  650. }
  651. EditorProfiler::Metric::Category funcs;
  652. funcs.total_time = frame.script_time;
  653. funcs.items.resize(frame.script_functions.size());
  654. funcs.name = "Script Functions";
  655. funcs.signature = "script_functions";
  656. for (int i = 0; i < frame.script_functions.size(); i++) {
  657. int signature = frame.script_functions[i].sig_id;
  658. int calls = frame.script_functions[i].call_count;
  659. float total = frame.script_functions[i].total_time;
  660. float self = frame.script_functions[i].self_time;
  661. EditorProfiler::Metric::Category::Item item;
  662. if (profiler_signature.has(signature)) {
  663. item.signature = profiler_signature[signature];
  664. String name = profiler_signature[signature];
  665. Vector<String> strings = name.split("::");
  666. if (strings.size() == 3) {
  667. item.name = strings[2];
  668. item.script = strings[0];
  669. item.line = strings[1].to_int();
  670. } else if (strings.size() == 4) { //Built-in scripts have an :: in their name
  671. item.name = strings[3];
  672. item.script = strings[0] + "::" + strings[1];
  673. item.line = strings[2].to_int();
  674. }
  675. } else {
  676. item.name = "SigErr " + itos(signature);
  677. }
  678. item.calls = calls;
  679. item.self = self;
  680. item.total = total;
  681. funcs.items.write[i] = item;
  682. }
  683. metric.categories.push_back(funcs);
  684. if (p_msg == "servers:profile_frame") {
  685. profiler->add_frame_metric(metric, false);
  686. } else {
  687. profiler->add_frame_metric(metric, true);
  688. }
  689. } else if (p_msg == "request_quit") {
  690. emit_signal(SNAME("stop_requested"));
  691. _stop_and_notify();
  692. } else if (p_msg == "performance:profile_names") {
  693. Vector<StringName> monitors;
  694. monitors.resize(p_data.size());
  695. for (int i = 0; i < p_data.size(); i++) {
  696. ERR_FAIL_COND(p_data[i].get_type() != Variant::STRING_NAME);
  697. monitors.set(i, p_data[i]);
  698. }
  699. performance_profiler->update_monitors(monitors);
  700. } else if (p_msg == "filesystem:update_file") {
  701. ERR_FAIL_COND(p_data.size() < 1);
  702. if (EditorFileSystem::get_singleton()) {
  703. EditorFileSystem::get_singleton()->update_file(p_data[0]);
  704. }
  705. } else {
  706. int colon_index = p_msg.find_char(':');
  707. ERR_FAIL_COND_MSG(colon_index < 1, "Invalid message received");
  708. bool parsed = EditorDebuggerNode::get_singleton()->plugins_capture(this, p_msg, p_data);
  709. if (!parsed) {
  710. WARN_PRINT("unknown message " + p_msg);
  711. }
  712. }
  713. }
  714. void ScriptEditorDebugger::_set_reason_text(const String &p_reason, MessageType p_type) {
  715. switch (p_type) {
  716. case MESSAGE_ERROR:
  717. reason->add_theme_color_override("font_color", get_theme_color(SNAME("error_color"), SNAME("Editor")));
  718. break;
  719. case MESSAGE_WARNING:
  720. reason->add_theme_color_override("font_color", get_theme_color(SNAME("warning_color"), SNAME("Editor")));
  721. break;
  722. default:
  723. reason->add_theme_color_override("font_color", get_theme_color(SNAME("success_color"), SNAME("Editor")));
  724. }
  725. reason->set_text(p_reason);
  726. const PackedInt32Array boundaries = TS->string_get_word_breaks(p_reason, "", 80);
  727. PackedStringArray lines;
  728. for (int i = 0; i < boundaries.size(); i += 2) {
  729. const int start = boundaries[i];
  730. const int end = boundaries[i + 1];
  731. lines.append(p_reason.substr(start, end - start + 1));
  732. }
  733. reason->set_tooltip_text(String("\n").join(lines));
  734. }
  735. void ScriptEditorDebugger::_notification(int p_what) {
  736. switch (p_what) {
  737. case NOTIFICATION_ENTER_TREE: {
  738. le_set->connect("pressed", callable_mp(this, &ScriptEditorDebugger::_live_edit_set));
  739. le_clear->connect("pressed", callable_mp(this, &ScriptEditorDebugger::_live_edit_clear));
  740. error_tree->connect("item_selected", callable_mp(this, &ScriptEditorDebugger::_error_selected));
  741. error_tree->connect("item_activated", callable_mp(this, &ScriptEditorDebugger::_error_activated));
  742. breakpoints_tree->connect("item_activated", callable_mp(this, &ScriptEditorDebugger::_breakpoint_tree_clicked));
  743. [[fallthrough]];
  744. }
  745. case NOTIFICATION_THEME_CHANGED: {
  746. tabs->add_theme_style_override("panel", get_theme_stylebox(SNAME("DebuggerPanel"), SNAME("EditorStyles")));
  747. skip_breakpoints->set_icon(get_theme_icon(skip_breakpoints_value ? SNAME("DebugSkipBreakpointsOn") : SNAME("DebugSkipBreakpointsOff"), SNAME("EditorIcons")));
  748. copy->set_icon(get_theme_icon(SNAME("ActionCopy"), SNAME("EditorIcons")));
  749. step->set_icon(get_theme_icon(SNAME("DebugStep"), SNAME("EditorIcons")));
  750. next->set_icon(get_theme_icon(SNAME("DebugNext"), SNAME("EditorIcons")));
  751. dobreak->set_icon(get_theme_icon(SNAME("Pause"), SNAME("EditorIcons")));
  752. docontinue->set_icon(get_theme_icon(SNAME("DebugContinue"), SNAME("EditorIcons")));
  753. vmem_refresh->set_icon(get_theme_icon(SNAME("Reload"), SNAME("EditorIcons")));
  754. vmem_export->set_icon(get_theme_icon(SNAME("Save"), SNAME("EditorIcons")));
  755. search->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
  756. reason->add_theme_color_override("font_color", get_theme_color(SNAME("error_color"), SNAME("Editor")));
  757. TreeItem *error_root = error_tree->get_root();
  758. if (error_root) {
  759. TreeItem *error = error_root->get_first_child();
  760. while (error) {
  761. if (error->has_meta("_is_warning")) {
  762. error->set_icon(0, get_theme_icon(SNAME("Warning"), SNAME("EditorIcons")));
  763. error->set_custom_color(0, get_theme_color(SNAME("warning_color"), SNAME("Editor")));
  764. error->set_custom_color(1, get_theme_color(SNAME("warning_color"), SNAME("Editor")));
  765. } else if (error->has_meta("_is_error")) {
  766. error->set_icon(0, get_theme_icon(SNAME("Error"), SNAME("EditorIcons")));
  767. error->set_custom_color(0, get_theme_color(SNAME("error_color"), SNAME("Editor")));
  768. error->set_custom_color(1, get_theme_color(SNAME("error_color"), SNAME("Editor")));
  769. }
  770. error = error->get_next();
  771. }
  772. }
  773. } break;
  774. case NOTIFICATION_PROCESS: {
  775. if (is_session_active()) {
  776. peer->poll();
  777. if (camera_override == CameraOverride::OVERRIDE_2D) {
  778. Dictionary state = CanvasItemEditor::get_singleton()->get_state();
  779. float zoom = state["zoom"];
  780. Point2 offset = state["ofs"];
  781. Transform2D transform;
  782. transform.scale_basis(Size2(zoom, zoom));
  783. transform.columns[2] = -offset * zoom;
  784. Array msg;
  785. msg.push_back(transform);
  786. _put_msg("scene:override_camera_2D:transform", msg);
  787. } else if (camera_override >= CameraOverride::OVERRIDE_3D_1) {
  788. int viewport_idx = camera_override - CameraOverride::OVERRIDE_3D_1;
  789. Node3DEditorViewport *viewport = Node3DEditor::get_singleton()->get_editor_viewport(viewport_idx);
  790. Camera3D *const cam = viewport->get_camera_3d();
  791. Array msg;
  792. msg.push_back(cam->get_camera_transform());
  793. if (cam->get_projection() == Camera3D::PROJECTION_ORTHOGONAL) {
  794. msg.push_back(false);
  795. msg.push_back(cam->get_size());
  796. } else {
  797. msg.push_back(true);
  798. msg.push_back(cam->get_fov());
  799. }
  800. msg.push_back(cam->get_near());
  801. msg.push_back(cam->get_far());
  802. _put_msg("scene:override_camera_3D:transform", msg);
  803. }
  804. if (is_breaked() && can_request_idle_draw) {
  805. _put_msg("servers:draw", Array());
  806. can_request_idle_draw = false;
  807. }
  808. }
  809. const uint64_t until = OS::get_singleton()->get_ticks_msec() + 20;
  810. while (peer.is_valid() && peer->has_message()) {
  811. Array arr = peer->get_message();
  812. if (arr.size() != 3 || arr[0].get_type() != Variant::STRING || arr[1].get_type() != Variant::INT || arr[2].get_type() != Variant::ARRAY) {
  813. _stop_and_notify();
  814. ERR_FAIL_MSG("Invalid message format received from peer");
  815. }
  816. _parse_message(arr[0], arr[1], arr[2]);
  817. if (OS::get_singleton()->get_ticks_msec() > until) {
  818. break;
  819. }
  820. }
  821. if (!is_session_active()) {
  822. _stop_and_notify();
  823. break;
  824. };
  825. } break;
  826. }
  827. }
  828. void ScriptEditorDebugger::_clear_execution() {
  829. TreeItem *ti = stack_dump->get_selected();
  830. if (!ti) {
  831. return;
  832. }
  833. Dictionary d = ti->get_metadata(0);
  834. stack_script = ResourceLoader::load(d["file"]);
  835. emit_signal(SNAME("clear_execution"), stack_script);
  836. stack_script.unref();
  837. stack_dump->clear();
  838. inspector->clear_stack_variables();
  839. }
  840. void ScriptEditorDebugger::_set_breakpoint(const String &p_file, const int &p_line, const bool &p_enabled) {
  841. Ref<Script> scr = ResourceLoader::load(p_file);
  842. emit_signal(SNAME("set_breakpoint"), scr, p_line - 1, p_enabled);
  843. scr.unref();
  844. }
  845. void ScriptEditorDebugger::_clear_breakpoints() {
  846. emit_signal(SNAME("clear_breakpoints"));
  847. }
  848. void ScriptEditorDebugger::_breakpoint_tree_clicked() {
  849. TreeItem *selected = breakpoints_tree->get_selected();
  850. if (selected->has_meta("line")) {
  851. emit_signal(SNAME("breakpoint_selected"), selected->get_parent()->get_text(0), int(selected->get_meta("line")));
  852. }
  853. }
  854. String ScriptEditorDebugger::_format_frame_text(const ScriptLanguage::StackInfo *info) {
  855. String text = info->file.get_file() + ":" + itos(info->line) + " @ " + info->func;
  856. if (!text.ends_with(")")) {
  857. text += "()";
  858. }
  859. return text;
  860. }
  861. void ScriptEditorDebugger::start(Ref<RemoteDebuggerPeer> p_peer) {
  862. _clear_errors_list();
  863. stop();
  864. profiler->set_enabled(true, true);
  865. visual_profiler->set_enabled(true);
  866. peer = p_peer;
  867. ERR_FAIL_COND(p_peer.is_null());
  868. performance_profiler->reset();
  869. set_process(true);
  870. camera_override = CameraOverride::OVERRIDE_NONE;
  871. tabs->set_current_tab(0);
  872. _set_reason_text(TTR("Debug session started."), MESSAGE_SUCCESS);
  873. _update_buttons_state();
  874. emit_signal(SNAME("started"));
  875. }
  876. void ScriptEditorDebugger::_update_buttons_state() {
  877. const bool active = is_session_active();
  878. const bool has_editor_tree = active && editor_remote_tree && editor_remote_tree->get_selected();
  879. vmem_refresh->set_disabled(!active);
  880. step->set_disabled(!active || !is_breaked() || !is_debuggable());
  881. next->set_disabled(!active || !is_breaked() || !is_debuggable());
  882. copy->set_disabled(!active || !is_breaked());
  883. docontinue->set_disabled(!active || !is_breaked());
  884. dobreak->set_disabled(!active || is_breaked());
  885. le_clear->set_disabled(!active);
  886. le_set->set_disabled(!has_editor_tree);
  887. thread_list_updating = true;
  888. LocalVector<ThreadDebugged *> threadss;
  889. for (KeyValue<uint64_t, ThreadDebugged> &I : threads_debugged) {
  890. threadss.push_back(&I.value);
  891. }
  892. threadss.sort_custom<ThreadSort>();
  893. threads->clear();
  894. int32_t selected_index = -1;
  895. for (uint32_t i = 0; i < threadss.size(); i++) {
  896. if (debugging_thread_id == threadss[i]->thread_id) {
  897. selected_index = i;
  898. }
  899. threads->add_item(threadss[i]->name);
  900. threads->set_item_metadata(threads->get_item_count() - 1, threadss[i]->thread_id);
  901. }
  902. if (selected_index != -1) {
  903. threads->select(selected_index);
  904. }
  905. thread_list_updating = false;
  906. }
  907. void ScriptEditorDebugger::_stop_and_notify() {
  908. stop();
  909. emit_signal(SNAME("stopped"));
  910. _set_reason_text(TTR("Debug session closed."), MESSAGE_WARNING);
  911. }
  912. void ScriptEditorDebugger::stop() {
  913. set_process(false);
  914. threads_debugged.clear();
  915. debugging_thread_id = Thread::UNASSIGNED_ID;
  916. remote_pid = 0;
  917. _clear_execution();
  918. inspector->clear_cache();
  919. if (peer.is_valid()) {
  920. peer->close();
  921. peer.unref();
  922. reason->set_text("");
  923. reason->set_tooltip_text("");
  924. }
  925. node_path_cache.clear();
  926. res_path_cache.clear();
  927. profiler_signature.clear();
  928. profiler->set_enabled(false, false);
  929. profiler->set_pressed(false);
  930. visual_profiler->set_enabled(false);
  931. visual_profiler->set_pressed(false);
  932. inspector->edit(nullptr);
  933. _update_buttons_state();
  934. }
  935. void ScriptEditorDebugger::_profiler_activate(bool p_enable, int p_type) {
  936. Array msg_data;
  937. msg_data.push_back(p_enable);
  938. switch (p_type) {
  939. case PROFILER_VISUAL:
  940. _put_msg("profiler:visual", msg_data);
  941. break;
  942. case PROFILER_SCRIPTS_SERVERS:
  943. if (p_enable) {
  944. // Clear old script signatures. (should we move all this into the profiler?)
  945. profiler_signature.clear();
  946. // Add max funcs options to request.
  947. Array opts;
  948. int max_funcs = EDITOR_GET("debugger/profiler_frame_max_functions");
  949. opts.push_back(CLAMP(max_funcs, 16, 512));
  950. msg_data.push_back(opts);
  951. }
  952. _put_msg("profiler:servers", msg_data);
  953. break;
  954. default:
  955. ERR_FAIL_MSG("Invalid profiler type");
  956. }
  957. }
  958. void ScriptEditorDebugger::_profiler_seeked() {
  959. if (is_breaked()) {
  960. return;
  961. }
  962. debug_break();
  963. }
  964. void ScriptEditorDebugger::_stack_dump_frame_selected() {
  965. emit_signal(SNAME("stack_frame_selected"));
  966. int frame = get_stack_script_frame();
  967. if (!request_stack_dump(frame)) {
  968. inspector->edit(nullptr);
  969. }
  970. }
  971. void ScriptEditorDebugger::_export_csv() {
  972. file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
  973. file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  974. file_dialog_purpose = SAVE_MONITORS_CSV;
  975. file_dialog->popup_file_dialog();
  976. }
  977. String ScriptEditorDebugger::get_var_value(const String &p_var) const {
  978. if (!is_breaked()) {
  979. return String();
  980. }
  981. return inspector->get_stack_variable(p_var);
  982. }
  983. int ScriptEditorDebugger::_get_node_path_cache(const NodePath &p_path) {
  984. const int *r = node_path_cache.getptr(p_path);
  985. if (r) {
  986. return *r;
  987. }
  988. last_path_id++;
  989. node_path_cache[p_path] = last_path_id;
  990. Array msg;
  991. msg.push_back(p_path);
  992. msg.push_back(last_path_id);
  993. _put_msg("scene:live_node_path", msg);
  994. return last_path_id;
  995. }
  996. int ScriptEditorDebugger::_get_res_path_cache(const String &p_path) {
  997. HashMap<String, int>::Iterator E = res_path_cache.find(p_path);
  998. if (E) {
  999. return E->value;
  1000. }
  1001. last_path_id++;
  1002. res_path_cache[p_path] = last_path_id;
  1003. Array msg;
  1004. msg.push_back(p_path);
  1005. msg.push_back(last_path_id);
  1006. _put_msg("scene:live_res_path", msg);
  1007. return last_path_id;
  1008. }
  1009. void ScriptEditorDebugger::_method_changed(Object *p_base, const StringName &p_name, const Variant **p_args, int p_argcount) {
  1010. if (!p_base || !live_debug || !is_session_active() || !EditorNode::get_singleton()->get_edited_scene()) {
  1011. return;
  1012. }
  1013. Node *node = Object::cast_to<Node>(p_base);
  1014. for (int i = 0; i < p_argcount; i++) {
  1015. //no pointers, sorry
  1016. if (p_args[i]->get_type() == Variant::OBJECT || p_args[i]->get_type() == Variant::RID) {
  1017. return;
  1018. }
  1019. }
  1020. if (node) {
  1021. NodePath path = EditorNode::get_singleton()->get_edited_scene()->get_path_to(node);
  1022. int pathid = _get_node_path_cache(path);
  1023. Array msg;
  1024. msg.push_back(pathid);
  1025. msg.push_back(p_name);
  1026. for (int i = 0; i < p_argcount; i++) {
  1027. //no pointers, sorry
  1028. msg.push_back(*p_args[i]);
  1029. }
  1030. _put_msg("scene:live_node_call", msg);
  1031. return;
  1032. }
  1033. Resource *res = Object::cast_to<Resource>(p_base);
  1034. if (res && !res->get_path().is_empty()) {
  1035. String respath = res->get_path();
  1036. int pathid = _get_res_path_cache(respath);
  1037. Array msg;
  1038. msg.push_back(pathid);
  1039. msg.push_back(p_name);
  1040. for (int i = 0; i < p_argcount; i++) {
  1041. //no pointers, sorry
  1042. msg.push_back(*p_args[i]);
  1043. }
  1044. _put_msg("scene:live_res_call", msg);
  1045. return;
  1046. }
  1047. }
  1048. void ScriptEditorDebugger::_property_changed(Object *p_base, const StringName &p_property, const Variant &p_value) {
  1049. if (!p_base || !live_debug || !EditorNode::get_singleton()->get_edited_scene()) {
  1050. return;
  1051. }
  1052. Node *node = Object::cast_to<Node>(p_base);
  1053. if (node) {
  1054. NodePath path = EditorNode::get_singleton()->get_edited_scene()->get_path_to(node);
  1055. int pathid = _get_node_path_cache(path);
  1056. if (p_value.is_ref_counted()) {
  1057. Ref<Resource> res = p_value;
  1058. if (res.is_valid() && !res->get_path().is_empty()) {
  1059. Array msg;
  1060. msg.push_back(pathid);
  1061. msg.push_back(p_property);
  1062. msg.push_back(res->get_path());
  1063. _put_msg("scene:live_node_prop_res", msg);
  1064. }
  1065. } else {
  1066. Array msg;
  1067. msg.push_back(pathid);
  1068. msg.push_back(p_property);
  1069. msg.push_back(p_value);
  1070. _put_msg("scene:live_node_prop", msg);
  1071. }
  1072. return;
  1073. }
  1074. Resource *res = Object::cast_to<Resource>(p_base);
  1075. if (res && !res->get_path().is_empty()) {
  1076. String respath = res->get_path();
  1077. int pathid = _get_res_path_cache(respath);
  1078. if (p_value.is_ref_counted()) {
  1079. Ref<Resource> res2 = p_value;
  1080. if (res2.is_valid() && !res2->get_path().is_empty()) {
  1081. Array msg;
  1082. msg.push_back(pathid);
  1083. msg.push_back(p_property);
  1084. msg.push_back(res2->get_path());
  1085. _put_msg("scene:live_res_prop_res", msg);
  1086. }
  1087. } else {
  1088. Array msg;
  1089. msg.push_back(pathid);
  1090. msg.push_back(p_property);
  1091. msg.push_back(p_value);
  1092. _put_msg("scene:live_res_prop", msg);
  1093. }
  1094. return;
  1095. }
  1096. }
  1097. bool ScriptEditorDebugger::is_move_to_foreground() const {
  1098. return move_to_foreground;
  1099. }
  1100. void ScriptEditorDebugger::set_move_to_foreground(const bool &p_move_to_foreground) {
  1101. move_to_foreground = p_move_to_foreground;
  1102. }
  1103. String ScriptEditorDebugger::get_stack_script_file() const {
  1104. TreeItem *ti = stack_dump->get_selected();
  1105. if (!ti) {
  1106. return "";
  1107. }
  1108. Dictionary d = ti->get_metadata(0);
  1109. return d["file"];
  1110. }
  1111. int ScriptEditorDebugger::get_stack_script_line() const {
  1112. TreeItem *ti = stack_dump->get_selected();
  1113. if (!ti) {
  1114. return -1;
  1115. }
  1116. Dictionary d = ti->get_metadata(0);
  1117. return d["line"];
  1118. }
  1119. int ScriptEditorDebugger::get_stack_script_frame() const {
  1120. TreeItem *ti = stack_dump->get_selected();
  1121. if (!ti) {
  1122. return -1;
  1123. }
  1124. Dictionary d = ti->get_metadata(0);
  1125. return d["frame"];
  1126. }
  1127. bool ScriptEditorDebugger::request_stack_dump(const int &p_frame) {
  1128. ERR_FAIL_COND_V(!is_session_active() || p_frame < 0, false);
  1129. Array msg;
  1130. msg.push_back(p_frame);
  1131. _put_msg("get_stack_frame_vars", msg, debugging_thread_id);
  1132. return true;
  1133. }
  1134. void ScriptEditorDebugger::set_live_debugging(bool p_enable) {
  1135. live_debug = p_enable;
  1136. }
  1137. void ScriptEditorDebugger::_live_edit_set() {
  1138. if (!is_session_active() || !editor_remote_tree) {
  1139. return;
  1140. }
  1141. TreeItem *ti = editor_remote_tree->get_selected();
  1142. if (!ti) {
  1143. return;
  1144. }
  1145. String path;
  1146. while (ti) {
  1147. String lp = ti->get_text(0);
  1148. path = "/" + lp + path;
  1149. ti = ti->get_parent();
  1150. }
  1151. NodePath np = path;
  1152. EditorNode::get_editor_data().set_edited_scene_live_edit_root(np);
  1153. update_live_edit_root();
  1154. }
  1155. void ScriptEditorDebugger::_live_edit_clear() {
  1156. NodePath np = NodePath("/root");
  1157. EditorNode::get_editor_data().set_edited_scene_live_edit_root(np);
  1158. update_live_edit_root();
  1159. }
  1160. void ScriptEditorDebugger::update_live_edit_root() {
  1161. NodePath np = EditorNode::get_editor_data().get_edited_scene_live_edit_root();
  1162. Array msg;
  1163. msg.push_back(np);
  1164. if (EditorNode::get_singleton()->get_edited_scene()) {
  1165. msg.push_back(EditorNode::get_singleton()->get_edited_scene()->get_scene_file_path());
  1166. } else {
  1167. msg.push_back("");
  1168. }
  1169. _put_msg("scene:live_set_root", msg);
  1170. live_edit_root->set_text(np);
  1171. }
  1172. void ScriptEditorDebugger::live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name) {
  1173. if (live_debug) {
  1174. Array msg;
  1175. msg.push_back(p_parent);
  1176. msg.push_back(p_type);
  1177. msg.push_back(p_name);
  1178. _put_msg("scene:live_create_node", msg);
  1179. }
  1180. }
  1181. void ScriptEditorDebugger::live_debug_instantiate_node(const NodePath &p_parent, const String &p_path, const String &p_name) {
  1182. if (live_debug) {
  1183. Array msg;
  1184. msg.push_back(p_parent);
  1185. msg.push_back(p_path);
  1186. msg.push_back(p_name);
  1187. _put_msg("scene:live_instantiate_node", msg);
  1188. }
  1189. }
  1190. void ScriptEditorDebugger::live_debug_remove_node(const NodePath &p_at) {
  1191. if (live_debug) {
  1192. Array msg;
  1193. msg.push_back(p_at);
  1194. _put_msg("scene:live_remove_node", msg);
  1195. }
  1196. }
  1197. void ScriptEditorDebugger::live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id) {
  1198. if (live_debug) {
  1199. Array msg;
  1200. msg.push_back(p_at);
  1201. msg.push_back(p_keep_id);
  1202. _put_msg("scene:live_remove_and_keep_node", msg);
  1203. }
  1204. }
  1205. void ScriptEditorDebugger::live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos) {
  1206. if (live_debug) {
  1207. Array msg;
  1208. msg.push_back(p_id);
  1209. msg.push_back(p_at);
  1210. msg.push_back(p_at_pos);
  1211. _put_msg("scene:live_restore_node", msg);
  1212. }
  1213. }
  1214. void ScriptEditorDebugger::live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name) {
  1215. if (live_debug) {
  1216. Array msg;
  1217. msg.push_back(p_at);
  1218. msg.push_back(p_new_name);
  1219. _put_msg("scene:live_duplicate_node", msg);
  1220. }
  1221. }
  1222. void ScriptEditorDebugger::live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos) {
  1223. if (live_debug) {
  1224. Array msg;
  1225. msg.push_back(p_at);
  1226. msg.push_back(p_new_place);
  1227. msg.push_back(p_new_name);
  1228. msg.push_back(p_at_pos);
  1229. _put_msg("scene:live_reparent_node", msg);
  1230. }
  1231. }
  1232. CameraOverride ScriptEditorDebugger::get_camera_override() const {
  1233. return camera_override;
  1234. }
  1235. void ScriptEditorDebugger::set_camera_override(CameraOverride p_override) {
  1236. if (p_override == CameraOverride::OVERRIDE_2D && camera_override != CameraOverride::OVERRIDE_2D) {
  1237. Array msg;
  1238. msg.push_back(true);
  1239. _put_msg("scene:override_camera_2D:set", msg);
  1240. } else if (p_override != CameraOverride::OVERRIDE_2D && camera_override == CameraOverride::OVERRIDE_2D) {
  1241. Array msg;
  1242. msg.push_back(false);
  1243. _put_msg("scene:override_camera_2D:set", msg);
  1244. } else if (p_override >= CameraOverride::OVERRIDE_3D_1 && camera_override < CameraOverride::OVERRIDE_3D_1) {
  1245. Array msg;
  1246. msg.push_back(true);
  1247. _put_msg("scene:override_camera_3D:set", msg);
  1248. } else if (p_override < CameraOverride::OVERRIDE_3D_1 && camera_override >= CameraOverride::OVERRIDE_3D_1) {
  1249. Array msg;
  1250. msg.push_back(false);
  1251. _put_msg("scene:override_camera_3D:set", msg);
  1252. }
  1253. camera_override = p_override;
  1254. }
  1255. void ScriptEditorDebugger::set_breakpoint(const String &p_path, int p_line, bool p_enabled) {
  1256. Array msg;
  1257. msg.push_back(p_path);
  1258. msg.push_back(p_line);
  1259. msg.push_back(p_enabled);
  1260. _put_msg("breakpoint", msg, debugging_thread_id != Thread::UNASSIGNED_ID ? debugging_thread_id : Thread::MAIN_ID);
  1261. TreeItem *path_item = breakpoints_tree->search_item_text(p_path);
  1262. if (path_item == nullptr) {
  1263. if (!p_enabled) {
  1264. return;
  1265. }
  1266. path_item = breakpoints_tree->create_item();
  1267. path_item->set_text(0, p_path);
  1268. }
  1269. int idx = 0;
  1270. TreeItem *breakpoint_item;
  1271. for (breakpoint_item = path_item->get_first_child(); breakpoint_item; breakpoint_item = breakpoint_item->get_next()) {
  1272. if ((int)breakpoint_item->get_meta("line") < p_line) {
  1273. idx++;
  1274. continue;
  1275. }
  1276. if ((int)breakpoint_item->get_meta("line") == p_line) {
  1277. break;
  1278. }
  1279. }
  1280. if (breakpoint_item == nullptr) {
  1281. if (!p_enabled) {
  1282. return;
  1283. }
  1284. breakpoint_item = breakpoints_tree->create_item(path_item, idx);
  1285. breakpoint_item->set_meta("line", p_line);
  1286. breakpoint_item->set_text(0, vformat(TTR("Line %d"), p_line));
  1287. return;
  1288. }
  1289. if (!p_enabled) {
  1290. path_item->remove_child(breakpoint_item);
  1291. if (path_item->get_first_child() == nullptr) {
  1292. breakpoints_tree->get_root()->remove_child(path_item);
  1293. }
  1294. }
  1295. }
  1296. void ScriptEditorDebugger::reload_scripts() {
  1297. _put_msg("reload_scripts", Array(), debugging_thread_id != Thread::UNASSIGNED_ID ? debugging_thread_id : Thread::MAIN_ID);
  1298. }
  1299. bool ScriptEditorDebugger::is_skip_breakpoints() {
  1300. return skip_breakpoints_value;
  1301. }
  1302. void ScriptEditorDebugger::_error_activated() {
  1303. TreeItem *selected = error_tree->get_selected();
  1304. if (!selected) {
  1305. return;
  1306. }
  1307. TreeItem *ci = selected->get_first_child();
  1308. if (ci) {
  1309. selected->set_collapsed(!selected->is_collapsed());
  1310. }
  1311. }
  1312. void ScriptEditorDebugger::_error_selected() {
  1313. TreeItem *selected = error_tree->get_selected();
  1314. if (!selected) {
  1315. return;
  1316. }
  1317. Array meta = selected->get_metadata(0);
  1318. if (meta.size() == 0) {
  1319. return;
  1320. }
  1321. emit_signal(SNAME("error_selected"), String(meta[0]), int(meta[1]));
  1322. }
  1323. void ScriptEditorDebugger::_expand_errors_list() {
  1324. TreeItem *root = error_tree->get_root();
  1325. if (!root) {
  1326. return;
  1327. }
  1328. TreeItem *item = root->get_first_child();
  1329. while (item) {
  1330. item->set_collapsed(false);
  1331. item = item->get_next();
  1332. }
  1333. }
  1334. void ScriptEditorDebugger::_collapse_errors_list() {
  1335. TreeItem *root = error_tree->get_root();
  1336. if (!root) {
  1337. return;
  1338. }
  1339. TreeItem *item = root->get_first_child();
  1340. while (item) {
  1341. item->set_collapsed(true);
  1342. item = item->get_next();
  1343. }
  1344. }
  1345. void ScriptEditorDebugger::_clear_errors_list() {
  1346. error_tree->clear();
  1347. error_count = 0;
  1348. warning_count = 0;
  1349. emit_signal(SNAME("errors_cleared"));
  1350. update_tabs();
  1351. expand_all_button->set_disabled(true);
  1352. collapse_all_button->set_disabled(true);
  1353. clear_button->set_disabled(true);
  1354. }
  1355. void ScriptEditorDebugger::_breakpoints_item_rmb_selected(const Vector2 &p_pos, MouseButton p_button) {
  1356. if (p_button != MouseButton::RIGHT) {
  1357. return;
  1358. }
  1359. breakpoints_menu->clear();
  1360. breakpoints_menu->set_size(Size2(1, 1));
  1361. const TreeItem *selected = breakpoints_tree->get_selected();
  1362. String file = selected->get_text(0);
  1363. if (selected->has_meta("line")) {
  1364. breakpoints_menu->add_icon_item(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), TTR("Delete Breakpoint"), ACTION_DELETE_BREAKPOINT);
  1365. file = selected->get_parent()->get_text(0);
  1366. }
  1367. breakpoints_menu->add_icon_item(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), TTR("Delete All Breakpoints in:") + " " + file, ACTION_DELETE_BREAKPOINTS_IN_FILE);
  1368. breakpoints_menu->add_icon_item(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), TTR("Delete All Breakpoints"), ACTION_DELETE_ALL_BREAKPOINTS);
  1369. breakpoints_menu->set_position(breakpoints_tree->get_global_position() + p_pos);
  1370. breakpoints_menu->popup();
  1371. }
  1372. // Right click on specific file(s) or folder(s).
  1373. void ScriptEditorDebugger::_error_tree_item_rmb_selected(const Vector2 &p_pos, MouseButton p_button) {
  1374. if (p_button != MouseButton::RIGHT) {
  1375. return;
  1376. }
  1377. item_menu->clear();
  1378. item_menu->reset_size();
  1379. if (error_tree->is_anything_selected()) {
  1380. item_menu->add_icon_item(get_theme_icon(SNAME("ActionCopy"), SNAME("EditorIcons")), TTR("Copy Error"), ACTION_COPY_ERROR);
  1381. item_menu->add_icon_item(get_theme_icon(SNAME("ExternalLink"), SNAME("EditorIcons")), TTR("Open C++ Source on GitHub"), ACTION_OPEN_SOURCE);
  1382. }
  1383. if (item_menu->get_item_count() > 0) {
  1384. item_menu->set_position(error_tree->get_screen_position() + p_pos);
  1385. item_menu->popup();
  1386. }
  1387. }
  1388. void ScriptEditorDebugger::_item_menu_id_pressed(int p_option) {
  1389. switch (p_option) {
  1390. case ACTION_COPY_ERROR: {
  1391. TreeItem *ti = error_tree->get_selected();
  1392. while (ti->get_parent() != error_tree->get_root()) {
  1393. ti = ti->get_parent();
  1394. }
  1395. String type;
  1396. if (ti->has_meta("_is_warning")) {
  1397. type = "W ";
  1398. } else if (ti->has_meta("_is_error")) {
  1399. type = "E ";
  1400. }
  1401. String text = ti->get_text(0) + " ";
  1402. int rpad_len = text.length();
  1403. text = type + text + ti->get_text(1) + "\n";
  1404. TreeItem *ci = ti->get_first_child();
  1405. while (ci) {
  1406. text += " " + ci->get_text(0).rpad(rpad_len) + ci->get_text(1) + "\n";
  1407. ci = ci->get_next();
  1408. }
  1409. DisplayServer::get_singleton()->clipboard_set(text);
  1410. } break;
  1411. case ACTION_OPEN_SOURCE: {
  1412. TreeItem *ti = error_tree->get_selected();
  1413. while (ti->get_parent() != error_tree->get_root()) {
  1414. ti = ti->get_parent();
  1415. }
  1416. // Find the child with the "C++ Source".
  1417. // It's not at a fixed position as "C++ Error" may come first.
  1418. TreeItem *ci = ti->get_first_child();
  1419. const String cpp_source = "<" + TTR("C++ Source") + ">";
  1420. while (ci) {
  1421. if (ci->get_text(0) == cpp_source) {
  1422. break;
  1423. }
  1424. ci = ci->get_next();
  1425. }
  1426. if (!ci) {
  1427. WARN_PRINT_ED("No C++ source reference is available for this error.");
  1428. return;
  1429. }
  1430. // Parse back the `file:line @ method()` string.
  1431. const Vector<String> file_line_number = ci->get_text(1).split("@")[0].strip_edges().split(":");
  1432. ERR_FAIL_COND_MSG(file_line_number.size() < 2, "Incorrect C++ source stack trace file:line format (please report).");
  1433. const String file = file_line_number[0];
  1434. const int line_number = file_line_number[1].to_int();
  1435. // Construct a GitHub repository URL and open it in the user's default web browser.
  1436. // If the commit hash is available, use it for greater accuracy. Otherwise fall back to tagged release.
  1437. String git_ref = String(VERSION_HASH).is_empty() ? String(VERSION_NUMBER) + "-stable" : String(VERSION_HASH);
  1438. OS::get_singleton()->shell_open(vformat("https://github.com/godotengine/godot/blob/%s/%s#L%d",
  1439. git_ref, file, line_number));
  1440. } break;
  1441. case ACTION_DELETE_BREAKPOINT: {
  1442. const TreeItem *selected = breakpoints_tree->get_selected();
  1443. _set_breakpoint(selected->get_parent()->get_text(0), selected->get_meta("line"), false);
  1444. } break;
  1445. case ACTION_DELETE_BREAKPOINTS_IN_FILE: {
  1446. TreeItem *file_item = breakpoints_tree->get_selected();
  1447. if (file_item->has_meta("line")) {
  1448. file_item = file_item->get_parent();
  1449. }
  1450. // Store first else we will be removing as we loop.
  1451. List<int> lines;
  1452. for (TreeItem *breakpoint_item = file_item->get_first_child(); breakpoint_item; breakpoint_item = breakpoint_item->get_next()) {
  1453. lines.push_back(breakpoint_item->get_meta("line"));
  1454. }
  1455. for (const int &line : lines) {
  1456. _set_breakpoint(file_item->get_text(0), line, false);
  1457. }
  1458. } break;
  1459. case ACTION_DELETE_ALL_BREAKPOINTS: {
  1460. _clear_breakpoints();
  1461. } break;
  1462. }
  1463. }
  1464. void ScriptEditorDebugger::_tab_changed(int p_tab) {
  1465. if (tabs->get_tab_title(p_tab) == TTR("Video RAM")) {
  1466. // "Video RAM" tab was clicked, refresh the data it's displaying when entering the tab.
  1467. _video_mem_request();
  1468. }
  1469. }
  1470. void ScriptEditorDebugger::_bind_methods() {
  1471. ClassDB::bind_method(D_METHOD("live_debug_create_node"), &ScriptEditorDebugger::live_debug_create_node);
  1472. ClassDB::bind_method(D_METHOD("live_debug_instantiate_node"), &ScriptEditorDebugger::live_debug_instantiate_node);
  1473. ClassDB::bind_method(D_METHOD("live_debug_remove_node"), &ScriptEditorDebugger::live_debug_remove_node);
  1474. ClassDB::bind_method(D_METHOD("live_debug_remove_and_keep_node"), &ScriptEditorDebugger::live_debug_remove_and_keep_node);
  1475. ClassDB::bind_method(D_METHOD("live_debug_restore_node"), &ScriptEditorDebugger::live_debug_restore_node);
  1476. ClassDB::bind_method(D_METHOD("live_debug_duplicate_node"), &ScriptEditorDebugger::live_debug_duplicate_node);
  1477. ClassDB::bind_method(D_METHOD("live_debug_reparent_node"), &ScriptEditorDebugger::live_debug_reparent_node);
  1478. ClassDB::bind_method(D_METHOD("request_remote_object", "id"), &ScriptEditorDebugger::request_remote_object);
  1479. ClassDB::bind_method(D_METHOD("update_remote_object", "id", "property", "value"), &ScriptEditorDebugger::update_remote_object);
  1480. ADD_SIGNAL(MethodInfo("started"));
  1481. ADD_SIGNAL(MethodInfo("stopped"));
  1482. ADD_SIGNAL(MethodInfo("stop_requested"));
  1483. ADD_SIGNAL(MethodInfo("stack_frame_selected", PropertyInfo(Variant::INT, "frame")));
  1484. ADD_SIGNAL(MethodInfo("error_selected", PropertyInfo(Variant::INT, "error")));
  1485. ADD_SIGNAL(MethodInfo("breakpoint_selected", PropertyInfo("script"), PropertyInfo(Variant::INT, "line")));
  1486. ADD_SIGNAL(MethodInfo("set_execution", PropertyInfo("script"), PropertyInfo(Variant::INT, "line")));
  1487. ADD_SIGNAL(MethodInfo("clear_execution", PropertyInfo("script")));
  1488. ADD_SIGNAL(MethodInfo("breaked", PropertyInfo(Variant::BOOL, "reallydid"), PropertyInfo(Variant::BOOL, "can_debug"), PropertyInfo(Variant::STRING, "reason"), PropertyInfo(Variant::BOOL, "has_stackdump")));
  1489. ADD_SIGNAL(MethodInfo("remote_object_requested", PropertyInfo(Variant::INT, "id")));
  1490. ADD_SIGNAL(MethodInfo("remote_object_updated", PropertyInfo(Variant::INT, "id")));
  1491. ADD_SIGNAL(MethodInfo("remote_object_property_updated", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::STRING, "property")));
  1492. ADD_SIGNAL(MethodInfo("remote_tree_updated"));
  1493. ADD_SIGNAL(MethodInfo("output"));
  1494. ADD_SIGNAL(MethodInfo("stack_dump", PropertyInfo(Variant::ARRAY, "stack_dump")));
  1495. ADD_SIGNAL(MethodInfo("stack_frame_vars", PropertyInfo(Variant::INT, "num_vars")));
  1496. ADD_SIGNAL(MethodInfo("stack_frame_var", PropertyInfo(Variant::ARRAY, "data")));
  1497. ADD_SIGNAL(MethodInfo("debug_data", PropertyInfo(Variant::STRING, "msg"), PropertyInfo(Variant::ARRAY, "data")));
  1498. ADD_SIGNAL(MethodInfo("set_breakpoint", PropertyInfo("script"), PropertyInfo(Variant::INT, "line"), PropertyInfo(Variant::BOOL, "enabled")));
  1499. ADD_SIGNAL(MethodInfo("clear_breakpoints"));
  1500. ADD_SIGNAL(MethodInfo("errors_cleared"));
  1501. }
  1502. void ScriptEditorDebugger::add_debugger_tab(Control *p_control) {
  1503. tabs->add_child(p_control);
  1504. }
  1505. void ScriptEditorDebugger::remove_debugger_tab(Control *p_control) {
  1506. int idx = tabs->get_tab_idx_from_control(p_control);
  1507. ERR_FAIL_COND(idx < 0);
  1508. p_control->queue_free();
  1509. }
  1510. int ScriptEditorDebugger::get_current_debugger_tab() const {
  1511. return tabs->get_current_tab();
  1512. }
  1513. void ScriptEditorDebugger::switch_to_debugger(int p_debugger_tab_idx) {
  1514. tabs->set_current_tab(p_debugger_tab_idx);
  1515. }
  1516. void ScriptEditorDebugger::send_message(const String &p_message, const Array &p_args) {
  1517. _put_msg(p_message, p_args);
  1518. }
  1519. void ScriptEditorDebugger::toggle_profiler(const String &p_profiler, bool p_enable, const Array &p_data) {
  1520. Array msg_data;
  1521. msg_data.push_back(p_enable);
  1522. msg_data.append_array(p_data);
  1523. _put_msg("profiler:" + p_profiler, msg_data);
  1524. }
  1525. ScriptEditorDebugger::ScriptEditorDebugger() {
  1526. tabs = memnew(TabContainer);
  1527. add_child(tabs);
  1528. tabs->connect("tab_changed", callable_mp(this, &ScriptEditorDebugger::_tab_changed));
  1529. InspectorDock::get_inspector_singleton()->connect("object_id_selected", callable_mp(this, &ScriptEditorDebugger::_remote_object_selected));
  1530. { //debugger
  1531. VBoxContainer *vbc = memnew(VBoxContainer);
  1532. vbc->set_name(TTR("Stack Trace"));
  1533. Control *dbg = vbc;
  1534. HBoxContainer *hbc = memnew(HBoxContainer);
  1535. vbc->add_child(hbc);
  1536. reason = memnew(Label);
  1537. reason->set_text("");
  1538. hbc->add_child(reason);
  1539. reason->set_h_size_flags(SIZE_EXPAND_FILL);
  1540. reason->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
  1541. reason->set_max_lines_visible(3);
  1542. reason->set_mouse_filter(Control::MOUSE_FILTER_PASS);
  1543. hbc->add_child(memnew(VSeparator));
  1544. skip_breakpoints = memnew(Button);
  1545. skip_breakpoints->set_flat(true);
  1546. hbc->add_child(skip_breakpoints);
  1547. skip_breakpoints->set_tooltip_text(TTR("Skip Breakpoints"));
  1548. skip_breakpoints->connect("pressed", callable_mp(this, &ScriptEditorDebugger::debug_skip_breakpoints));
  1549. hbc->add_child(memnew(VSeparator));
  1550. copy = memnew(Button);
  1551. copy->set_flat(true);
  1552. hbc->add_child(copy);
  1553. copy->set_tooltip_text(TTR("Copy Error"));
  1554. copy->connect("pressed", callable_mp(this, &ScriptEditorDebugger::debug_copy));
  1555. hbc->add_child(memnew(VSeparator));
  1556. step = memnew(Button);
  1557. step->set_flat(true);
  1558. hbc->add_child(step);
  1559. step->set_tooltip_text(TTR("Step Into"));
  1560. step->set_shortcut(ED_GET_SHORTCUT("debugger/step_into"));
  1561. step->connect("pressed", callable_mp(this, &ScriptEditorDebugger::debug_step));
  1562. next = memnew(Button);
  1563. next->set_flat(true);
  1564. hbc->add_child(next);
  1565. next->set_tooltip_text(TTR("Step Over"));
  1566. next->set_shortcut(ED_GET_SHORTCUT("debugger/step_over"));
  1567. next->connect("pressed", callable_mp(this, &ScriptEditorDebugger::debug_next));
  1568. hbc->add_child(memnew(VSeparator));
  1569. dobreak = memnew(Button);
  1570. dobreak->set_flat(true);
  1571. hbc->add_child(dobreak);
  1572. dobreak->set_tooltip_text(TTR("Break"));
  1573. dobreak->set_shortcut(ED_GET_SHORTCUT("debugger/break"));
  1574. dobreak->connect("pressed", callable_mp(this, &ScriptEditorDebugger::debug_break));
  1575. docontinue = memnew(Button);
  1576. docontinue->set_flat(true);
  1577. hbc->add_child(docontinue);
  1578. docontinue->set_tooltip_text(TTR("Continue"));
  1579. docontinue->set_shortcut(ED_GET_SHORTCUT("debugger/continue"));
  1580. docontinue->connect("pressed", callable_mp(this, &ScriptEditorDebugger::debug_continue));
  1581. HSplitContainer *parent_sc = memnew(HSplitContainer);
  1582. vbc->add_child(parent_sc);
  1583. parent_sc->set_v_size_flags(SIZE_EXPAND_FILL);
  1584. parent_sc->set_split_offset(500 * EDSCALE);
  1585. HSplitContainer *sc = memnew(HSplitContainer);
  1586. sc->set_v_size_flags(SIZE_EXPAND_FILL);
  1587. sc->set_h_size_flags(SIZE_EXPAND_FILL);
  1588. parent_sc->add_child(sc);
  1589. VBoxContainer *stack_vb = memnew(VBoxContainer);
  1590. stack_vb->set_h_size_flags(SIZE_EXPAND_FILL);
  1591. sc->add_child(stack_vb);
  1592. HBoxContainer *thread_hb = memnew(HBoxContainer);
  1593. stack_vb->add_child(thread_hb);
  1594. thread_hb->add_child(memnew(Label(TTR("Thread:"))));
  1595. threads = memnew(OptionButton);
  1596. thread_hb->add_child(threads);
  1597. threads->set_h_size_flags(SIZE_EXPAND_FILL);
  1598. threads->connect("item_selected", callable_mp(this, &ScriptEditorDebugger::_select_thread));
  1599. stack_dump = memnew(Tree);
  1600. stack_dump->set_allow_reselect(true);
  1601. stack_dump->set_columns(1);
  1602. stack_dump->set_column_titles_visible(true);
  1603. stack_dump->set_column_title(0, TTR("Stack Frames"));
  1604. stack_dump->set_hide_root(true);
  1605. stack_dump->set_v_size_flags(SIZE_EXPAND_FILL);
  1606. stack_dump->connect("cell_selected", callable_mp(this, &ScriptEditorDebugger::_stack_dump_frame_selected));
  1607. stack_vb->add_child(stack_dump);
  1608. VBoxContainer *inspector_vbox = memnew(VBoxContainer);
  1609. inspector_vbox->set_h_size_flags(SIZE_EXPAND_FILL);
  1610. sc->add_child(inspector_vbox);
  1611. HBoxContainer *tools_hb = memnew(HBoxContainer);
  1612. inspector_vbox->add_child(tools_hb);
  1613. search = memnew(LineEdit);
  1614. search->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1615. search->set_placeholder(TTR("Filter Stack Variables"));
  1616. search->set_clear_button_enabled(true);
  1617. tools_hb->add_child(search);
  1618. inspector = memnew(EditorDebuggerInspector);
  1619. inspector->set_h_size_flags(SIZE_EXPAND_FILL);
  1620. inspector->set_v_size_flags(SIZE_EXPAND_FILL);
  1621. inspector->set_property_name_style(EditorPropertyNameProcessor::STYLE_RAW);
  1622. inspector->set_read_only(true);
  1623. inspector->connect("object_selected", callable_mp(this, &ScriptEditorDebugger::_remote_object_selected));
  1624. inspector->connect("object_edited", callable_mp(this, &ScriptEditorDebugger::_remote_object_edited));
  1625. inspector->connect("object_property_updated", callable_mp(this, &ScriptEditorDebugger::_remote_object_property_updated));
  1626. inspector->register_text_enter(search);
  1627. inspector->set_use_filter(true);
  1628. inspector_vbox->add_child(inspector);
  1629. breakpoints_tree = memnew(Tree);
  1630. breakpoints_tree->set_h_size_flags(SIZE_EXPAND_FILL);
  1631. breakpoints_tree->set_column_titles_visible(true);
  1632. breakpoints_tree->set_column_title(0, TTR("Breakpoints"));
  1633. breakpoints_tree->set_allow_reselect(true);
  1634. breakpoints_tree->set_allow_rmb_select(true);
  1635. breakpoints_tree->set_hide_root(true);
  1636. breakpoints_tree->connect("item_mouse_selected", callable_mp(this, &ScriptEditorDebugger::_breakpoints_item_rmb_selected));
  1637. breakpoints_tree->create_item();
  1638. parent_sc->add_child(breakpoints_tree);
  1639. tabs->add_child(dbg);
  1640. breakpoints_menu = memnew(PopupMenu);
  1641. breakpoints_menu->connect("id_pressed", callable_mp(this, &ScriptEditorDebugger::_item_menu_id_pressed));
  1642. breakpoints_tree->add_child(breakpoints_menu);
  1643. }
  1644. { //errors
  1645. errors_tab = memnew(VBoxContainer);
  1646. errors_tab->set_name(TTR("Errors"));
  1647. HBoxContainer *error_hbox = memnew(HBoxContainer);
  1648. errors_tab->add_child(error_hbox);
  1649. expand_all_button = memnew(Button);
  1650. expand_all_button->set_text(TTR("Expand All"));
  1651. expand_all_button->set_disabled(true);
  1652. expand_all_button->connect("pressed", callable_mp(this, &ScriptEditorDebugger::_expand_errors_list));
  1653. error_hbox->add_child(expand_all_button);
  1654. collapse_all_button = memnew(Button);
  1655. collapse_all_button->set_text(TTR("Collapse All"));
  1656. collapse_all_button->set_disabled(true);
  1657. collapse_all_button->connect("pressed", callable_mp(this, &ScriptEditorDebugger::_collapse_errors_list));
  1658. error_hbox->add_child(collapse_all_button);
  1659. Control *space = memnew(Control);
  1660. space->set_h_size_flags(SIZE_EXPAND_FILL);
  1661. error_hbox->add_child(space);
  1662. clear_button = memnew(Button);
  1663. clear_button->set_text(TTR("Clear"));
  1664. clear_button->set_h_size_flags(0);
  1665. clear_button->set_disabled(true);
  1666. clear_button->connect("pressed", callable_mp(this, &ScriptEditorDebugger::_clear_errors_list));
  1667. error_hbox->add_child(clear_button);
  1668. error_tree = memnew(Tree);
  1669. error_tree->set_columns(2);
  1670. error_tree->set_column_expand(0, false);
  1671. error_tree->set_column_custom_minimum_width(0, 140);
  1672. error_tree->set_column_clip_content(0, true);
  1673. error_tree->set_column_expand(1, true);
  1674. error_tree->set_column_clip_content(1, true);
  1675. error_tree->set_select_mode(Tree::SELECT_ROW);
  1676. error_tree->set_hide_root(true);
  1677. error_tree->set_v_size_flags(SIZE_EXPAND_FILL);
  1678. error_tree->set_allow_rmb_select(true);
  1679. error_tree->set_allow_reselect(true);
  1680. error_tree->connect("item_mouse_selected", callable_mp(this, &ScriptEditorDebugger::_error_tree_item_rmb_selected));
  1681. errors_tab->add_child(error_tree);
  1682. item_menu = memnew(PopupMenu);
  1683. item_menu->connect("id_pressed", callable_mp(this, &ScriptEditorDebugger::_item_menu_id_pressed));
  1684. error_tree->add_child(item_menu);
  1685. tabs->add_child(errors_tab);
  1686. }
  1687. { // File dialog
  1688. file_dialog = memnew(EditorFileDialog);
  1689. file_dialog->connect("file_selected", callable_mp(this, &ScriptEditorDebugger::_file_selected));
  1690. add_child(file_dialog);
  1691. }
  1692. { //profiler
  1693. profiler = memnew(EditorProfiler);
  1694. profiler->set_name(TTR("Profiler"));
  1695. tabs->add_child(profiler);
  1696. profiler->connect("enable_profiling", callable_mp(this, &ScriptEditorDebugger::_profiler_activate).bind(PROFILER_SCRIPTS_SERVERS));
  1697. profiler->connect("break_request", callable_mp(this, &ScriptEditorDebugger::_profiler_seeked));
  1698. }
  1699. { //frame profiler
  1700. visual_profiler = memnew(EditorVisualProfiler);
  1701. visual_profiler->set_name(TTR("Visual Profiler"));
  1702. tabs->add_child(visual_profiler);
  1703. visual_profiler->connect("enable_profiling", callable_mp(this, &ScriptEditorDebugger::_profiler_activate).bind(PROFILER_VISUAL));
  1704. }
  1705. { //monitors
  1706. performance_profiler = memnew(EditorPerformanceProfiler);
  1707. tabs->add_child(performance_profiler);
  1708. }
  1709. { //vmem inspect
  1710. VBoxContainer *vmem_vb = memnew(VBoxContainer);
  1711. HBoxContainer *vmem_hb = memnew(HBoxContainer);
  1712. Label *vmlb = memnew(Label(TTR("List of Video Memory Usage by Resource:") + " "));
  1713. vmlb->set_theme_type_variation("HeaderSmall");
  1714. vmlb->set_h_size_flags(SIZE_EXPAND_FILL);
  1715. vmem_hb->add_child(vmlb);
  1716. vmem_hb->add_child(memnew(Label(TTR("Total:") + " ")));
  1717. vmem_total = memnew(LineEdit);
  1718. vmem_total->set_editable(false);
  1719. vmem_total->set_custom_minimum_size(Size2(100, 0) * EDSCALE);
  1720. vmem_hb->add_child(vmem_total);
  1721. vmem_refresh = memnew(Button);
  1722. vmem_refresh->set_flat(true);
  1723. vmem_hb->add_child(vmem_refresh);
  1724. vmem_export = memnew(Button);
  1725. vmem_export->set_flat(true);
  1726. vmem_export->set_tooltip_text(TTR("Export list to a CSV file"));
  1727. vmem_hb->add_child(vmem_export);
  1728. vmem_vb->add_child(vmem_hb);
  1729. vmem_refresh->connect("pressed", callable_mp(this, &ScriptEditorDebugger::_video_mem_request));
  1730. vmem_export->connect("pressed", callable_mp(this, &ScriptEditorDebugger::_video_mem_export));
  1731. VBoxContainer *vmmc = memnew(VBoxContainer);
  1732. vmem_tree = memnew(Tree);
  1733. vmem_tree->set_v_size_flags(SIZE_EXPAND_FILL);
  1734. vmem_tree->set_h_size_flags(SIZE_EXPAND_FILL);
  1735. vmmc->add_child(vmem_tree);
  1736. vmmc->set_v_size_flags(SIZE_EXPAND_FILL);
  1737. vmem_vb->add_child(vmmc);
  1738. vmem_vb->set_name(TTR("Video RAM"));
  1739. vmem_tree->set_columns(4);
  1740. vmem_tree->set_column_titles_visible(true);
  1741. vmem_tree->set_column_title(0, TTR("Resource Path"));
  1742. vmem_tree->set_column_expand(0, true);
  1743. vmem_tree->set_column_expand(1, false);
  1744. vmem_tree->set_column_title(1, TTR("Type"));
  1745. vmem_tree->set_column_custom_minimum_width(1, 100 * EDSCALE);
  1746. vmem_tree->set_column_expand(2, false);
  1747. vmem_tree->set_column_title(2, TTR("Format"));
  1748. vmem_tree->set_column_custom_minimum_width(2, 150 * EDSCALE);
  1749. vmem_tree->set_column_expand(3, false);
  1750. vmem_tree->set_column_title(3, TTR("Usage"));
  1751. vmem_tree->set_column_custom_minimum_width(3, 80 * EDSCALE);
  1752. vmem_tree->set_hide_root(true);
  1753. tabs->add_child(vmem_vb);
  1754. }
  1755. { // misc
  1756. VBoxContainer *misc = memnew(VBoxContainer);
  1757. misc->set_name(TTR("Misc"));
  1758. tabs->add_child(misc);
  1759. GridContainer *info_left = memnew(GridContainer);
  1760. info_left->set_columns(2);
  1761. misc->add_child(info_left);
  1762. clicked_ctrl = memnew(LineEdit);
  1763. clicked_ctrl->set_editable(false);
  1764. clicked_ctrl->set_h_size_flags(SIZE_EXPAND_FILL);
  1765. info_left->add_child(memnew(Label(TTR("Clicked Control:"))));
  1766. info_left->add_child(clicked_ctrl);
  1767. clicked_ctrl_type = memnew(LineEdit);
  1768. clicked_ctrl_type->set_editable(false);
  1769. info_left->add_child(memnew(Label(TTR("Clicked Control Type:"))));
  1770. info_left->add_child(clicked_ctrl_type);
  1771. scene_tree = memnew(SceneDebuggerTree);
  1772. live_edit_root = memnew(LineEdit);
  1773. live_edit_root->set_editable(false);
  1774. live_edit_root->set_h_size_flags(SIZE_EXPAND_FILL);
  1775. {
  1776. HBoxContainer *lehb = memnew(HBoxContainer);
  1777. Label *l = memnew(Label(TTR("Live Edit Root:")));
  1778. info_left->add_child(l);
  1779. lehb->add_child(live_edit_root);
  1780. le_set = memnew(Button(TTR("Set From Tree")));
  1781. lehb->add_child(le_set);
  1782. le_clear = memnew(Button(TTR("Clear")));
  1783. lehb->add_child(le_clear);
  1784. info_left->add_child(lehb);
  1785. }
  1786. misc->add_child(memnew(VSeparator));
  1787. HBoxContainer *buttons = memnew(HBoxContainer);
  1788. export_csv = memnew(Button(TTR("Export measures as CSV")));
  1789. export_csv->connect("pressed", callable_mp(this, &ScriptEditorDebugger::_export_csv));
  1790. buttons->add_child(export_csv);
  1791. misc->add_child(buttons);
  1792. }
  1793. msgdialog = memnew(AcceptDialog);
  1794. add_child(msgdialog);
  1795. live_debug = true;
  1796. camera_override = CameraOverride::OVERRIDE_NONE;
  1797. last_path_id = false;
  1798. error_count = 0;
  1799. warning_count = 0;
  1800. _update_buttons_state();
  1801. }
  1802. ScriptEditorDebugger::~ScriptEditorDebugger() {
  1803. if (peer.is_valid()) {
  1804. peer->close();
  1805. peer.unref();
  1806. }
  1807. memdelete(scene_tree);
  1808. }