script_editor_debugger.cpp 70 KB

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