script_editor_debugger.cpp 55 KB

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