script_editor_debugger.cpp 54 KB

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