script_editor_debugger.cpp 54 KB

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