script_editor_debugger.cpp 71 KB

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