script_editor_debugger.cpp 71 KB

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