script_editor_debugger.cpp 70 KB

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