script_editor_debugger.cpp 72 KB

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