script_editor_debugger.cpp 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795
  1. /*************************************************************************/
  2. /* script_editor_debugger.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "script_editor_debugger.h"
  31. #include "core/debugger/debugger_marshalls.h"
  32. #include "core/io/marshalls.h"
  33. #include "core/project_settings.h"
  34. #include "core/ustring.h"
  35. #include "editor/debugger/editor_network_profiler.h"
  36. #include "editor/debugger/editor_profiler.h"
  37. #include "editor/debugger/editor_visual_profiler.h"
  38. #include "editor/editor_log.h"
  39. #include "editor/editor_node.h"
  40. #include "editor/editor_scale.h"
  41. #include "editor/editor_settings.h"
  42. #include "editor/plugins/canvas_item_editor_plugin.h"
  43. #include "editor/plugins/spatial_editor_plugin.h"
  44. #include "editor/property_editor.h"
  45. #include "main/performance.h"
  46. #include "scene/3d/camera.h"
  47. #include "scene/debugger/scene_debugger.h"
  48. #include "scene/gui/dialogs.h"
  49. #include "scene/gui/label.h"
  50. #include "scene/gui/line_edit.h"
  51. #include "scene/gui/margin_container.h"
  52. #include "scene/gui/rich_text_label.h"
  53. #include "scene/gui/separator.h"
  54. #include "scene/gui/split_container.h"
  55. #include "scene/gui/tab_container.h"
  56. #include "scene/gui/texture_button.h"
  57. #include "scene/gui/tree.h"
  58. #include "scene/resources/packed_scene.h"
  59. #include "servers/display_server.h"
  60. using CameraOverride = EditorDebuggerNode::CameraOverride;
  61. void ScriptEditorDebugger::_put_msg(String p_message, Array p_data) {
  62. if (is_session_active()) {
  63. Array msg;
  64. msg.push_back(p_message);
  65. msg.push_back(p_data);
  66. peer->put_message(msg);
  67. }
  68. }
  69. void ScriptEditorDebugger::debug_copy() {
  70. String msg = reason->get_text();
  71. if (msg == "") return;
  72. DisplayServer::get_singleton()->clipboard_set(msg);
  73. }
  74. void ScriptEditorDebugger::debug_skip_breakpoints() {
  75. skip_breakpoints_value = !skip_breakpoints_value;
  76. if (skip_breakpoints_value)
  77. skip_breakpoints->set_icon(get_icon("DebugSkipBreakpointsOn", "EditorIcons"));
  78. else
  79. skip_breakpoints->set_icon(get_icon("DebugSkipBreakpointsOff", "EditorIcons"));
  80. Array msg;
  81. msg.push_back(skip_breakpoints_value);
  82. _put_msg("set_skip_breakpoints", msg);
  83. }
  84. void ScriptEditorDebugger::debug_next() {
  85. ERR_FAIL_COND(!breaked);
  86. _put_msg("next", Array());
  87. _clear_execution();
  88. }
  89. void ScriptEditorDebugger::debug_step() {
  90. ERR_FAIL_COND(!breaked);
  91. _put_msg("step", Array());
  92. _clear_execution();
  93. }
  94. void ScriptEditorDebugger::debug_break() {
  95. ERR_FAIL_COND(breaked);
  96. _put_msg("break", Array());
  97. }
  98. void ScriptEditorDebugger::debug_continue() {
  99. ERR_FAIL_COND(!breaked);
  100. // Allow focus stealing only if we actually run this client for security.
  101. if (remote_pid && EditorNode::get_singleton()->has_child_process(remote_pid))
  102. DisplayServer::get_singleton()->enable_for_stealing_focus(remote_pid);
  103. _clear_execution();
  104. _put_msg("continue", Array());
  105. }
  106. void ScriptEditorDebugger::update_tabs() {
  107. if (error_count == 0 && warning_count == 0) {
  108. errors_tab->set_name(TTR("Errors"));
  109. tabs->set_tab_icon(errors_tab->get_index(), Ref<Texture2D>());
  110. } else {
  111. errors_tab->set_name(TTR("Errors") + " (" + itos(error_count + warning_count) + ")");
  112. if (error_count == 0) {
  113. tabs->set_tab_icon(errors_tab->get_index(), get_icon("Warning", "EditorIcons"));
  114. } else {
  115. tabs->set_tab_icon(errors_tab->get_index(), get_icon("Error", "EditorIcons"));
  116. }
  117. }
  118. }
  119. void ScriptEditorDebugger::clear_style() {
  120. tabs->add_style_override("panel", NULL);
  121. }
  122. void ScriptEditorDebugger::save_node(ObjectID p_id, const String &p_file) {
  123. Array msg;
  124. msg.push_back(p_id);
  125. msg.push_back(p_file);
  126. _put_msg("scene:save_node", msg);
  127. }
  128. void ScriptEditorDebugger::_file_selected(const String &p_file) {
  129. Error err;
  130. FileAccessRef file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  131. if (err != OK) {
  132. ERR_PRINT("Failed to open " + p_file);
  133. return;
  134. }
  135. Vector<String> line;
  136. line.resize(Performance::MONITOR_MAX);
  137. // signatures
  138. for (int i = 0; i < Performance::MONITOR_MAX; i++) {
  139. line.write[i] = Performance::get_singleton()->get_monitor_name(Performance::Monitor(i));
  140. }
  141. file->store_csv_line(line);
  142. // values
  143. List<Vector<float>>::Element *E = perf_history.back();
  144. while (E) {
  145. Vector<float> &perf_data = E->get();
  146. for (int i = 0; i < perf_data.size(); i++) {
  147. line.write[i] = String::num_real(perf_data[i]);
  148. }
  149. file->store_csv_line(line);
  150. E = E->prev();
  151. }
  152. file->store_string("\n");
  153. Vector<Vector<String>> profiler_data = profiler->get_data_as_csv();
  154. for (int i = 0; i < profiler_data.size(); i++) {
  155. file->store_csv_line(profiler_data[i]);
  156. }
  157. }
  158. void ScriptEditorDebugger::request_remote_tree() {
  159. _put_msg("scene:request_scene_tree", Array());
  160. }
  161. const SceneDebuggerTree *ScriptEditorDebugger::get_remote_tree() {
  162. return scene_tree;
  163. }
  164. void ScriptEditorDebugger::update_remote_object(ObjectID p_obj_id, const String &p_prop, const Variant &p_value) {
  165. Array msg;
  166. msg.push_back(p_obj_id);
  167. msg.push_back(p_prop);
  168. msg.push_back(p_value);
  169. _put_msg("scene:set_object_property", msg);
  170. }
  171. void ScriptEditorDebugger::request_remote_object(ObjectID p_obj_id) {
  172. ERR_FAIL_COND(p_obj_id.is_null());
  173. Array msg;
  174. msg.push_back(p_obj_id);
  175. _put_msg("scene:inspect_object", msg);
  176. }
  177. Object *ScriptEditorDebugger::get_remote_object(ObjectID p_id) {
  178. return inspector->get_object(p_id);
  179. }
  180. void ScriptEditorDebugger::_remote_object_selected(ObjectID p_id) {
  181. emit_signal("remote_object_requested", p_id);
  182. }
  183. void ScriptEditorDebugger::_remote_object_edited(ObjectID p_id, const String &p_prop, const Variant &p_value) {
  184. update_remote_object(p_id, p_prop, p_value);
  185. request_remote_object(p_id);
  186. }
  187. void ScriptEditorDebugger::_remote_object_property_updated(ObjectID p_id, const String &p_property) {
  188. emit_signal("remote_object_property_updated", p_id, p_property);
  189. }
  190. void ScriptEditorDebugger::_video_mem_request() {
  191. _put_msg("core:memory", Array());
  192. }
  193. Size2 ScriptEditorDebugger::get_minimum_size() const {
  194. Size2 ms = MarginContainer::get_minimum_size();
  195. ms.y = MAX(ms.y, 250 * EDSCALE);
  196. return ms;
  197. }
  198. void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_data) {
  199. if (p_msg == "debug_enter") {
  200. _put_msg("get_stack_dump", Array());
  201. ERR_FAIL_COND(p_data.size() != 2);
  202. bool can_continue = p_data[0];
  203. String error = p_data[1];
  204. breaked = true;
  205. can_debug = can_continue;
  206. _update_buttons_state();
  207. _set_reason_text(error, MESSAGE_ERROR);
  208. emit_signal("breaked", true, can_continue);
  209. DisplayServer::get_singleton()->window_move_to_foreground();
  210. if (error != "") {
  211. tabs->set_current_tab(0);
  212. }
  213. profiler->set_enabled(false);
  214. inspector->clear_cache(); // Take a chance to force remote objects update.
  215. } else if (p_msg == "debug_exit") {
  216. breaked = false;
  217. can_debug = false;
  218. _clear_execution();
  219. _update_buttons_state();
  220. _set_reason_text(TTR("Execution resumed."), MESSAGE_SUCCESS);
  221. emit_signal("breaked", false, false);
  222. profiler->set_enabled(true);
  223. profiler->disable_seeking();
  224. } else if (p_msg == "set_pid") {
  225. ERR_FAIL_COND(p_data.size() < 1);
  226. remote_pid = p_data[0];
  227. } else if (p_msg == "scene:click_ctrl") {
  228. ERR_FAIL_COND(p_data.size() < 2);
  229. clicked_ctrl->set_text(p_data[0]);
  230. clicked_ctrl_type->set_text(p_data[1]);
  231. } else if (p_msg == "scene:scene_tree") {
  232. scene_tree->nodes.clear();
  233. scene_tree->deserialize(p_data);
  234. emit_signal("remote_tree_updated");
  235. _update_buttons_state();
  236. } else if (p_msg == "scene:inspect_object") {
  237. ObjectID id = inspector->add_object(p_data);
  238. if (id.is_valid())
  239. emit_signal("remote_object_updated", id);
  240. } else if (p_msg == "memory:usage") {
  241. vmem_tree->clear();
  242. TreeItem *root = vmem_tree->create_item();
  243. DebuggerMarshalls::ResourceUsage usage;
  244. usage.deserialize(p_data);
  245. int total = 0;
  246. for (List<DebuggerMarshalls::ResourceInfo>::Element *E = usage.infos.front(); E; E = E->next()) {
  247. TreeItem *it = vmem_tree->create_item(root);
  248. String type = E->get().type;
  249. int bytes = E->get().vram;
  250. it->set_text(0, E->get().path);
  251. it->set_text(1, type);
  252. it->set_text(2, E->get().format);
  253. it->set_text(3, String::humanize_size(bytes));
  254. total += bytes;
  255. if (has_icon(type, "EditorIcons"))
  256. it->set_icon(0, get_icon(type, "EditorIcons"));
  257. }
  258. vmem_total->set_tooltip(TTR("Bytes:") + " " + itos(total));
  259. vmem_total->set_text(String::humanize_size(total));
  260. } else if (p_msg == "stack_dump") {
  261. DebuggerMarshalls::ScriptStackDump stack;
  262. stack.deserialize(p_data);
  263. stack_dump->clear();
  264. inspector->clear_stack_variables();
  265. TreeItem *r = stack_dump->create_item();
  266. for (int i = 0; i < stack.frames.size(); i++) {
  267. TreeItem *s = stack_dump->create_item(r);
  268. Dictionary d;
  269. d["frame"] = i;
  270. d["file"] = stack.frames[i].file;
  271. d["function"] = stack.frames[i].func;
  272. d["line"] = stack.frames[i].line;
  273. s->set_metadata(0, d);
  274. String line = itos(i) + " - " + String(d["file"]) + ":" + itos(d["line"]) + " - at function: " + d["function"];
  275. s->set_text(0, line);
  276. if (i == 0)
  277. s->select(0);
  278. }
  279. } else if (p_msg == "stack_frame_vars") {
  280. inspector->clear_stack_variables();
  281. } else if (p_msg == "stack_frame_var") {
  282. inspector->add_stack_variable(p_data);
  283. } else if (p_msg == "output") {
  284. ERR_FAIL_COND(p_data.size() < 1);
  285. ERR_FAIL_COND(p_data[0].get_type() != Variant::PACKED_STRING_ARRAY);
  286. Vector<String> strings = p_data[0];
  287. EditorNode::get_log()->add_message(String("\n").join(strings));
  288. } else if (p_msg == "performance:profile_frame") {
  289. Vector<float> p;
  290. p.resize(p_data.size());
  291. for (int i = 0; i < p_data.size(); i++) {
  292. p.write[i] = p_data[i];
  293. if (i < perf_items.size()) {
  294. const float value = p[i];
  295. String label = rtos(value);
  296. String tooltip = label;
  297. switch (Performance::MonitorType((int)perf_items[i]->get_metadata(1))) {
  298. case Performance::MONITOR_TYPE_MEMORY: {
  299. label = String::humanize_size(value);
  300. tooltip = label;
  301. } break;
  302. case Performance::MONITOR_TYPE_TIME: {
  303. label = rtos(value * 1000).pad_decimals(2) + " ms";
  304. tooltip = label;
  305. } break;
  306. default: {
  307. tooltip += " " + perf_items[i]->get_text(0);
  308. } break;
  309. }
  310. perf_items[i]->set_text(1, label);
  311. perf_items[i]->set_tooltip(1, tooltip);
  312. if (p[i] > perf_max[i])
  313. perf_max.write[i] = p[i];
  314. }
  315. }
  316. perf_history.push_front(p);
  317. perf_draw->update();
  318. } else if (p_msg == "visual:profile_frame") {
  319. DebuggerMarshalls::VisualProfilerFrame frame;
  320. frame.deserialize(p_data);
  321. EditorVisualProfiler::Metric metric;
  322. metric.areas.resize(frame.areas.size());
  323. metric.frame_number = frame.frame_number;
  324. metric.valid = true;
  325. {
  326. EditorVisualProfiler::Metric::Area *areas_ptr = metric.areas.ptrw();
  327. for (int i = 0; i < frame.areas.size(); i++) {
  328. areas_ptr[i].name = frame.areas[i].name;
  329. areas_ptr[i].cpu_time = frame.areas[i].cpu_msec;
  330. areas_ptr[i].gpu_time = frame.areas[i].gpu_msec;
  331. }
  332. }
  333. visual_profiler->add_frame_metric(metric);
  334. } else if (p_msg == "error") {
  335. DebuggerMarshalls::OutputError oe;
  336. ERR_FAIL_COND_MSG(oe.deserialize(p_data) == false, "Failed to deserialize error message");
  337. // Format time.
  338. Array time_vals;
  339. time_vals.push_back(oe.hr);
  340. time_vals.push_back(oe.min);
  341. time_vals.push_back(oe.sec);
  342. time_vals.push_back(oe.msec);
  343. bool e;
  344. String time = String("%d:%02d:%02d:%04d").sprintf(time_vals, &e);
  345. // Rest of the error data.
  346. bool source_is_project_file = oe.source_file.begins_with("res://");
  347. // Metadata to highlight error line in scripts.
  348. Array source_meta;
  349. source_meta.push_back(oe.source_file);
  350. source_meta.push_back(oe.source_line);
  351. // Create error tree to display above error or warning details.
  352. TreeItem *r = error_tree->get_root();
  353. if (!r) {
  354. r = error_tree->create_item();
  355. }
  356. // Also provide the relevant details as tooltip to quickly check without
  357. // uncollapsing the tree.
  358. String tooltip = oe.warning ? TTR("Warning:") : TTR("Error:");
  359. TreeItem *error = error_tree->create_item(r);
  360. error->set_collapsed(true);
  361. error->set_icon(0, get_icon(oe.warning ? "Warning" : "Error", "EditorIcons"));
  362. error->set_text(0, time);
  363. error->set_text_align(0, TreeItem::ALIGN_LEFT);
  364. String error_title;
  365. // Include method name, when given, in error title.
  366. if (!oe.source_func.empty())
  367. error_title += oe.source_func + ": ";
  368. // If we have a (custom) error message, use it as title, and add a C++ Error
  369. // item with the original error condition.
  370. error_title += oe.error_descr.empty() ? oe.error : oe.error_descr;
  371. error->set_text(1, error_title);
  372. tooltip += " " + error_title + "\n";
  373. if (!oe.error_descr.empty()) {
  374. // Add item for C++ error condition.
  375. TreeItem *cpp_cond = error_tree->create_item(error);
  376. cpp_cond->set_text(0, "<" + TTR("C++ Error") + ">");
  377. cpp_cond->set_text(1, oe.error);
  378. cpp_cond->set_text_align(0, TreeItem::ALIGN_LEFT);
  379. tooltip += TTR("C++ Error:") + " " + oe.error + "\n";
  380. if (source_is_project_file)
  381. cpp_cond->set_metadata(0, source_meta);
  382. }
  383. Vector<uint8_t> v;
  384. v.resize(100);
  385. // Source of the error.
  386. String source_txt = (source_is_project_file ? oe.source_file.get_file() : oe.source_file) + ":" + itos(oe.source_line);
  387. if (!oe.source_func.empty())
  388. source_txt += " @ " + oe.source_func + "()";
  389. TreeItem *cpp_source = error_tree->create_item(error);
  390. cpp_source->set_text(0, "<" + (source_is_project_file ? TTR("Source") : TTR("C++ Source")) + ">");
  391. cpp_source->set_text(1, source_txt);
  392. cpp_source->set_text_align(0, TreeItem::ALIGN_LEFT);
  393. tooltip += (source_is_project_file ? TTR("Source:") : TTR("C++ Source:")) + " " + source_txt + "\n";
  394. // Set metadata to highlight error line in scripts.
  395. if (source_is_project_file) {
  396. error->set_metadata(0, source_meta);
  397. cpp_source->set_metadata(0, source_meta);
  398. }
  399. error->set_tooltip(0, tooltip);
  400. error->set_tooltip(1, tooltip);
  401. // Format stack trace.
  402. // stack_items_count is the number of elements to parse, with 3 items per frame
  403. // of the stack trace (script, method, line).
  404. const ScriptLanguage::StackInfo *infos = oe.callstack.ptr();
  405. for (unsigned int i = 0; i < (unsigned int)oe.callstack.size(); i++) {
  406. TreeItem *stack_trace = error_tree->create_item(error);
  407. Array meta;
  408. meta.push_back(infos[i].file);
  409. meta.push_back(infos[i].line);
  410. stack_trace->set_metadata(0, meta);
  411. if (i == 0) {
  412. stack_trace->set_text(0, "<" + TTR("Stack Trace") + ">");
  413. stack_trace->set_text_align(0, TreeItem::ALIGN_LEFT);
  414. error->set_metadata(0, meta);
  415. }
  416. stack_trace->set_text(1, infos[i].file.get_file() + ":" + itos(infos[i].line) + " @ " + infos[i].func + "()");
  417. }
  418. if (oe.warning)
  419. warning_count++;
  420. else
  421. error_count++;
  422. } else if (p_msg == "servers:function_signature") {
  423. // Cache a profiler signature.
  424. DebuggerMarshalls::ScriptFunctionSignature sig;
  425. sig.deserialize(p_data);
  426. profiler_signature[sig.id] = sig.name;
  427. } else if (p_msg == "servers:profile_frame" || p_msg == "servers:profile_total") {
  428. EditorProfiler::Metric metric;
  429. DebuggerMarshalls::ServersProfilerFrame frame;
  430. frame.deserialize(p_data);
  431. metric.valid = true;
  432. metric.frame_number = frame.frame_number;
  433. metric.frame_time = frame.frame_time;
  434. metric.idle_time = frame.idle_time;
  435. metric.physics_time = frame.physics_time;
  436. metric.physics_frame_time = frame.physics_frame_time;
  437. if (frame.servers.size()) {
  438. EditorProfiler::Metric::Category frame_time;
  439. frame_time.signature = "category_frame_time";
  440. frame_time.name = "Frame Time";
  441. frame_time.total_time = metric.frame_time;
  442. EditorProfiler::Metric::Category::Item item;
  443. item.calls = 1;
  444. item.line = 0;
  445. item.name = "Physics Time";
  446. item.total = metric.physics_time;
  447. item.self = item.total;
  448. item.signature = "physics_time";
  449. frame_time.items.push_back(item);
  450. item.name = "Idle Time";
  451. item.total = metric.idle_time;
  452. item.self = item.total;
  453. item.signature = "idle_time";
  454. frame_time.items.push_back(item);
  455. item.name = "Physics Frame Time";
  456. item.total = metric.physics_frame_time;
  457. item.self = item.total;
  458. item.signature = "physics_frame_time";
  459. frame_time.items.push_back(item);
  460. metric.categories.push_back(frame_time);
  461. }
  462. for (int i = 0; i < frame.servers.size(); i++) {
  463. const DebuggerMarshalls::ServerInfo &srv = frame.servers[i];
  464. EditorProfiler::Metric::Category c;
  465. const String name = srv.name;
  466. c.name = name.capitalize();
  467. c.items.resize(srv.functions.size());
  468. c.total_time = 0;
  469. c.signature = "categ::" + name;
  470. for (int j = 0; j < srv.functions.size(); j++) {
  471. EditorProfiler::Metric::Category::Item item;
  472. item.calls = 1;
  473. item.line = 0;
  474. item.name = srv.functions[j].name;
  475. item.self = srv.functions[j].time;
  476. item.total = item.self;
  477. item.signature = "categ::" + name + "::" + item.name;
  478. item.name = item.name.capitalize();
  479. c.total_time += item.total;
  480. c.items.write[j] = item;
  481. }
  482. metric.categories.push_back(c);
  483. }
  484. EditorProfiler::Metric::Category funcs;
  485. funcs.total_time = frame.script_time;
  486. funcs.items.resize(frame.script_functions.size());
  487. funcs.name = "Script Functions";
  488. funcs.signature = "script_functions";
  489. for (int i = 0; i < frame.script_functions.size(); i++) {
  490. int signature = frame.script_functions[i].sig_id;
  491. int calls = frame.script_functions[i].call_count;
  492. float total = frame.script_functions[i].total_time;
  493. float self = frame.script_functions[i].self_time;
  494. EditorProfiler::Metric::Category::Item item;
  495. if (profiler_signature.has(signature)) {
  496. item.signature = profiler_signature[signature];
  497. String name = profiler_signature[signature];
  498. Vector<String> strings = name.split("::");
  499. if (strings.size() == 3) {
  500. item.name = strings[2];
  501. item.script = strings[0];
  502. item.line = strings[1].to_int();
  503. } else if (strings.size() == 4) { //Built-in scripts have an :: in their name
  504. item.name = strings[3];
  505. item.script = strings[0] + "::" + strings[1];
  506. item.line = strings[2].to_int();
  507. }
  508. } else {
  509. item.name = "SigErr " + itos(signature);
  510. }
  511. item.calls = calls;
  512. item.self = self;
  513. item.total = total;
  514. funcs.items.write[i] = item;
  515. }
  516. metric.categories.push_back(funcs);
  517. if (p_msg == "servers:profile_frame")
  518. profiler->add_frame_metric(metric, false);
  519. else
  520. profiler->add_frame_metric(metric, true);
  521. } else if (p_msg == "network:profile_frame") {
  522. DebuggerMarshalls::NetworkProfilerFrame frame;
  523. frame.deserialize(p_data);
  524. for (int i = 0; i < frame.infos.size(); i++) {
  525. network_profiler->add_node_frame_data(frame.infos[i]);
  526. }
  527. } else if (p_msg == "network:bandwidth") {
  528. ERR_FAIL_COND(p_data.size() < 2);
  529. network_profiler->set_bandwidth(p_data[0], p_data[1]);
  530. } else if (p_msg == "request_quit") {
  531. emit_signal("stop_requested");
  532. _stop_and_notify();
  533. } else {
  534. WARN_PRINT("unknown message " + p_msg);
  535. }
  536. }
  537. void ScriptEditorDebugger::_set_reason_text(const String &p_reason, MessageType p_type) {
  538. switch (p_type) {
  539. case MESSAGE_ERROR:
  540. reason->add_color_override("font_color", get_color("error_color", "Editor"));
  541. break;
  542. case MESSAGE_WARNING:
  543. reason->add_color_override("font_color", get_color("warning_color", "Editor"));
  544. break;
  545. default:
  546. reason->add_color_override("font_color", get_color("success_color", "Editor"));
  547. }
  548. reason->set_text(p_reason);
  549. reason->set_tooltip(p_reason.word_wrap(80));
  550. }
  551. void ScriptEditorDebugger::_performance_select() {
  552. perf_draw->update();
  553. }
  554. void ScriptEditorDebugger::_performance_draw() {
  555. Vector<int> which;
  556. for (int i = 0; i < perf_items.size(); i++) {
  557. if (perf_items[i]->is_checked(0))
  558. which.push_back(i);
  559. }
  560. if (which.empty()) {
  561. info_message->show();
  562. return;
  563. }
  564. info_message->hide();
  565. Ref<StyleBox> graph_sb = get_stylebox("normal", "TextEdit");
  566. Ref<Font> graph_font = get_font("font", "TextEdit");
  567. int cols = Math::ceil(Math::sqrt((float)which.size()));
  568. int rows = Math::ceil((float)which.size() / cols);
  569. if (which.size() == 1)
  570. rows = 1;
  571. int margin = 3;
  572. int point_sep = 5;
  573. Size2i s = Size2i(perf_draw->get_size()) / Size2i(cols, rows);
  574. for (int i = 0; i < which.size(); i++) {
  575. Point2i p(i % cols, i / cols);
  576. Rect2i r(p * s, s);
  577. r.position += Point2(margin, margin);
  578. r.size -= Point2(margin, margin) * 2.0;
  579. perf_draw->draw_style_box(graph_sb, r);
  580. r.position += graph_sb->get_offset();
  581. r.size -= graph_sb->get_minimum_size();
  582. int pi = which[i];
  583. Color c = get_color("accent_color", "Editor");
  584. float h = (float)which[i] / (float)(perf_items.size());
  585. // Use a darker color on light backgrounds for better visibility
  586. float value_multiplier = EditorSettings::get_singleton()->is_dark_theme() ? 1.4 : 0.55;
  587. c.set_hsv(Math::fmod(h + 0.4, 0.9), c.get_s() * 0.9, c.get_v() * value_multiplier);
  588. c.a = 0.6;
  589. perf_draw->draw_string(graph_font, r.position + Point2(0, graph_font->get_ascent()), perf_items[pi]->get_text(0), c, r.size.x);
  590. c.a = 0.9;
  591. perf_draw->draw_string(graph_font, r.position + Point2(0, graph_font->get_ascent() + graph_font->get_height()), perf_items[pi]->get_text(1), c, r.size.y);
  592. float spacing = point_sep / float(cols);
  593. float from = r.size.width;
  594. List<Vector<float>>::Element *E = perf_history.front();
  595. float prev = -1;
  596. while (from >= 0 && E) {
  597. float m = perf_max[pi];
  598. if (m == 0)
  599. m = 0.00001;
  600. float h2 = E->get()[pi] / m;
  601. h2 = (1.0 - h2) * r.size.y;
  602. if (E != perf_history.front())
  603. perf_draw->draw_line(r.position + Point2(from, h2), r.position + Point2(from + spacing, prev), c, Math::round(EDSCALE));
  604. prev = h2;
  605. E = E->next();
  606. from -= spacing;
  607. }
  608. }
  609. }
  610. void ScriptEditorDebugger::_notification(int p_what) {
  611. switch (p_what) {
  612. case NOTIFICATION_ENTER_TREE: {
  613. skip_breakpoints->set_icon(get_icon("DebugSkipBreakpointsOff", "EditorIcons"));
  614. copy->set_icon(get_icon("ActionCopy", "EditorIcons"));
  615. step->set_icon(get_icon("DebugStep", "EditorIcons"));
  616. next->set_icon(get_icon("DebugNext", "EditorIcons"));
  617. dobreak->set_icon(get_icon("Pause", "EditorIcons"));
  618. docontinue->set_icon(get_icon("DebugContinue", "EditorIcons"));
  619. le_set->connect("pressed", callable_mp(this, &ScriptEditorDebugger::_live_edit_set));
  620. le_clear->connect("pressed", callable_mp(this, &ScriptEditorDebugger::_live_edit_clear));
  621. error_tree->connect("item_selected", callable_mp(this, &ScriptEditorDebugger::_error_selected));
  622. error_tree->connect("item_activated", callable_mp(this, &ScriptEditorDebugger::_error_activated));
  623. vmem_refresh->set_icon(get_icon("Reload", "EditorIcons"));
  624. reason->add_color_override("font_color", get_color("error_color", "Editor"));
  625. } break;
  626. case NOTIFICATION_PROCESS: {
  627. if (is_session_active()) {
  628. if (camera_override == CameraOverride::OVERRIDE_2D) {
  629. CanvasItemEditor *editor = CanvasItemEditor::get_singleton();
  630. Dictionary state = editor->get_state();
  631. float zoom = state["zoom"];
  632. Point2 offset = state["ofs"];
  633. Transform2D transform;
  634. transform.scale_basis(Size2(zoom, zoom));
  635. transform.elements[2] = -offset * zoom;
  636. Array msg;
  637. msg.push_back(transform);
  638. _put_msg("scene:override_camera_2D:transform", msg);
  639. } else if (camera_override >= CameraOverride::OVERRIDE_3D_1) {
  640. int viewport_idx = camera_override - CameraOverride::OVERRIDE_3D_1;
  641. SpatialEditorViewport *viewport = SpatialEditor::get_singleton()->get_editor_viewport(viewport_idx);
  642. Camera *const cam = viewport->get_camera();
  643. Array msg;
  644. msg.push_back(cam->get_camera_transform());
  645. if (cam->get_projection() == Camera::PROJECTION_ORTHOGONAL) {
  646. msg.push_back(false);
  647. msg.push_back(cam->get_size());
  648. } else {
  649. msg.push_back(true);
  650. msg.push_back(cam->get_fov());
  651. }
  652. msg.push_back(cam->get_znear());
  653. msg.push_back(cam->get_zfar());
  654. _put_msg("scene:override_camera_3D:transform", msg);
  655. }
  656. }
  657. const uint64_t until = OS::get_singleton()->get_ticks_msec() + 20;
  658. while (peer.is_valid() && peer->has_message()) {
  659. Array arr = peer->get_message();
  660. if (arr.size() != 2 || arr[0].get_type() != Variant::STRING || arr[1].get_type() != Variant::ARRAY) {
  661. _stop_and_notify();
  662. ERR_FAIL_MSG("Invalid message format received from peer");
  663. }
  664. _parse_message(arr[0], arr[1]);
  665. if (OS::get_singleton()->get_ticks_msec() > until)
  666. break;
  667. }
  668. if (!is_session_active()) {
  669. _stop_and_notify();
  670. break;
  671. };
  672. } break;
  673. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  674. if (tabs->has_stylebox_override("panel")) {
  675. tabs->add_style_override("panel", editor->get_gui_base()->get_stylebox("DebuggerPanel", "EditorStyles"));
  676. }
  677. copy->set_icon(get_icon("ActionCopy", "EditorIcons"));
  678. step->set_icon(get_icon("DebugStep", "EditorIcons"));
  679. next->set_icon(get_icon("DebugNext", "EditorIcons"));
  680. dobreak->set_icon(get_icon("Pause", "EditorIcons"));
  681. docontinue->set_icon(get_icon("DebugContinue", "EditorIcons"));
  682. vmem_refresh->set_icon(get_icon("Reload", "EditorIcons"));
  683. } break;
  684. }
  685. }
  686. void ScriptEditorDebugger::_clear_execution() {
  687. TreeItem *ti = stack_dump->get_selected();
  688. if (!ti)
  689. return;
  690. Dictionary d = ti->get_metadata(0);
  691. stack_script = ResourceLoader::load(d["file"]);
  692. emit_signal("clear_execution", stack_script);
  693. stack_script.unref();
  694. stack_dump->clear();
  695. inspector->clear_stack_variables();
  696. }
  697. void ScriptEditorDebugger::start(Ref<RemoteDebuggerPeer> p_peer) {
  698. error_count = 0;
  699. warning_count = 0;
  700. stop();
  701. peer = p_peer;
  702. ERR_FAIL_COND(p_peer.is_null());
  703. perf_history.clear();
  704. for (int i = 0; i < Performance::MONITOR_MAX; i++) {
  705. perf_max.write[i] = 0;
  706. }
  707. set_process(true);
  708. breaked = false;
  709. can_debug = true;
  710. camera_override = CameraOverride::OVERRIDE_NONE;
  711. tabs->set_current_tab(0);
  712. _set_reason_text(TTR("Debug session started."), MESSAGE_SUCCESS);
  713. _update_buttons_state();
  714. }
  715. void ScriptEditorDebugger::_update_buttons_state() {
  716. const bool active = is_session_active();
  717. const bool has_editor_tree = active && editor_remote_tree && editor_remote_tree->get_selected();
  718. vmem_refresh->set_disabled(!active);
  719. step->set_disabled(!active || !breaked || !can_debug);
  720. next->set_disabled(!active || !breaked || !can_debug);
  721. copy->set_disabled(!active || !breaked);
  722. docontinue->set_disabled(!active || !breaked);
  723. dobreak->set_disabled(!active || breaked);
  724. le_clear->set_disabled(!active);
  725. le_set->set_disabled(!has_editor_tree);
  726. }
  727. void ScriptEditorDebugger::_stop_and_notify() {
  728. stop();
  729. emit_signal("stopped");
  730. _set_reason_text(TTR("Debug session closed."), MESSAGE_WARNING);
  731. }
  732. void ScriptEditorDebugger::stop() {
  733. set_process(false);
  734. breaked = false;
  735. can_debug = false;
  736. remote_pid = 0;
  737. _clear_execution();
  738. inspector->clear_cache();
  739. if (peer.is_valid()) {
  740. peer->close();
  741. peer.unref();
  742. reason->set_text("");
  743. reason->set_tooltip("");
  744. }
  745. node_path_cache.clear();
  746. res_path_cache.clear();
  747. profiler_signature.clear();
  748. inspector->edit(NULL);
  749. _update_buttons_state();
  750. }
  751. void ScriptEditorDebugger::_profiler_activate(bool p_enable, int p_type) {
  752. Array data;
  753. data.push_back(p_enable);
  754. switch (p_type) {
  755. case PROFILER_NETWORK:
  756. _put_msg("profiler:network", data);
  757. break;
  758. case PROFILER_VISUAL:
  759. _put_msg("profiler:visual", data);
  760. break;
  761. case PROFILER_SCRIPTS_SERVERS:
  762. if (p_enable) {
  763. // Clear old script signatures. (should we move all this into the profiler?)
  764. profiler_signature.clear();
  765. // Add max funcs options to request.
  766. Array opts;
  767. int max_funcs = EditorSettings::get_singleton()->get("debugger/profiler_frame_max_functions");
  768. opts.push_back(CLAMP(max_funcs, 16, 512));
  769. data.push_back(opts);
  770. }
  771. _put_msg("profiler:servers", data);
  772. break;
  773. default:
  774. ERR_FAIL_MSG("Invalid profiler type");
  775. }
  776. }
  777. void ScriptEditorDebugger::_profiler_seeked() {
  778. if (breaked)
  779. return;
  780. debug_break();
  781. }
  782. void ScriptEditorDebugger::_stack_dump_frame_selected() {
  783. emit_signal("stack_frame_selected");
  784. int frame = get_stack_script_frame();
  785. if (is_session_active() && frame >= 0) {
  786. Array msg;
  787. msg.push_back(frame);
  788. _put_msg("get_stack_frame_vars", msg);
  789. } else {
  790. inspector->edit(NULL);
  791. }
  792. }
  793. void ScriptEditorDebugger::_export_csv() {
  794. file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
  795. file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  796. file_dialog->popup_centered_ratio();
  797. }
  798. String ScriptEditorDebugger::get_var_value(const String &p_var) const {
  799. if (!breaked)
  800. return String();
  801. return inspector->get_stack_variable(p_var);
  802. }
  803. int ScriptEditorDebugger::_get_node_path_cache(const NodePath &p_path) {
  804. const int *r = node_path_cache.getptr(p_path);
  805. if (r)
  806. return *r;
  807. last_path_id++;
  808. node_path_cache[p_path] = last_path_id;
  809. Array msg;
  810. msg.push_back(p_path);
  811. msg.push_back(last_path_id);
  812. _put_msg("scene:live_node_path", msg);
  813. return last_path_id;
  814. }
  815. int ScriptEditorDebugger::_get_res_path_cache(const String &p_path) {
  816. Map<String, int>::Element *E = res_path_cache.find(p_path);
  817. if (E)
  818. return E->get();
  819. last_path_id++;
  820. res_path_cache[p_path] = last_path_id;
  821. Array msg;
  822. msg.push_back(p_path);
  823. msg.push_back(last_path_id);
  824. _put_msg("scene:live_res_path", msg);
  825. return last_path_id;
  826. }
  827. void ScriptEditorDebugger::_method_changed(Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE) {
  828. if (!p_base || !live_debug || !is_session_active() || !editor->get_edited_scene())
  829. return;
  830. Node *node = Object::cast_to<Node>(p_base);
  831. VARIANT_ARGPTRS
  832. for (int i = 0; i < VARIANT_ARG_MAX; i++) {
  833. //no pointers, sorry
  834. if (argptr[i] && (argptr[i]->get_type() == Variant::OBJECT || argptr[i]->get_type() == Variant::_RID))
  835. return;
  836. }
  837. if (node) {
  838. NodePath path = editor->get_edited_scene()->get_path_to(node);
  839. int pathid = _get_node_path_cache(path);
  840. Array msg;
  841. msg.push_back(pathid);
  842. msg.push_back(p_name);
  843. for (int i = 0; i < VARIANT_ARG_MAX; i++) {
  844. //no pointers, sorry
  845. msg.push_back(*argptr[i]);
  846. }
  847. _put_msg("scene:live_node_call", msg);
  848. return;
  849. }
  850. Resource *res = Object::cast_to<Resource>(p_base);
  851. if (res && res->get_path() != String()) {
  852. String respath = res->get_path();
  853. int pathid = _get_res_path_cache(respath);
  854. Array msg;
  855. msg.push_back(pathid);
  856. msg.push_back(p_name);
  857. for (int i = 0; i < VARIANT_ARG_MAX; i++) {
  858. //no pointers, sorry
  859. msg.push_back(*argptr[i]);
  860. }
  861. _put_msg("scene:live_res_call", msg);
  862. return;
  863. }
  864. }
  865. void ScriptEditorDebugger::_property_changed(Object *p_base, const StringName &p_property, const Variant &p_value) {
  866. if (!p_base || !live_debug || !editor->get_edited_scene())
  867. return;
  868. Node *node = Object::cast_to<Node>(p_base);
  869. if (node) {
  870. NodePath path = editor->get_edited_scene()->get_path_to(node);
  871. int pathid = _get_node_path_cache(path);
  872. if (p_value.is_ref()) {
  873. Ref<Resource> res = p_value;
  874. if (res.is_valid() && res->get_path() != String()) {
  875. Array msg;
  876. msg.push_back(pathid);
  877. msg.push_back(p_property);
  878. msg.push_back(res->get_path());
  879. _put_msg("scene:live_node_prop_res", msg);
  880. }
  881. } else {
  882. Array msg;
  883. msg.push_back(pathid);
  884. msg.push_back(p_property);
  885. msg.push_back(p_value);
  886. _put_msg("scene:live_node_prop", msg);
  887. }
  888. return;
  889. }
  890. Resource *res = Object::cast_to<Resource>(p_base);
  891. if (res && res->get_path() != String()) {
  892. String respath = res->get_path();
  893. int pathid = _get_res_path_cache(respath);
  894. if (p_value.is_ref()) {
  895. Ref<Resource> res2 = p_value;
  896. if (res2.is_valid() && res2->get_path() != String()) {
  897. Array msg;
  898. msg.push_back(pathid);
  899. msg.push_back(p_property);
  900. msg.push_back(res2->get_path());
  901. _put_msg("scene:live_res_prop_res", msg);
  902. }
  903. } else {
  904. Array msg;
  905. msg.push_back(pathid);
  906. msg.push_back(p_property);
  907. msg.push_back(p_value);
  908. _put_msg("scene:live_res_prop", msg);
  909. }
  910. return;
  911. }
  912. }
  913. String ScriptEditorDebugger::get_stack_script_file() const {
  914. TreeItem *ti = stack_dump->get_selected();
  915. if (!ti)
  916. return "";
  917. Dictionary d = ti->get_metadata(0);
  918. return d["file"];
  919. }
  920. int ScriptEditorDebugger::get_stack_script_line() const {
  921. TreeItem *ti = stack_dump->get_selected();
  922. if (!ti)
  923. return -1;
  924. Dictionary d = ti->get_metadata(0);
  925. return d["line"];
  926. }
  927. int ScriptEditorDebugger::get_stack_script_frame() const {
  928. TreeItem *ti = stack_dump->get_selected();
  929. if (!ti)
  930. return -1;
  931. Dictionary d = ti->get_metadata(0);
  932. return d["frame"];
  933. }
  934. void ScriptEditorDebugger::set_live_debugging(bool p_enable) {
  935. live_debug = p_enable;
  936. }
  937. void ScriptEditorDebugger::_live_edit_set() {
  938. if (!is_session_active() || !editor_remote_tree)
  939. return;
  940. TreeItem *ti = editor_remote_tree->get_selected();
  941. if (!ti)
  942. return;
  943. String path;
  944. while (ti) {
  945. String lp = ti->get_text(0);
  946. path = "/" + lp + path;
  947. ti = ti->get_parent();
  948. }
  949. NodePath np = path;
  950. editor->get_editor_data().set_edited_scene_live_edit_root(np);
  951. update_live_edit_root();
  952. }
  953. void ScriptEditorDebugger::_live_edit_clear() {
  954. NodePath np = NodePath("/root");
  955. editor->get_editor_data().set_edited_scene_live_edit_root(np);
  956. update_live_edit_root();
  957. }
  958. void ScriptEditorDebugger::update_live_edit_root() {
  959. NodePath np = editor->get_editor_data().get_edited_scene_live_edit_root();
  960. Array msg;
  961. msg.push_back(np);
  962. if (editor->get_edited_scene())
  963. msg.push_back(editor->get_edited_scene()->get_filename());
  964. else
  965. msg.push_back("");
  966. _put_msg("scene:live_set_root", msg);
  967. live_edit_root->set_text(np);
  968. }
  969. void ScriptEditorDebugger::live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name) {
  970. if (live_debug) {
  971. Array msg;
  972. msg.push_back(p_parent);
  973. msg.push_back(p_type);
  974. msg.push_back(p_name);
  975. _put_msg("scene:live_create_node", msg);
  976. }
  977. }
  978. void ScriptEditorDebugger::live_debug_instance_node(const NodePath &p_parent, const String &p_path, const String &p_name) {
  979. if (live_debug) {
  980. Array msg;
  981. msg.push_back(p_parent);
  982. msg.push_back(p_path);
  983. msg.push_back(p_name);
  984. _put_msg("scene:live_instance_node", msg);
  985. }
  986. }
  987. void ScriptEditorDebugger::live_debug_remove_node(const NodePath &p_at) {
  988. if (live_debug) {
  989. Array msg;
  990. msg.push_back(p_at);
  991. _put_msg("scene:live_remove_node", msg);
  992. }
  993. }
  994. void ScriptEditorDebugger::live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id) {
  995. if (live_debug) {
  996. Array msg;
  997. msg.push_back(p_at);
  998. msg.push_back(p_keep_id);
  999. _put_msg("scene:live_remove_and_keep_node", msg);
  1000. }
  1001. }
  1002. void ScriptEditorDebugger::live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos) {
  1003. if (live_debug) {
  1004. Array msg;
  1005. msg.push_back(p_id);
  1006. msg.push_back(p_at);
  1007. msg.push_back(p_at_pos);
  1008. _put_msg("scene:live_restore_node", msg);
  1009. }
  1010. }
  1011. void ScriptEditorDebugger::live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name) {
  1012. if (live_debug) {
  1013. Array msg;
  1014. msg.push_back(p_at);
  1015. msg.push_back(p_new_name);
  1016. _put_msg("scene:live_duplicate_node", msg);
  1017. }
  1018. }
  1019. void ScriptEditorDebugger::live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos) {
  1020. if (live_debug) {
  1021. Array msg;
  1022. msg.push_back(p_at);
  1023. msg.push_back(p_new_place);
  1024. msg.push_back(p_new_name);
  1025. msg.push_back(p_at_pos);
  1026. _put_msg("scene:live_reparent_node", msg);
  1027. }
  1028. }
  1029. CameraOverride ScriptEditorDebugger::get_camera_override() const {
  1030. return camera_override;
  1031. }
  1032. void ScriptEditorDebugger::set_camera_override(CameraOverride p_override) {
  1033. if (p_override == CameraOverride::OVERRIDE_2D && camera_override != CameraOverride::OVERRIDE_2D) {
  1034. Array msg;
  1035. msg.push_back(true);
  1036. _put_msg("scene:override_camera_2D:set", msg);
  1037. } else if (p_override != CameraOverride::OVERRIDE_2D && camera_override == CameraOverride::OVERRIDE_2D) {
  1038. Array msg;
  1039. msg.push_back(false);
  1040. _put_msg("scene:override_camera_2D:set", msg);
  1041. } else if (p_override >= CameraOverride::OVERRIDE_3D_1 && camera_override < CameraOverride::OVERRIDE_3D_1) {
  1042. Array msg;
  1043. msg.push_back(true);
  1044. _put_msg("scene:override_camera_3D:set", msg);
  1045. } else if (p_override < CameraOverride::OVERRIDE_3D_1 && camera_override >= CameraOverride::OVERRIDE_3D_1) {
  1046. Array msg;
  1047. msg.push_back(false);
  1048. _put_msg("scene:override_camera_3D:set", msg);
  1049. }
  1050. camera_override = p_override;
  1051. }
  1052. void ScriptEditorDebugger::set_breakpoint(const String &p_path, int p_line, bool p_enabled) {
  1053. Array msg;
  1054. msg.push_back(p_path);
  1055. msg.push_back(p_line);
  1056. msg.push_back(p_enabled);
  1057. _put_msg("breakpoint", msg);
  1058. }
  1059. void ScriptEditorDebugger::reload_scripts() {
  1060. _put_msg("reload_scripts", Array());
  1061. }
  1062. bool ScriptEditorDebugger::is_skip_breakpoints() {
  1063. return skip_breakpoints_value;
  1064. }
  1065. void ScriptEditorDebugger::_error_activated() {
  1066. TreeItem *selected = error_tree->get_selected();
  1067. TreeItem *ci = selected->get_children();
  1068. if (ci) {
  1069. selected->set_collapsed(!selected->is_collapsed());
  1070. }
  1071. }
  1072. void ScriptEditorDebugger::_error_selected() {
  1073. TreeItem *selected = error_tree->get_selected();
  1074. Array meta = selected->get_metadata(0);
  1075. if (meta.size() == 0) {
  1076. return;
  1077. }
  1078. emit_signal("error_selected", String(meta[0]), int(meta[1]));
  1079. }
  1080. void ScriptEditorDebugger::_expand_errors_list() {
  1081. TreeItem *root = error_tree->get_root();
  1082. if (!root)
  1083. return;
  1084. TreeItem *item = root->get_children();
  1085. while (item) {
  1086. item->set_collapsed(false);
  1087. item = item->get_next();
  1088. }
  1089. }
  1090. void ScriptEditorDebugger::_collapse_errors_list() {
  1091. TreeItem *root = error_tree->get_root();
  1092. if (!root)
  1093. return;
  1094. TreeItem *item = root->get_children();
  1095. while (item) {
  1096. item->set_collapsed(true);
  1097. item = item->get_next();
  1098. }
  1099. }
  1100. void ScriptEditorDebugger::_clear_errors_list() {
  1101. error_tree->clear();
  1102. error_count = 0;
  1103. warning_count = 0;
  1104. }
  1105. // Right click on specific file(s) or folder(s).
  1106. void ScriptEditorDebugger::_error_tree_item_rmb_selected(const Vector2 &p_pos) {
  1107. item_menu->clear();
  1108. item_menu->set_size(Size2(1, 1));
  1109. if (error_tree->is_anything_selected()) {
  1110. item_menu->add_icon_item(get_icon("ActionCopy", "EditorIcons"), TTR("Copy Error"), 0);
  1111. }
  1112. if (item_menu->get_item_count() > 0) {
  1113. item_menu->set_position(error_tree->get_global_position() + p_pos);
  1114. item_menu->popup();
  1115. }
  1116. }
  1117. void ScriptEditorDebugger::_item_menu_id_pressed(int p_option) {
  1118. TreeItem *ti = error_tree->get_selected();
  1119. while (ti->get_parent() != error_tree->get_root())
  1120. ti = ti->get_parent();
  1121. String type;
  1122. if (ti->get_icon(0) == get_icon("Warning", "EditorIcons")) {
  1123. type = "W ";
  1124. } else if (ti->get_icon(0) == get_icon("Error", "EditorIcons")) {
  1125. type = "E ";
  1126. }
  1127. String text = ti->get_text(0) + " ";
  1128. int rpad_len = text.length();
  1129. text = type + text + ti->get_text(1) + "\n";
  1130. TreeItem *ci = ti->get_children();
  1131. while (ci) {
  1132. text += " " + ci->get_text(0).rpad(rpad_len) + ci->get_text(1) + "\n";
  1133. ci = ci->get_next();
  1134. }
  1135. DisplayServer::get_singleton()->clipboard_set(text);
  1136. }
  1137. void ScriptEditorDebugger::_tab_changed(int p_tab) {
  1138. if (tabs->get_tab_title(p_tab) == TTR("Video RAM")) {
  1139. // "Video RAM" tab was clicked, refresh the data it's displaying when entering the tab.
  1140. _video_mem_request();
  1141. }
  1142. }
  1143. void ScriptEditorDebugger::_bind_methods() {
  1144. ClassDB::bind_method(D_METHOD("live_debug_create_node"), &ScriptEditorDebugger::live_debug_create_node);
  1145. ClassDB::bind_method(D_METHOD("live_debug_instance_node"), &ScriptEditorDebugger::live_debug_instance_node);
  1146. ClassDB::bind_method(D_METHOD("live_debug_remove_node"), &ScriptEditorDebugger::live_debug_remove_node);
  1147. ClassDB::bind_method(D_METHOD("live_debug_remove_and_keep_node"), &ScriptEditorDebugger::live_debug_remove_and_keep_node);
  1148. ClassDB::bind_method(D_METHOD("live_debug_restore_node"), &ScriptEditorDebugger::live_debug_restore_node);
  1149. ClassDB::bind_method(D_METHOD("live_debug_duplicate_node"), &ScriptEditorDebugger::live_debug_duplicate_node);
  1150. ClassDB::bind_method(D_METHOD("live_debug_reparent_node"), &ScriptEditorDebugger::live_debug_reparent_node);
  1151. ClassDB::bind_method(D_METHOD("request_remote_object", "id"), &ScriptEditorDebugger::request_remote_object);
  1152. ClassDB::bind_method(D_METHOD("update_remote_object", "id", "property", "value"), &ScriptEditorDebugger::update_remote_object);
  1153. ADD_SIGNAL(MethodInfo("stopped"));
  1154. ADD_SIGNAL(MethodInfo("stop_requested"));
  1155. ADD_SIGNAL(MethodInfo("stack_frame_selected", PropertyInfo(Variant::INT, "frame")));
  1156. ADD_SIGNAL(MethodInfo("error_selected", PropertyInfo(Variant::INT, "error")));
  1157. ADD_SIGNAL(MethodInfo("set_execution", PropertyInfo("script"), PropertyInfo(Variant::INT, "line")));
  1158. ADD_SIGNAL(MethodInfo("clear_execution", PropertyInfo("script")));
  1159. ADD_SIGNAL(MethodInfo("breaked", PropertyInfo(Variant::BOOL, "reallydid"), PropertyInfo(Variant::BOOL, "can_debug")));
  1160. ADD_SIGNAL(MethodInfo("remote_object_requested", PropertyInfo(Variant::INT, "id")));
  1161. ADD_SIGNAL(MethodInfo("remote_object_updated", PropertyInfo(Variant::INT, "id")));
  1162. ADD_SIGNAL(MethodInfo("remote_object_property_updated", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::STRING, "property")));
  1163. ADD_SIGNAL(MethodInfo("remote_tree_updated"));
  1164. }
  1165. ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) {
  1166. editor = p_editor;
  1167. tabs = memnew(TabContainer);
  1168. tabs->set_tab_align(TabContainer::ALIGN_LEFT);
  1169. tabs->add_style_override("panel", editor->get_gui_base()->get_stylebox("DebuggerPanel", "EditorStyles"));
  1170. tabs->connect("tab_changed", callable_mp(this, &ScriptEditorDebugger::_tab_changed));
  1171. add_child(tabs);
  1172. { //debugger
  1173. VBoxContainer *vbc = memnew(VBoxContainer);
  1174. vbc->set_name(TTR("Debugger"));
  1175. Control *dbg = vbc;
  1176. HBoxContainer *hbc = memnew(HBoxContainer);
  1177. vbc->add_child(hbc);
  1178. reason = memnew(Label);
  1179. reason->set_text("");
  1180. hbc->add_child(reason);
  1181. reason->set_h_size_flags(SIZE_EXPAND_FILL);
  1182. reason->set_autowrap(true);
  1183. reason->set_max_lines_visible(3);
  1184. reason->set_mouse_filter(Control::MOUSE_FILTER_PASS);
  1185. hbc->add_child(memnew(VSeparator));
  1186. skip_breakpoints = memnew(ToolButton);
  1187. hbc->add_child(skip_breakpoints);
  1188. skip_breakpoints->set_tooltip(TTR("Skip Breakpoints"));
  1189. skip_breakpoints->connect("pressed", callable_mp(this, &ScriptEditorDebugger::debug_skip_breakpoints));
  1190. hbc->add_child(memnew(VSeparator));
  1191. copy = memnew(ToolButton);
  1192. hbc->add_child(copy);
  1193. copy->set_tooltip(TTR("Copy Error"));
  1194. copy->connect("pressed", callable_mp(this, &ScriptEditorDebugger::debug_copy));
  1195. hbc->add_child(memnew(VSeparator));
  1196. step = memnew(ToolButton);
  1197. hbc->add_child(step);
  1198. step->set_tooltip(TTR("Step Into"));
  1199. step->set_shortcut(ED_GET_SHORTCUT("debugger/step_into"));
  1200. step->connect("pressed", callable_mp(this, &ScriptEditorDebugger::debug_step));
  1201. next = memnew(ToolButton);
  1202. hbc->add_child(next);
  1203. next->set_tooltip(TTR("Step Over"));
  1204. next->set_shortcut(ED_GET_SHORTCUT("debugger/step_over"));
  1205. next->connect("pressed", callable_mp(this, &ScriptEditorDebugger::debug_next));
  1206. hbc->add_child(memnew(VSeparator));
  1207. dobreak = memnew(ToolButton);
  1208. hbc->add_child(dobreak);
  1209. dobreak->set_tooltip(TTR("Break"));
  1210. dobreak->set_shortcut(ED_GET_SHORTCUT("debugger/break"));
  1211. dobreak->connect("pressed", callable_mp(this, &ScriptEditorDebugger::debug_break));
  1212. docontinue = memnew(ToolButton);
  1213. hbc->add_child(docontinue);
  1214. docontinue->set_tooltip(TTR("Continue"));
  1215. docontinue->set_shortcut(ED_GET_SHORTCUT("debugger/continue"));
  1216. docontinue->connect("pressed", callable_mp(this, &ScriptEditorDebugger::debug_continue));
  1217. HSplitContainer *sc = memnew(HSplitContainer);
  1218. vbc->add_child(sc);
  1219. sc->set_v_size_flags(SIZE_EXPAND_FILL);
  1220. stack_dump = memnew(Tree);
  1221. stack_dump->set_allow_reselect(true);
  1222. stack_dump->set_columns(1);
  1223. stack_dump->set_column_titles_visible(true);
  1224. stack_dump->set_column_title(0, TTR("Stack Frames"));
  1225. stack_dump->set_h_size_flags(SIZE_EXPAND_FILL);
  1226. stack_dump->set_hide_root(true);
  1227. stack_dump->connect("cell_selected", callable_mp(this, &ScriptEditorDebugger::_stack_dump_frame_selected));
  1228. sc->add_child(stack_dump);
  1229. inspector = memnew(EditorDebuggerInspector);
  1230. inspector->set_h_size_flags(SIZE_EXPAND_FILL);
  1231. inspector->set_enable_capitalize_paths(false);
  1232. inspector->set_read_only(true);
  1233. inspector->connect("object_selected", callable_mp(this, &ScriptEditorDebugger::_remote_object_selected));
  1234. inspector->connect("object_edited", callable_mp(this, &ScriptEditorDebugger::_remote_object_edited));
  1235. inspector->connect("object_property_updated", callable_mp(this, &ScriptEditorDebugger::_remote_object_property_updated));
  1236. sc->add_child(inspector);
  1237. tabs->add_child(dbg);
  1238. }
  1239. { //errors
  1240. errors_tab = memnew(VBoxContainer);
  1241. errors_tab->set_name(TTR("Errors"));
  1242. HBoxContainer *errhb = memnew(HBoxContainer);
  1243. errors_tab->add_child(errhb);
  1244. Button *expand_all = memnew(Button);
  1245. expand_all->set_text(TTR("Expand All"));
  1246. expand_all->connect("pressed", callable_mp(this, &ScriptEditorDebugger::_expand_errors_list));
  1247. errhb->add_child(expand_all);
  1248. Button *collapse_all = memnew(Button);
  1249. collapse_all->set_text(TTR("Collapse All"));
  1250. collapse_all->connect("pressed", callable_mp(this, &ScriptEditorDebugger::_collapse_errors_list));
  1251. errhb->add_child(collapse_all);
  1252. Control *space = memnew(Control);
  1253. space->set_h_size_flags(SIZE_EXPAND_FILL);
  1254. errhb->add_child(space);
  1255. clearbutton = memnew(Button);
  1256. clearbutton->set_text(TTR("Clear"));
  1257. clearbutton->set_h_size_flags(0);
  1258. clearbutton->connect("pressed", callable_mp(this, &ScriptEditorDebugger::_clear_errors_list));
  1259. errhb->add_child(clearbutton);
  1260. error_tree = memnew(Tree);
  1261. error_tree->set_columns(2);
  1262. error_tree->set_column_expand(0, false);
  1263. error_tree->set_column_min_width(0, 140);
  1264. error_tree->set_column_expand(1, true);
  1265. error_tree->set_select_mode(Tree::SELECT_ROW);
  1266. error_tree->set_hide_root(true);
  1267. error_tree->set_v_size_flags(SIZE_EXPAND_FILL);
  1268. error_tree->set_allow_rmb_select(true);
  1269. error_tree->connect("item_rmb_selected", callable_mp(this, &ScriptEditorDebugger::_error_tree_item_rmb_selected));
  1270. errors_tab->add_child(error_tree);
  1271. item_menu = memnew(PopupMenu);
  1272. item_menu->connect("id_pressed", callable_mp(this, &ScriptEditorDebugger::_item_menu_id_pressed));
  1273. error_tree->add_child(item_menu);
  1274. tabs->add_child(errors_tab);
  1275. }
  1276. { // File dialog
  1277. file_dialog = memnew(EditorFileDialog);
  1278. file_dialog->connect("file_selected", callable_mp(this, &ScriptEditorDebugger::_file_selected));
  1279. add_child(file_dialog);
  1280. }
  1281. { //profiler
  1282. profiler = memnew(EditorProfiler);
  1283. profiler->set_name(TTR("Profiler"));
  1284. tabs->add_child(profiler);
  1285. profiler->connect("enable_profiling", callable_mp(this, &ScriptEditorDebugger::_profiler_activate), varray(PROFILER_SCRIPTS_SERVERS));
  1286. profiler->connect("break_request", callable_mp(this, &ScriptEditorDebugger::_profiler_seeked));
  1287. }
  1288. { //frame profiler
  1289. visual_profiler = memnew(EditorVisualProfiler);
  1290. visual_profiler->set_name(TTR("Visual Profiler"));
  1291. tabs->add_child(visual_profiler);
  1292. visual_profiler->connect("enable_profiling", callable_mp(this, &ScriptEditorDebugger::_profiler_activate), varray(PROFILER_VISUAL));
  1293. }
  1294. { //network profiler
  1295. network_profiler = memnew(EditorNetworkProfiler);
  1296. network_profiler->set_name(TTR("Network Profiler"));
  1297. tabs->add_child(network_profiler);
  1298. network_profiler->connect("enable_profiling", callable_mp(this, &ScriptEditorDebugger::_profiler_activate), varray(PROFILER_NETWORK));
  1299. }
  1300. { //monitors
  1301. HSplitContainer *hsp = memnew(HSplitContainer);
  1302. perf_monitors = memnew(Tree);
  1303. perf_monitors->set_columns(2);
  1304. perf_monitors->set_column_title(0, TTR("Monitor"));
  1305. perf_monitors->set_column_title(1, TTR("Value"));
  1306. perf_monitors->set_column_titles_visible(true);
  1307. perf_monitors->connect("item_edited", callable_mp(this, &ScriptEditorDebugger::_performance_select));
  1308. hsp->add_child(perf_monitors);
  1309. perf_draw = memnew(Control);
  1310. perf_draw->set_clip_contents(true);
  1311. perf_draw->connect("draw", callable_mp(this, &ScriptEditorDebugger::_performance_draw));
  1312. hsp->add_child(perf_draw);
  1313. hsp->set_name(TTR("Monitors"));
  1314. hsp->set_split_offset(340 * EDSCALE);
  1315. tabs->add_child(hsp);
  1316. perf_max.resize(Performance::MONITOR_MAX);
  1317. Map<String, TreeItem *> bases;
  1318. TreeItem *root = perf_monitors->create_item();
  1319. perf_monitors->set_hide_root(true);
  1320. for (int i = 0; i < Performance::MONITOR_MAX; i++) {
  1321. String n = Performance::get_singleton()->get_monitor_name(Performance::Monitor(i));
  1322. Performance::MonitorType mtype = Performance::get_singleton()->get_monitor_type(Performance::Monitor(i));
  1323. String base = n.get_slice("/", 0);
  1324. String name = n.get_slice("/", 1);
  1325. if (!bases.has(base)) {
  1326. TreeItem *b = perf_monitors->create_item(root);
  1327. b->set_text(0, base.capitalize());
  1328. b->set_editable(0, false);
  1329. b->set_selectable(0, false);
  1330. b->set_expand_right(0, true);
  1331. bases[base] = b;
  1332. }
  1333. TreeItem *it = perf_monitors->create_item(bases[base]);
  1334. it->set_metadata(1, mtype);
  1335. it->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  1336. it->set_editable(0, true);
  1337. it->set_selectable(0, false);
  1338. it->set_selectable(1, false);
  1339. it->set_text(0, name.capitalize());
  1340. perf_items.push_back(it);
  1341. perf_max.write[i] = 0;
  1342. }
  1343. info_message = memnew(Label);
  1344. info_message->set_text(TTR("Pick one or more items from the list to display the graph."));
  1345. info_message->set_valign(Label::VALIGN_CENTER);
  1346. info_message->set_align(Label::ALIGN_CENTER);
  1347. info_message->set_autowrap(true);
  1348. info_message->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  1349. info_message->set_anchors_and_margins_preset(PRESET_WIDE, PRESET_MODE_KEEP_SIZE, 8 * EDSCALE);
  1350. perf_draw->add_child(info_message);
  1351. }
  1352. { //vmem inspect
  1353. VBoxContainer *vmem_vb = memnew(VBoxContainer);
  1354. HBoxContainer *vmem_hb = memnew(HBoxContainer);
  1355. Label *vmlb = memnew(Label(TTR("List of Video Memory Usage by Resource:") + " "));
  1356. vmlb->set_h_size_flags(SIZE_EXPAND_FILL);
  1357. vmem_hb->add_child(vmlb);
  1358. vmem_hb->add_child(memnew(Label(TTR("Total:") + " ")));
  1359. vmem_total = memnew(LineEdit);
  1360. vmem_total->set_editable(false);
  1361. vmem_total->set_custom_minimum_size(Size2(100, 0) * EDSCALE);
  1362. vmem_hb->add_child(vmem_total);
  1363. vmem_refresh = memnew(ToolButton);
  1364. vmem_hb->add_child(vmem_refresh);
  1365. vmem_vb->add_child(vmem_hb);
  1366. vmem_refresh->connect("pressed", callable_mp(this, &ScriptEditorDebugger::_video_mem_request));
  1367. VBoxContainer *vmmc = memnew(VBoxContainer);
  1368. vmem_tree = memnew(Tree);
  1369. vmem_tree->set_v_size_flags(SIZE_EXPAND_FILL);
  1370. vmem_tree->set_h_size_flags(SIZE_EXPAND_FILL);
  1371. vmmc->add_child(vmem_tree);
  1372. vmmc->set_v_size_flags(SIZE_EXPAND_FILL);
  1373. vmem_vb->add_child(vmmc);
  1374. vmem_vb->set_name(TTR("Video RAM"));
  1375. vmem_tree->set_columns(4);
  1376. vmem_tree->set_column_titles_visible(true);
  1377. vmem_tree->set_column_title(0, TTR("Resource Path"));
  1378. vmem_tree->set_column_expand(0, true);
  1379. vmem_tree->set_column_expand(1, false);
  1380. vmem_tree->set_column_title(1, TTR("Type"));
  1381. vmem_tree->set_column_min_width(1, 100 * EDSCALE);
  1382. vmem_tree->set_column_expand(2, false);
  1383. vmem_tree->set_column_title(2, TTR("Format"));
  1384. vmem_tree->set_column_min_width(2, 150 * EDSCALE);
  1385. vmem_tree->set_column_expand(3, false);
  1386. vmem_tree->set_column_title(3, TTR("Usage"));
  1387. vmem_tree->set_column_min_width(3, 80 * EDSCALE);
  1388. vmem_tree->set_hide_root(true);
  1389. tabs->add_child(vmem_vb);
  1390. }
  1391. { // misc
  1392. VBoxContainer *misc = memnew(VBoxContainer);
  1393. misc->set_name(TTR("Misc"));
  1394. tabs->add_child(misc);
  1395. GridContainer *info_left = memnew(GridContainer);
  1396. info_left->set_columns(2);
  1397. misc->add_child(info_left);
  1398. clicked_ctrl = memnew(LineEdit);
  1399. clicked_ctrl->set_h_size_flags(SIZE_EXPAND_FILL);
  1400. info_left->add_child(memnew(Label(TTR("Clicked Control:"))));
  1401. info_left->add_child(clicked_ctrl);
  1402. clicked_ctrl_type = memnew(LineEdit);
  1403. info_left->add_child(memnew(Label(TTR("Clicked Control Type:"))));
  1404. info_left->add_child(clicked_ctrl_type);
  1405. scene_tree = memnew(SceneDebuggerTree);
  1406. live_edit_root = memnew(LineEdit);
  1407. live_edit_root->set_h_size_flags(SIZE_EXPAND_FILL);
  1408. {
  1409. HBoxContainer *lehb = memnew(HBoxContainer);
  1410. Label *l = memnew(Label(TTR("Live Edit Root:")));
  1411. info_left->add_child(l);
  1412. lehb->add_child(live_edit_root);
  1413. le_set = memnew(Button(TTR("Set From Tree")));
  1414. lehb->add_child(le_set);
  1415. le_clear = memnew(Button(TTR("Clear")));
  1416. lehb->add_child(le_clear);
  1417. info_left->add_child(lehb);
  1418. }
  1419. misc->add_child(memnew(VSeparator));
  1420. HBoxContainer *buttons = memnew(HBoxContainer);
  1421. export_csv = memnew(Button(TTR("Export measures as CSV")));
  1422. export_csv->connect("pressed", callable_mp(this, &ScriptEditorDebugger::_export_csv));
  1423. buttons->add_child(export_csv);
  1424. misc->add_child(buttons);
  1425. }
  1426. msgdialog = memnew(AcceptDialog);
  1427. add_child(msgdialog);
  1428. live_debug = true;
  1429. camera_override = CameraOverride::OVERRIDE_NONE;
  1430. last_path_id = false;
  1431. error_count = 0;
  1432. warning_count = 0;
  1433. _update_buttons_state();
  1434. }
  1435. ScriptEditorDebugger::~ScriptEditorDebugger() {
  1436. if (peer.is_valid()) {
  1437. peer->close();
  1438. peer.unref();
  1439. }
  1440. memdelete(scene_tree);
  1441. }