script_editor_debugger.cpp 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475
  1. /*************************************************************************/
  2. /* script_editor_debugger.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "script_editor_debugger.h"
  31. #include "core/io/marshalls.h"
  32. #include "core/project_settings.h"
  33. #include "core/ustring.h"
  34. #include "editor_network_profiler.h"
  35. #include "editor_node.h"
  36. #include "editor_profiler.h"
  37. #include "editor_settings.h"
  38. #include "main/performance.h"
  39. #include "property_editor.h"
  40. #include "scene/gui/dialogs.h"
  41. #include "scene/gui/label.h"
  42. #include "scene/gui/line_edit.h"
  43. #include "scene/gui/margin_container.h"
  44. #include "scene/gui/rich_text_label.h"
  45. #include "scene/gui/separator.h"
  46. #include "scene/gui/split_container.h"
  47. #include "scene/gui/tab_container.h"
  48. #include "scene/gui/texture_button.h"
  49. #include "scene/gui/tree.h"
  50. #include "scene/resources/packed_scene.h"
  51. class ScriptEditorDebuggerVariables : public Object {
  52. GDCLASS(ScriptEditorDebuggerVariables, Object);
  53. List<PropertyInfo> props;
  54. Map<StringName, Variant> values;
  55. protected:
  56. bool _set(const StringName &p_name, const Variant &p_value) {
  57. return false;
  58. }
  59. bool _get(const StringName &p_name, Variant &r_ret) const {
  60. if (!values.has(p_name))
  61. return false;
  62. r_ret = values[p_name];
  63. return true;
  64. }
  65. void _get_property_list(List<PropertyInfo> *p_list) const {
  66. for (const List<PropertyInfo>::Element *E = props.front(); E; E = E->next())
  67. p_list->push_back(E->get());
  68. }
  69. public:
  70. void clear() {
  71. props.clear();
  72. values.clear();
  73. }
  74. String get_var_value(const String &p_var) const {
  75. for (Map<StringName, Variant>::Element *E = values.front(); E; E = E->next()) {
  76. String v = E->key().operator String().get_slice("/", 1);
  77. if (v == p_var)
  78. return E->get();
  79. }
  80. return "";
  81. }
  82. void add_property(const String &p_name, const Variant &p_value, const PropertyHint &p_hint, const String p_hint_string) {
  83. PropertyInfo pinfo;
  84. pinfo.name = p_name;
  85. pinfo.type = p_value.get_type();
  86. pinfo.hint = p_hint;
  87. pinfo.hint_string = p_hint_string;
  88. props.push_back(pinfo);
  89. values[p_name] = p_value;
  90. }
  91. void update() {
  92. _change_notify();
  93. }
  94. ScriptEditorDebuggerVariables() {
  95. }
  96. };
  97. class ScriptEditorDebuggerInspectedObject : public Object {
  98. GDCLASS(ScriptEditorDebuggerInspectedObject, Object);
  99. protected:
  100. bool _set(const StringName &p_name, const Variant &p_value) {
  101. if (!prop_values.has(p_name) || String(p_name).begins_with("Constants/"))
  102. return false;
  103. prop_values[p_name] = p_value;
  104. emit_signal("value_edited", p_name, p_value);
  105. return true;
  106. }
  107. bool _get(const StringName &p_name, Variant &r_ret) const {
  108. if (!prop_values.has(p_name))
  109. return false;
  110. r_ret = prop_values[p_name];
  111. return true;
  112. }
  113. void _get_property_list(List<PropertyInfo> *p_list) const {
  114. p_list->clear(); //sorry, no want category
  115. for (const List<PropertyInfo>::Element *E = prop_list.front(); E; E = E->next()) {
  116. p_list->push_back(E->get());
  117. }
  118. }
  119. static void _bind_methods() {
  120. ClassDB::bind_method(D_METHOD("get_title"), &ScriptEditorDebuggerInspectedObject::get_title);
  121. ClassDB::bind_method(D_METHOD("get_variant"), &ScriptEditorDebuggerInspectedObject::get_variant);
  122. ClassDB::bind_method(D_METHOD("clear"), &ScriptEditorDebuggerInspectedObject::clear);
  123. ClassDB::bind_method(D_METHOD("get_remote_object_id"), &ScriptEditorDebuggerInspectedObject::get_remote_object_id);
  124. ADD_SIGNAL(MethodInfo("value_edited"));
  125. }
  126. public:
  127. String type_name;
  128. ObjectID remote_object_id;
  129. List<PropertyInfo> prop_list;
  130. Map<StringName, Variant> prop_values;
  131. ObjectID get_remote_object_id() {
  132. return remote_object_id;
  133. }
  134. String get_title() {
  135. if (remote_object_id)
  136. return TTR("Remote ") + String(type_name) + ": " + itos(remote_object_id);
  137. else
  138. return "<null>";
  139. }
  140. Variant get_variant(const StringName &p_name) {
  141. Variant var;
  142. _get(p_name, var);
  143. return var;
  144. }
  145. void clear() {
  146. prop_list.clear();
  147. prop_values.clear();
  148. }
  149. void update() {
  150. _change_notify();
  151. }
  152. void update_single(const char *p_prop) {
  153. _change_notify(p_prop);
  154. }
  155. ScriptEditorDebuggerInspectedObject() {
  156. remote_object_id = 0;
  157. }
  158. };
  159. void ScriptEditorDebugger::debug_copy() {
  160. String msg = reason->get_text();
  161. if (msg == "") return;
  162. OS::get_singleton()->set_clipboard(msg);
  163. }
  164. void ScriptEditorDebugger::debug_skip_breakpoints() {
  165. skip_breakpoints_value = !skip_breakpoints_value;
  166. if (skip_breakpoints_value)
  167. skip_breakpoints->set_icon(get_icon("DebugSkipBreakpointsOn", "EditorIcons"));
  168. else
  169. skip_breakpoints->set_icon(get_icon("DebugSkipBreakpointsOff", "EditorIcons"));
  170. if (connection.is_valid()) {
  171. Array msg;
  172. msg.push_back("set_skip_breakpoints");
  173. msg.push_back(skip_breakpoints_value);
  174. ppeer->put_var(msg);
  175. }
  176. }
  177. void ScriptEditorDebugger::debug_next() {
  178. ERR_FAIL_COND(!breaked);
  179. ERR_FAIL_COND(connection.is_null());
  180. ERR_FAIL_COND(!connection->is_connected_to_host());
  181. Array msg;
  182. msg.push_back("next");
  183. ppeer->put_var(msg);
  184. _clear_execution();
  185. stack_dump->clear();
  186. }
  187. void ScriptEditorDebugger::debug_step() {
  188. ERR_FAIL_COND(!breaked);
  189. ERR_FAIL_COND(connection.is_null());
  190. ERR_FAIL_COND(!connection->is_connected_to_host());
  191. Array msg;
  192. msg.push_back("step");
  193. ppeer->put_var(msg);
  194. _clear_execution();
  195. stack_dump->clear();
  196. }
  197. void ScriptEditorDebugger::debug_break() {
  198. ERR_FAIL_COND(breaked);
  199. ERR_FAIL_COND(connection.is_null());
  200. ERR_FAIL_COND(!connection->is_connected_to_host());
  201. Array msg;
  202. msg.push_back("break");
  203. ppeer->put_var(msg);
  204. }
  205. void ScriptEditorDebugger::debug_continue() {
  206. ERR_FAIL_COND(!breaked);
  207. ERR_FAIL_COND(connection.is_null());
  208. ERR_FAIL_COND(!connection->is_connected_to_host());
  209. OS::get_singleton()->enable_for_stealing_focus(EditorNode::get_singleton()->get_child_process_id());
  210. Array msg;
  211. _clear_execution();
  212. msg.push_back("continue");
  213. ppeer->put_var(msg);
  214. }
  215. void ScriptEditorDebugger::_scene_tree_folded(Object *obj) {
  216. if (updating_scene_tree) {
  217. return;
  218. }
  219. TreeItem *item = Object::cast_to<TreeItem>(obj);
  220. if (!item)
  221. return;
  222. ObjectID id = item->get_metadata(0);
  223. if (unfold_cache.has(id)) {
  224. unfold_cache.erase(id);
  225. } else {
  226. unfold_cache.insert(id);
  227. }
  228. }
  229. void ScriptEditorDebugger::_scene_tree_selected() {
  230. if (updating_scene_tree) {
  231. return;
  232. }
  233. TreeItem *item = inspect_scene_tree->get_selected();
  234. if (!item) {
  235. return;
  236. }
  237. inspected_object_id = item->get_metadata(0);
  238. Array msg;
  239. msg.push_back("inspect_object");
  240. msg.push_back(inspected_object_id);
  241. ppeer->put_var(msg);
  242. }
  243. void ScriptEditorDebugger::_scene_tree_rmb_selected(const Vector2 &p_position) {
  244. TreeItem *item = inspect_scene_tree->get_item_at_position(p_position);
  245. if (!item)
  246. return;
  247. item->select(0);
  248. item_menu->clear();
  249. item_menu->add_icon_item(get_icon("CreateNewSceneFrom", "EditorIcons"), TTR("Save Branch as Scene"), ITEM_MENU_SAVE_REMOTE_NODE);
  250. item_menu->add_icon_item(get_icon("CopyNodePath", "EditorIcons"), TTR("Copy Node Path"), ITEM_MENU_COPY_NODE_PATH);
  251. item_menu->set_global_position(get_global_mouse_position());
  252. item_menu->popup();
  253. }
  254. void ScriptEditorDebugger::_file_selected(const String &p_file) {
  255. switch (file_dialog_mode) {
  256. case SAVE_NODE: {
  257. Array msg;
  258. msg.push_back("save_node");
  259. msg.push_back(inspected_object_id);
  260. msg.push_back(p_file);
  261. ppeer->put_var(msg);
  262. } break;
  263. case SAVE_CSV: {
  264. Error err;
  265. FileAccessRef file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  266. if (err != OK) {
  267. ERR_PRINTS("Failed to open " + p_file);
  268. return;
  269. }
  270. Vector<String> line;
  271. line.resize(Performance::MONITOR_MAX);
  272. // signatures
  273. for (int i = 0; i < Performance::MONITOR_MAX; i++) {
  274. line.write[i] = Performance::get_singleton()->get_monitor_name(Performance::Monitor(i));
  275. }
  276. file->store_csv_line(line);
  277. // values
  278. List<Vector<float> >::Element *E = perf_history.back();
  279. while (E) {
  280. Vector<float> &perf_data = E->get();
  281. for (int i = 0; i < perf_data.size(); i++) {
  282. line.write[i] = String::num_real(perf_data[i]);
  283. }
  284. file->store_csv_line(line);
  285. E = E->prev();
  286. }
  287. file->store_string("\n");
  288. Vector<Vector<String> > profiler_data = profiler->get_data_as_csv();
  289. for (int i = 0; i < profiler_data.size(); i++) {
  290. file->store_csv_line(profiler_data[i]);
  291. }
  292. } break;
  293. }
  294. }
  295. void ScriptEditorDebugger::_scene_tree_property_value_edited(const String &p_prop, const Variant &p_value) {
  296. Array msg;
  297. msg.push_back("set_object_property");
  298. msg.push_back(inspected_object_id);
  299. msg.push_back(p_prop);
  300. msg.push_back(p_value);
  301. ppeer->put_var(msg);
  302. inspect_edited_object_timeout = 0.7; //avoid annoyance, don't request soon after editing
  303. }
  304. void ScriptEditorDebugger::_scene_tree_property_select_object(ObjectID p_object) {
  305. inspected_object_id = p_object;
  306. Array msg;
  307. msg.push_back("inspect_object");
  308. msg.push_back(inspected_object_id);
  309. ppeer->put_var(msg);
  310. }
  311. void ScriptEditorDebugger::_scene_tree_request() {
  312. ERR_FAIL_COND(connection.is_null());
  313. ERR_FAIL_COND(!connection->is_connected_to_host());
  314. Array msg;
  315. msg.push_back("request_scene_tree");
  316. ppeer->put_var(msg);
  317. }
  318. /// Populates inspect_scene_tree recursively given data in nodes.
  319. /// Nodes is an array containing 4 elements for each node, it follows this pattern:
  320. /// nodes[i] == number of direct children of this node
  321. /// nodes[i + 1] == node name
  322. /// nodes[i + 2] == node class
  323. /// nodes[i + 3] == node instance id
  324. ///
  325. /// Returns the number of items parsed in nodes from current_index.
  326. ///
  327. /// Given a nodes array like [R,A,B,C,D,E] the following Tree will be generated, assuming
  328. /// filter is an empty String, R and A child count are 2, B is 1 and C, D and E are 0.
  329. ///
  330. /// R
  331. /// |-A
  332. /// | |-B
  333. /// | | |-C
  334. /// | |
  335. /// | |-D
  336. /// |
  337. /// |-E
  338. ///
  339. int ScriptEditorDebugger::_update_scene_tree(TreeItem *parent, const Array &nodes, int current_index) {
  340. String filter = EditorNode::get_singleton()->get_scene_tree_dock()->get_filter();
  341. String item_text = nodes[current_index + 1];
  342. bool keep = filter.is_subsequence_ofi(item_text);
  343. TreeItem *item = inspect_scene_tree->create_item(parent);
  344. item->set_text(0, item_text);
  345. ObjectID id = ObjectID(nodes[current_index + 3]);
  346. Ref<Texture> icon = EditorNode::get_singleton()->get_class_icon(nodes[current_index + 2], "");
  347. if (icon.is_valid()) {
  348. item->set_icon(0, icon);
  349. }
  350. item->set_metadata(0, id);
  351. if (id == inspected_object_id) {
  352. TreeItem *cti = item->get_parent();
  353. while (cti) {
  354. cti->set_collapsed(false);
  355. cti = cti->get_parent();
  356. }
  357. item->select(0);
  358. }
  359. // Set current item as collapsed if necessary
  360. if (parent) {
  361. if (!unfold_cache.has(id)) {
  362. item->set_collapsed(true);
  363. }
  364. }
  365. int children_count = nodes[current_index];
  366. // Tracks the total number of items parsed in nodes, this is used to skips nodes that
  367. // are not direct children of the current node since we can't know in advance the total
  368. // number of children, direct and not, of a node without traversing the nodes array previously.
  369. // Keeping track of this allows us to build our remote scene tree by traversing the node
  370. // array just once.
  371. int items_count = 1;
  372. for (int i = 0; i < children_count; i++) {
  373. // Called for each direct child of item.
  374. // Direct children of current item might not be adjacent so items_count must
  375. // be incremented by the number of items parsed until now, otherwise we would not
  376. // be able to access the next child of the current item.
  377. // items_count is multiplied by 4 since that's the number of elements in the nodes
  378. // array needed to represent a single node.
  379. items_count += _update_scene_tree(item, nodes, current_index + items_count * 4);
  380. }
  381. // If item has not children and should not be kept delete it
  382. if (!keep && !item->get_children() && parent) {
  383. parent->remove_child(item);
  384. memdelete(item);
  385. }
  386. return items_count;
  387. }
  388. void ScriptEditorDebugger::_video_mem_request() {
  389. ERR_FAIL_COND(connection.is_null());
  390. ERR_FAIL_COND(!connection->is_connected_to_host());
  391. Array msg;
  392. msg.push_back("request_video_mem");
  393. ppeer->put_var(msg);
  394. }
  395. Size2 ScriptEditorDebugger::get_minimum_size() const {
  396. Size2 ms = Control::get_minimum_size();
  397. ms.y = MAX(ms.y, 250 * EDSCALE);
  398. return ms;
  399. }
  400. void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_data) {
  401. if (p_msg == "debug_enter") {
  402. Array msg;
  403. msg.push_back("get_stack_dump");
  404. ppeer->put_var(msg);
  405. ERR_FAIL_COND(p_data.size() != 2);
  406. bool can_continue = p_data[0];
  407. String error = p_data[1];
  408. step->set_disabled(!can_continue);
  409. next->set_disabled(!can_continue);
  410. _set_reason_text(error, MESSAGE_ERROR);
  411. copy->set_disabled(false);
  412. breaked = true;
  413. dobreak->set_disabled(true);
  414. docontinue->set_disabled(false);
  415. emit_signal("breaked", true, can_continue);
  416. OS::get_singleton()->move_window_to_foreground();
  417. if (error != "") {
  418. tabs->set_current_tab(0);
  419. }
  420. profiler->set_enabled(false);
  421. EditorNode::get_singleton()->get_pause_button()->set_pressed(true);
  422. EditorNode::get_singleton()->make_bottom_panel_item_visible(this);
  423. _clear_remote_objects();
  424. } else if (p_msg == "debug_exit") {
  425. breaked = false;
  426. _clear_execution();
  427. copy->set_disabled(true);
  428. step->set_disabled(true);
  429. next->set_disabled(true);
  430. reason->set_text("");
  431. reason->set_tooltip("");
  432. back->set_disabled(true);
  433. forward->set_disabled(true);
  434. dobreak->set_disabled(false);
  435. docontinue->set_disabled(true);
  436. emit_signal("breaked", false, false, Variant());
  437. profiler->set_enabled(true);
  438. profiler->disable_seeking();
  439. EditorNode::get_singleton()->get_pause_button()->set_pressed(false);
  440. } else if (p_msg == "message:click_ctrl") {
  441. clicked_ctrl->set_text(p_data[0]);
  442. clicked_ctrl_type->set_text(p_data[1]);
  443. } else if (p_msg == "message:scene_tree") {
  444. inspect_scene_tree->clear();
  445. Map<int, TreeItem *> lv;
  446. updating_scene_tree = true;
  447. _update_scene_tree(NULL, p_data, 0);
  448. updating_scene_tree = false;
  449. le_clear->set_disabled(false);
  450. le_set->set_disabled(false);
  451. } else if (p_msg == "message:inspect_object") {
  452. ScriptEditorDebuggerInspectedObject *debugObj = NULL;
  453. ObjectID id = p_data[0];
  454. String type = p_data[1];
  455. Array properties = p_data[2];
  456. if (remote_objects.has(id)) {
  457. debugObj = remote_objects[id];
  458. } else {
  459. debugObj = memnew(ScriptEditorDebuggerInspectedObject);
  460. debugObj->remote_object_id = id;
  461. debugObj->type_name = type;
  462. remote_objects[id] = debugObj;
  463. debugObj->connect("value_edited", this, "_scene_tree_property_value_edited");
  464. }
  465. int old_prop_size = debugObj->prop_list.size();
  466. debugObj->prop_list.clear();
  467. int new_props_added = 0;
  468. Set<String> changed;
  469. for (int i = 0; i < properties.size(); i++) {
  470. Array prop = properties[i];
  471. if (prop.size() != 6)
  472. continue;
  473. PropertyInfo pinfo;
  474. pinfo.name = prop[0];
  475. pinfo.type = Variant::Type(int(prop[1]));
  476. pinfo.hint = PropertyHint(int(prop[2]));
  477. pinfo.hint_string = prop[3];
  478. pinfo.usage = PropertyUsageFlags(int(prop[4]));
  479. Variant var = prop[5];
  480. if (pinfo.type == Variant::OBJECT) {
  481. if (var.is_zero()) {
  482. var = RES();
  483. } else if (var.get_type() == Variant::STRING) {
  484. var = ResourceLoader::load(var);
  485. if (pinfo.hint_string == "Script")
  486. debugObj->set_script(var);
  487. } else if (var.get_type() == Variant::OBJECT) {
  488. if (((Object *)var)->is_class("EncodedObjectAsID")) {
  489. var = Object::cast_to<EncodedObjectAsID>(var)->get_object_id();
  490. pinfo.type = var.get_type();
  491. pinfo.hint = PROPERTY_HINT_OBJECT_ID;
  492. pinfo.hint_string = "Object";
  493. }
  494. }
  495. }
  496. //always add the property, since props may have been added or removed
  497. debugObj->prop_list.push_back(pinfo);
  498. if (!debugObj->prop_values.has(pinfo.name)) {
  499. new_props_added++;
  500. debugObj->prop_values[pinfo.name] = var;
  501. } else {
  502. if (bool(Variant::evaluate(Variant::OP_NOT_EQUAL, debugObj->prop_values[pinfo.name], var))) {
  503. debugObj->prop_values[pinfo.name] = var;
  504. changed.insert(pinfo.name);
  505. }
  506. }
  507. }
  508. if (editor->get_editor_history()->get_current() != debugObj->get_instance_id()) {
  509. editor->push_item(debugObj, "");
  510. } else {
  511. if (old_prop_size == debugObj->prop_list.size() && new_props_added == 0) {
  512. //only some may have changed, if so, then update those, if exist
  513. for (Set<String>::Element *E = changed.front(); E; E = E->next()) {
  514. EditorNode::get_singleton()->get_inspector()->update_property(E->get());
  515. }
  516. } else {
  517. //full update, because props were added or removed
  518. debugObj->update();
  519. }
  520. }
  521. } else if (p_msg == "message:video_mem") {
  522. vmem_tree->clear();
  523. TreeItem *root = vmem_tree->create_item();
  524. int total = 0;
  525. for (int i = 0; i < p_data.size(); i += 4) {
  526. TreeItem *it = vmem_tree->create_item(root);
  527. String type = p_data[i + 1];
  528. int bytes = p_data[i + 3].operator int();
  529. it->set_text(0, p_data[i + 0]); //path
  530. it->set_text(1, type); //type
  531. it->set_text(2, p_data[i + 2]); //type
  532. it->set_text(3, String::humanize_size(bytes)); //type
  533. total += bytes;
  534. if (has_icon(type, "EditorIcons"))
  535. it->set_icon(0, get_icon(type, "EditorIcons"));
  536. }
  537. vmem_total->set_tooltip(TTR("Bytes:") + " " + itos(total));
  538. vmem_total->set_text(String::humanize_size(total));
  539. } else if (p_msg == "stack_dump") {
  540. stack_dump->clear();
  541. TreeItem *r = stack_dump->create_item();
  542. for (int i = 0; i < p_data.size(); i++) {
  543. Dictionary d = p_data[i];
  544. ERR_CONTINUE(!d.has("function"));
  545. ERR_CONTINUE(!d.has("file"));
  546. ERR_CONTINUE(!d.has("line"));
  547. ERR_CONTINUE(!d.has("id"));
  548. TreeItem *s = stack_dump->create_item(r);
  549. d["frame"] = i;
  550. s->set_metadata(0, d);
  551. String line = itos(i) + " - " + String(d["file"]) + ":" + itos(d["line"]) + " - at function: " + d["function"];
  552. s->set_text(0, line);
  553. if (i == 0)
  554. s->select(0);
  555. }
  556. } else if (p_msg == "stack_frame_vars") {
  557. variables->clear();
  558. int ofs = 0;
  559. int mcount = p_data[ofs];
  560. ofs++;
  561. for (int i = 0; i < mcount; i++) {
  562. String n = p_data[ofs + i * 2 + 0];
  563. Variant v = p_data[ofs + i * 2 + 1];
  564. PropertyHint h = PROPERTY_HINT_NONE;
  565. String hs = String();
  566. if (v.get_type() == Variant::OBJECT) {
  567. v = Object::cast_to<EncodedObjectAsID>(v)->get_object_id();
  568. h = PROPERTY_HINT_OBJECT_ID;
  569. hs = "Object";
  570. }
  571. variables->add_property("Locals/" + n, v, h, hs);
  572. }
  573. ofs += mcount * 2;
  574. mcount = p_data[ofs];
  575. ofs++;
  576. for (int i = 0; i < mcount; i++) {
  577. String n = p_data[ofs + i * 2 + 0];
  578. Variant v = p_data[ofs + i * 2 + 1];
  579. PropertyHint h = PROPERTY_HINT_NONE;
  580. String hs = String();
  581. if (v.get_type() == Variant::OBJECT) {
  582. v = Object::cast_to<EncodedObjectAsID>(v)->get_object_id();
  583. h = PROPERTY_HINT_OBJECT_ID;
  584. hs = "Object";
  585. }
  586. variables->add_property("Members/" + n, v, h, hs);
  587. }
  588. ofs += mcount * 2;
  589. mcount = p_data[ofs];
  590. ofs++;
  591. for (int i = 0; i < mcount; i++) {
  592. String n = p_data[ofs + i * 2 + 0];
  593. Variant v = p_data[ofs + i * 2 + 1];
  594. PropertyHint h = PROPERTY_HINT_NONE;
  595. String hs = String();
  596. if (v.get_type() == Variant::OBJECT) {
  597. v = Object::cast_to<EncodedObjectAsID>(v)->get_object_id();
  598. h = PROPERTY_HINT_OBJECT_ID;
  599. hs = "Object";
  600. }
  601. variables->add_property("Globals/" + n, v, h, hs);
  602. }
  603. variables->update();
  604. inspector->edit(variables);
  605. } else if (p_msg == "output") {
  606. //OUT
  607. for (int i = 0; i < p_data.size(); i++) {
  608. String t = p_data[i];
  609. //LOG
  610. if (!EditorNode::get_log()->is_visible()) {
  611. if (EditorNode::get_singleton()->are_bottom_panels_hidden()) {
  612. if (EDITOR_GET("run/output/always_open_output_on_play")) {
  613. EditorNode::get_singleton()->make_bottom_panel_item_visible(EditorNode::get_log());
  614. }
  615. }
  616. }
  617. EditorNode::get_log()->add_message(t);
  618. }
  619. } else if (p_msg == "performance") {
  620. Array arr = p_data[0];
  621. Vector<float> p;
  622. p.resize(arr.size());
  623. for (int i = 0; i < arr.size(); i++) {
  624. p.write[i] = arr[i];
  625. if (i < perf_items.size()) {
  626. float v = p[i];
  627. String vs = rtos(v);
  628. String tt = vs;
  629. switch (Performance::MonitorType((int)perf_items[i]->get_metadata(1))) {
  630. case Performance::MONITOR_TYPE_MEMORY: {
  631. vs = String::humanize_size(v);
  632. tt = vs;
  633. } break;
  634. case Performance::MONITOR_TYPE_TIME: {
  635. tt += " seconds";
  636. vs += " s";
  637. } break;
  638. default: {
  639. tt += " " + perf_items[i]->get_text(0);
  640. } break;
  641. }
  642. perf_items[i]->set_text(1, vs);
  643. perf_items[i]->set_tooltip(1, tt);
  644. if (p[i] > perf_max[i])
  645. perf_max.write[i] = p[i];
  646. }
  647. }
  648. perf_history.push_front(p);
  649. perf_draw->update();
  650. } else if (p_msg == "error") {
  651. Array err = p_data[0];
  652. Array vals;
  653. vals.push_back(err[0]);
  654. vals.push_back(err[1]);
  655. vals.push_back(err[2]);
  656. vals.push_back(err[3]);
  657. bool warning = err[9];
  658. bool e;
  659. String time = String("%d:%02d:%02d:%04d").sprintf(vals, &e);
  660. String txt = err[8].is_zero() ? String(err[7]) : String(err[8]);
  661. TreeItem *r = error_tree->get_root();
  662. if (!r) {
  663. r = error_tree->create_item();
  664. }
  665. TreeItem *error = error_tree->create_item(r);
  666. error->set_collapsed(true);
  667. error->set_icon(0, get_icon(warning ? "Warning" : "Error", "EditorIcons"));
  668. error->set_text(0, time);
  669. error->set_text_align(0, TreeItem::ALIGN_LEFT);
  670. error->set_text(1, txt);
  671. String source(err[5]);
  672. bool source_is_project_file = source.begins_with("res://");
  673. if (source_is_project_file)
  674. txt = source.get_file() + ":" + String(err[6]);
  675. else
  676. txt = source + ":" + String(err[6]);
  677. String method = err[4];
  678. if (method.length() > 0)
  679. txt += " @ " + method + "()";
  680. TreeItem *c_info = error_tree->create_item(error);
  681. c_info->set_text(0, "<" + TTR(source_is_project_file ? "Source" : "C Source") + ">");
  682. c_info->set_text(1, txt);
  683. c_info->set_text_align(0, TreeItem::ALIGN_LEFT);
  684. if (source_is_project_file) {
  685. Array meta;
  686. meta.push_back(source);
  687. meta.push_back(err[6]);
  688. error->set_metadata(0, meta);
  689. c_info->set_metadata(0, meta);
  690. }
  691. int scc = p_data[1];
  692. for (int i = 0; i < scc; i += 3) {
  693. String script = p_data[2 + i];
  694. String method2 = p_data[3 + i];
  695. int line = p_data[4 + i];
  696. TreeItem *stack_trace = error_tree->create_item(error);
  697. Array meta;
  698. meta.push_back(script);
  699. meta.push_back(line);
  700. stack_trace->set_metadata(0, meta);
  701. if (i == 0) {
  702. stack_trace->set_text(0, "<" + TTR("Stack Trace") + ">");
  703. stack_trace->set_text_align(0, TreeItem::ALIGN_LEFT);
  704. error->set_metadata(0, meta);
  705. }
  706. stack_trace->set_text(1, script.get_file() + ":" + itos(line) + " @ " + method2 + "()");
  707. }
  708. if (warning)
  709. warning_count++;
  710. else
  711. error_count++;
  712. } else if (p_msg == "profile_sig") {
  713. //cache a signature
  714. profiler_signature[p_data[1]] = p_data[0];
  715. } else if (p_msg == "profile_frame" || p_msg == "profile_total") {
  716. EditorProfiler::Metric metric;
  717. metric.valid = true;
  718. metric.frame_number = p_data[0];
  719. metric.frame_time = p_data[1];
  720. metric.idle_time = p_data[2];
  721. metric.physics_time = p_data[3];
  722. metric.physics_frame_time = p_data[4];
  723. int frame_data_amount = p_data[6];
  724. int frame_function_amount = p_data[7];
  725. if (frame_data_amount) {
  726. EditorProfiler::Metric::Category frame_time;
  727. frame_time.signature = "category_frame_time";
  728. frame_time.name = "Frame Time";
  729. frame_time.total_time = metric.frame_time;
  730. EditorProfiler::Metric::Category::Item item;
  731. item.calls = 1;
  732. item.line = 0;
  733. item.name = "Physics Time";
  734. item.total = metric.physics_time;
  735. item.self = item.total;
  736. item.signature = "physics_time";
  737. frame_time.items.push_back(item);
  738. item.name = "Idle Time";
  739. item.total = metric.idle_time;
  740. item.self = item.total;
  741. item.signature = "idle_time";
  742. frame_time.items.push_back(item);
  743. item.name = "Physics Frame Time";
  744. item.total = metric.physics_frame_time;
  745. item.self = item.total;
  746. item.signature = "physics_frame_time";
  747. frame_time.items.push_back(item);
  748. metric.categories.push_back(frame_time);
  749. }
  750. int idx = 8;
  751. for (int i = 0; i < frame_data_amount; i++) {
  752. EditorProfiler::Metric::Category c;
  753. String name = p_data[idx++];
  754. Array values = p_data[idx++];
  755. c.name = name.capitalize();
  756. c.items.resize(values.size() / 2);
  757. c.total_time = 0;
  758. c.signature = "categ::" + name;
  759. for (int j = 0; j < values.size(); j += 2) {
  760. EditorProfiler::Metric::Category::Item item;
  761. item.calls = 1;
  762. item.line = 0;
  763. item.name = values[j];
  764. item.self = values[j + 1];
  765. item.total = item.self;
  766. item.signature = "categ::" + name + "::" + item.name;
  767. item.name = item.name.capitalize();
  768. c.total_time += item.total;
  769. c.items.write[j / 2] = item;
  770. }
  771. metric.categories.push_back(c);
  772. }
  773. EditorProfiler::Metric::Category funcs;
  774. funcs.total_time = p_data[5]; //script time
  775. funcs.items.resize(frame_function_amount);
  776. funcs.name = "Script Functions";
  777. funcs.signature = "script_functions";
  778. for (int i = 0; i < frame_function_amount; i++) {
  779. int signature = p_data[idx++];
  780. int calls = p_data[idx++];
  781. float total = p_data[idx++];
  782. float self = p_data[idx++];
  783. EditorProfiler::Metric::Category::Item item;
  784. if (profiler_signature.has(signature)) {
  785. item.signature = profiler_signature[signature];
  786. String name = profiler_signature[signature];
  787. Vector<String> strings = name.split("::");
  788. if (strings.size() == 3) {
  789. item.name = strings[2];
  790. item.script = strings[0];
  791. item.line = strings[1].to_int();
  792. } else if (strings.size() == 4) { //Built-in scripts have an :: in their name
  793. item.name = strings[3];
  794. item.script = strings[0] + "::" + strings[1];
  795. item.line = strings[2].to_int();
  796. }
  797. } else {
  798. item.name = "SigErr " + itos(signature);
  799. }
  800. item.calls = calls;
  801. item.self = self;
  802. item.total = total;
  803. funcs.items.write[i] = item;
  804. }
  805. metric.categories.push_back(funcs);
  806. if (p_msg == "profile_frame")
  807. profiler->add_frame_metric(metric, false);
  808. else
  809. profiler->add_frame_metric(metric, true);
  810. } else if (p_msg == "network_profile") {
  811. int frame_size = 6;
  812. for (int i = 0; i < p_data.size(); i += frame_size) {
  813. MultiplayerAPI::ProfilingInfo pi;
  814. pi.node = p_data[i + 0];
  815. pi.node_path = p_data[i + 1];
  816. pi.incoming_rpc = p_data[i + 2];
  817. pi.incoming_rset = p_data[i + 3];
  818. pi.outgoing_rpc = p_data[i + 4];
  819. pi.outgoing_rset = p_data[i + 5];
  820. network_profiler->add_node_frame_data(pi);
  821. }
  822. } else if (p_msg == "network_bandwidth") {
  823. network_profiler->set_bandwidth(p_data[0], p_data[1]);
  824. } else if (p_msg == "kill_me") {
  825. editor->call_deferred("stop_child_process");
  826. }
  827. }
  828. void ScriptEditorDebugger::_set_reason_text(const String &p_reason, MessageType p_type) {
  829. switch (p_type) {
  830. case MESSAGE_ERROR:
  831. reason->add_color_override("font_color", get_color("error_color", "Editor"));
  832. break;
  833. case MESSAGE_WARNING:
  834. reason->add_color_override("font_color", get_color("warning_color", "Editor"));
  835. break;
  836. default:
  837. reason->add_color_override("font_color", get_color("success_color", "Editor"));
  838. }
  839. reason->set_text(p_reason);
  840. reason->set_tooltip(p_reason.word_wrap(80));
  841. }
  842. void ScriptEditorDebugger::_performance_select() {
  843. perf_draw->update();
  844. }
  845. void ScriptEditorDebugger::_performance_draw() {
  846. Vector<int> which;
  847. for (int i = 0; i < perf_items.size(); i++) {
  848. if (perf_items[i]->is_checked(0))
  849. which.push_back(i);
  850. }
  851. if (which.empty()) {
  852. info_message->show();
  853. return;
  854. }
  855. info_message->hide();
  856. Ref<StyleBox> graph_sb = get_stylebox("normal", "TextEdit");
  857. Ref<Font> graph_font = get_font("font", "TextEdit");
  858. int cols = Math::ceil(Math::sqrt((float)which.size()));
  859. int rows = Math::ceil((float)which.size() / cols);
  860. if (which.size() == 1)
  861. rows = 1;
  862. int margin = 3;
  863. int point_sep = 5;
  864. Size2i s = Size2i(perf_draw->get_size()) / Size2i(cols, rows);
  865. for (int i = 0; i < which.size(); i++) {
  866. Point2i p(i % cols, i / cols);
  867. Rect2i r(p * s, s);
  868. r.position += Point2(margin, margin);
  869. r.size -= Point2(margin, margin) * 2.0;
  870. perf_draw->draw_style_box(graph_sb, r);
  871. r.position += graph_sb->get_offset();
  872. r.size -= graph_sb->get_minimum_size();
  873. int pi = which[i];
  874. Color c = get_color("accent_color", "Editor");
  875. float h = (float)which[i] / (float)(perf_items.size());
  876. // Use a darker color on light backgrounds for better visibility
  877. float value_multiplier = EditorSettings::get_singleton()->is_dark_theme() ? 1.4 : 0.55;
  878. c.set_hsv(Math::fmod(h + 0.4, 0.9), c.get_s() * 0.9, c.get_v() * value_multiplier);
  879. c.a = 0.6;
  880. perf_draw->draw_string(graph_font, r.position + Point2(0, graph_font->get_ascent()), perf_items[pi]->get_text(0), c, r.size.x);
  881. c.a = 0.9;
  882. perf_draw->draw_string(graph_font, r.position + Point2(0, graph_font->get_ascent() + graph_font->get_height()), perf_items[pi]->get_text(1), c, r.size.y);
  883. float spacing = point_sep / float(cols);
  884. float from = r.size.width;
  885. List<Vector<float> >::Element *E = perf_history.front();
  886. float prev = -1;
  887. while (from >= 0 && E) {
  888. float m = perf_max[pi];
  889. if (m == 0)
  890. m = 0.00001;
  891. float h2 = E->get()[pi] / m;
  892. h2 = (1.0 - h2) * r.size.y;
  893. if (E != perf_history.front())
  894. perf_draw->draw_line(r.position + Point2(from, h2), r.position + Point2(from + spacing, prev), c, Math::round(EDSCALE), true);
  895. prev = h2;
  896. E = E->next();
  897. from -= spacing;
  898. }
  899. }
  900. }
  901. void ScriptEditorDebugger::_notification(int p_what) {
  902. switch (p_what) {
  903. case NOTIFICATION_ENTER_TREE: {
  904. inspector->edit(variables);
  905. skip_breakpoints->set_icon(get_icon("DebugSkipBreakpointsOff", "EditorIcons"));
  906. copy->set_icon(get_icon("ActionCopy", "EditorIcons"));
  907. step->set_icon(get_icon("DebugStep", "EditorIcons"));
  908. next->set_icon(get_icon("DebugNext", "EditorIcons"));
  909. back->set_icon(get_icon("Back", "EditorIcons"));
  910. forward->set_icon(get_icon("Forward", "EditorIcons"));
  911. dobreak->set_icon(get_icon("Pause", "EditorIcons"));
  912. docontinue->set_icon(get_icon("DebugContinue", "EditorIcons"));
  913. le_set->connect("pressed", this, "_live_edit_set");
  914. le_clear->connect("pressed", this, "_live_edit_clear");
  915. error_tree->connect("item_selected", this, "_error_selected");
  916. error_tree->connect("item_activated", this, "_error_activated");
  917. vmem_refresh->set_icon(get_icon("Reload", "EditorIcons"));
  918. reason->add_color_override("font_color", get_color("error_color", "Editor"));
  919. } break;
  920. case NOTIFICATION_PROCESS: {
  921. if (connection.is_valid()) {
  922. inspect_scene_tree_timeout -= get_process_delta_time();
  923. if (inspect_scene_tree_timeout < 0) {
  924. inspect_scene_tree_timeout = EditorSettings::get_singleton()->get("debugger/remote_scene_tree_refresh_interval");
  925. if (inspect_scene_tree->is_visible_in_tree()) {
  926. _scene_tree_request();
  927. }
  928. }
  929. inspect_edited_object_timeout -= get_process_delta_time();
  930. if (inspect_edited_object_timeout < 0) {
  931. inspect_edited_object_timeout = EditorSettings::get_singleton()->get("debugger/remote_inspect_refresh_interval");
  932. if (inspected_object_id) {
  933. if (ScriptEditorDebuggerInspectedObject *obj = Object::cast_to<ScriptEditorDebuggerInspectedObject>(ObjectDB::get_instance(editor->get_editor_history()->get_current()))) {
  934. if (obj->remote_object_id == inspected_object_id) {
  935. //take the chance and re-inspect selected object
  936. Array msg;
  937. msg.push_back("inspect_object");
  938. msg.push_back(inspected_object_id);
  939. ppeer->put_var(msg);
  940. }
  941. }
  942. }
  943. }
  944. }
  945. if (error_count != last_error_count || warning_count != last_warning_count) {
  946. if (error_count == 0 && warning_count == 0) {
  947. errors_tab->set_name(TTR("Errors"));
  948. debugger_button->set_text(TTR("Debugger"));
  949. debugger_button->set_icon(Ref<Texture>());
  950. tabs->set_tab_icon(errors_tab->get_index(), Ref<Texture>());
  951. } else {
  952. errors_tab->set_name(TTR("Errors") + " (" + itos(error_count + warning_count) + ")");
  953. debugger_button->set_text(TTR("Debugger") + " (" + itos(error_count + warning_count) + ")");
  954. if (error_count == 0) {
  955. debugger_button->set_icon(get_icon("Warning", "EditorIcons"));
  956. tabs->set_tab_icon(errors_tab->get_index(), get_icon("Warning", "EditorIcons"));
  957. } else {
  958. debugger_button->set_icon(get_icon("Error", "EditorIcons"));
  959. tabs->set_tab_icon(errors_tab->get_index(), get_icon("Error", "EditorIcons"));
  960. }
  961. }
  962. last_error_count = error_count;
  963. last_warning_count = warning_count;
  964. }
  965. if (server->is_connection_available()) {
  966. if (connection.is_valid()) {
  967. // We already have a valid connection. Disconnecting any new connecting client to prevent it from hanging.
  968. // (If we don't keep a reference to the connection it will be destroyed and disconnect_from_host will be called internally)
  969. server->take_connection();
  970. } else {
  971. // We just got the first connection.
  972. connection = server->take_connection();
  973. if (connection.is_null())
  974. break;
  975. EditorNode::get_log()->add_message("--- Debugging process started ---", EditorLog::MSG_TYPE_EDITOR);
  976. ppeer->set_stream_peer(connection);
  977. //EditorNode::get_singleton()->make_bottom_panel_item_visible(this);
  978. //emit_signal("show_debugger",true);
  979. dobreak->set_disabled(false);
  980. tabs->set_current_tab(0);
  981. _set_reason_text(TTR("Child process connected."), MESSAGE_SUCCESS);
  982. profiler->clear();
  983. inspect_scene_tree->clear();
  984. le_set->set_disabled(true);
  985. le_clear->set_disabled(false);
  986. error_tree->clear();
  987. error_count = 0;
  988. warning_count = 0;
  989. profiler_signature.clear();
  990. //live_edit_root->set_text("/root");
  991. EditorNode::get_singleton()->get_pause_button()->set_pressed(false);
  992. EditorNode::get_singleton()->get_pause_button()->set_disabled(false);
  993. update_live_edit_root();
  994. if (profiler->is_profiling()) {
  995. _profiler_activate(true);
  996. }
  997. if (network_profiler->is_profiling()) {
  998. _network_profiler_activate(true);
  999. }
  1000. }
  1001. }
  1002. if (connection.is_null())
  1003. break;
  1004. if (!connection->is_connected_to_host()) {
  1005. stop();
  1006. editor->notify_child_process_exited(); //somehow, exited
  1007. break;
  1008. };
  1009. if (ppeer->get_available_packet_count() <= 0) {
  1010. break;
  1011. };
  1012. const uint64_t until = OS::get_singleton()->get_ticks_msec() + 20;
  1013. while (ppeer->get_available_packet_count() > 0) {
  1014. if (pending_in_queue) {
  1015. int todo = MIN(ppeer->get_available_packet_count(), pending_in_queue);
  1016. for (int i = 0; i < todo; i++) {
  1017. Variant cmd;
  1018. Error ret = ppeer->get_var(cmd);
  1019. if (ret != OK) {
  1020. stop();
  1021. ERR_FAIL_COND(ret != OK);
  1022. }
  1023. message.push_back(cmd);
  1024. pending_in_queue--;
  1025. }
  1026. if (pending_in_queue == 0) {
  1027. _parse_message(message_type, message);
  1028. message.clear();
  1029. }
  1030. } else {
  1031. if (ppeer->get_available_packet_count() >= 2) {
  1032. Variant cmd;
  1033. Error ret = ppeer->get_var(cmd);
  1034. if (ret != OK) {
  1035. stop();
  1036. ERR_FAIL_COND(ret != OK);
  1037. }
  1038. if (cmd.get_type() != Variant::STRING) {
  1039. stop();
  1040. ERR_FAIL_COND(cmd.get_type() != Variant::STRING);
  1041. }
  1042. message_type = cmd;
  1043. ret = ppeer->get_var(cmd);
  1044. if (ret != OK) {
  1045. stop();
  1046. ERR_FAIL_COND(ret != OK);
  1047. }
  1048. if (cmd.get_type() != Variant::INT) {
  1049. stop();
  1050. ERR_FAIL_COND(cmd.get_type() != Variant::INT);
  1051. }
  1052. pending_in_queue = cmd;
  1053. if (pending_in_queue == 0) {
  1054. _parse_message(message_type, Array());
  1055. message.clear();
  1056. }
  1057. } else {
  1058. break;
  1059. }
  1060. }
  1061. if (OS::get_singleton()->get_ticks_msec() > until)
  1062. break;
  1063. }
  1064. } break;
  1065. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  1066. tabs->add_style_override("panel", editor->get_gui_base()->get_stylebox("DebuggerPanel", "EditorStyles"));
  1067. tabs->add_style_override("tab_fg", editor->get_gui_base()->get_stylebox("DebuggerTabFG", "EditorStyles"));
  1068. tabs->add_style_override("tab_bg", editor->get_gui_base()->get_stylebox("DebuggerTabBG", "EditorStyles"));
  1069. tabs->set_margin(MARGIN_LEFT, -EditorNode::get_singleton()->get_gui_base()->get_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_LEFT));
  1070. tabs->set_margin(MARGIN_RIGHT, EditorNode::get_singleton()->get_gui_base()->get_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_RIGHT));
  1071. copy->set_icon(get_icon("ActionCopy", "EditorIcons"));
  1072. step->set_icon(get_icon("DebugStep", "EditorIcons"));
  1073. next->set_icon(get_icon("DebugNext", "EditorIcons"));
  1074. back->set_icon(get_icon("Back", "EditorIcons"));
  1075. forward->set_icon(get_icon("Forward", "EditorIcons"));
  1076. dobreak->set_icon(get_icon("Pause", "EditorIcons"));
  1077. docontinue->set_icon(get_icon("DebugContinue", "EditorIcons"));
  1078. vmem_refresh->set_icon(get_icon("Reload", "EditorIcons"));
  1079. } break;
  1080. }
  1081. }
  1082. void ScriptEditorDebugger::_clear_execution() {
  1083. TreeItem *ti = stack_dump->get_selected();
  1084. if (!ti)
  1085. return;
  1086. Dictionary d = ti->get_metadata(0);
  1087. stack_script = ResourceLoader::load(d["file"]);
  1088. emit_signal("clear_execution", stack_script);
  1089. stack_script.unref();
  1090. }
  1091. void ScriptEditorDebugger::start() {
  1092. stop();
  1093. if (is_visible_in_tree()) {
  1094. EditorNode::get_singleton()->make_bottom_panel_item_visible(this);
  1095. }
  1096. perf_history.clear();
  1097. for (int i = 0; i < Performance::MONITOR_MAX; i++) {
  1098. perf_max.write[i] = 0;
  1099. }
  1100. int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port");
  1101. if (server->listen(remote_port) != OK) {
  1102. EditorNode::get_log()->add_message(String("Error listening on port ") + itos(remote_port), EditorLog::MSG_TYPE_ERROR);
  1103. return;
  1104. }
  1105. EditorNode::get_singleton()->get_scene_tree_dock()->show_tab_buttons();
  1106. auto_switch_remote_scene_tree = (bool)EditorSettings::get_singleton()->get("debugger/auto_switch_to_remote_scene_tree");
  1107. if (auto_switch_remote_scene_tree) {
  1108. EditorNode::get_singleton()->get_scene_tree_dock()->show_remote_tree();
  1109. }
  1110. set_process(true);
  1111. breaked = false;
  1112. }
  1113. void ScriptEditorDebugger::pause() {
  1114. }
  1115. void ScriptEditorDebugger::unpause() {
  1116. }
  1117. void ScriptEditorDebugger::stop() {
  1118. set_process(false);
  1119. breaked = false;
  1120. _clear_execution();
  1121. server->stop();
  1122. _clear_remote_objects();
  1123. ppeer->set_stream_peer(Ref<StreamPeer>());
  1124. if (connection.is_valid()) {
  1125. EditorNode::get_log()->add_message("--- Debugging process stopped ---", EditorLog::MSG_TYPE_EDITOR);
  1126. connection.unref();
  1127. reason->set_text("");
  1128. reason->set_tooltip("");
  1129. }
  1130. pending_in_queue = 0;
  1131. message.clear();
  1132. node_path_cache.clear();
  1133. res_path_cache.clear();
  1134. profiler_signature.clear();
  1135. le_clear->set_disabled(false);
  1136. le_set->set_disabled(true);
  1137. profiler->set_enabled(true);
  1138. inspect_scene_tree->clear();
  1139. inspector->edit(NULL);
  1140. EditorNode::get_singleton()->get_pause_button()->set_pressed(false);
  1141. EditorNode::get_singleton()->get_pause_button()->set_disabled(true);
  1142. EditorNode::get_singleton()->get_scene_tree_dock()->hide_remote_tree();
  1143. EditorNode::get_singleton()->get_scene_tree_dock()->hide_tab_buttons();
  1144. if (hide_on_stop) {
  1145. if (is_visible_in_tree())
  1146. EditorNode::get_singleton()->hide_bottom_panel();
  1147. emit_signal("show_debugger", false);
  1148. }
  1149. }
  1150. void ScriptEditorDebugger::_profiler_activate(bool p_enable) {
  1151. if (!connection.is_valid())
  1152. return;
  1153. if (p_enable) {
  1154. profiler_signature.clear();
  1155. Array msg;
  1156. msg.push_back("start_profiling");
  1157. int max_funcs = EditorSettings::get_singleton()->get("debugger/profiler_frame_max_functions");
  1158. max_funcs = CLAMP(max_funcs, 16, 512);
  1159. msg.push_back(max_funcs);
  1160. ppeer->put_var(msg);
  1161. print_verbose("Starting profiling.");
  1162. } else {
  1163. Array msg;
  1164. msg.push_back("stop_profiling");
  1165. ppeer->put_var(msg);
  1166. print_verbose("Ending profiling.");
  1167. }
  1168. }
  1169. void ScriptEditorDebugger::_network_profiler_activate(bool p_enable) {
  1170. if (!connection.is_valid())
  1171. return;
  1172. if (p_enable) {
  1173. Array msg;
  1174. msg.push_back("start_network_profiling");
  1175. ppeer->put_var(msg);
  1176. print_verbose("Starting network profiling.");
  1177. } else {
  1178. Array msg;
  1179. msg.push_back("stop_network_profiling");
  1180. ppeer->put_var(msg);
  1181. print_verbose("Ending network profiling.");
  1182. }
  1183. }
  1184. void ScriptEditorDebugger::_profiler_seeked() {
  1185. if (!connection.is_valid() || !connection->is_connected_to_host())
  1186. return;
  1187. if (breaked)
  1188. return;
  1189. debug_break();
  1190. }
  1191. void ScriptEditorDebugger::_stack_dump_frame_selected() {
  1192. TreeItem *ti = stack_dump->get_selected();
  1193. if (!ti)
  1194. return;
  1195. Dictionary d = ti->get_metadata(0);
  1196. stack_script = ResourceLoader::load(d["file"]);
  1197. emit_signal("goto_script_line", stack_script, int(d["line"]) - 1);
  1198. emit_signal("set_execution", stack_script, int(d["line"]) - 1);
  1199. stack_script.unref();
  1200. if (connection.is_valid() && connection->is_connected_to_host()) {
  1201. Array msg;
  1202. msg.push_back("get_stack_frame_vars");
  1203. msg.push_back(d["frame"]);
  1204. ppeer->put_var(msg);
  1205. } else {
  1206. inspector->edit(NULL);
  1207. }
  1208. }
  1209. void ScriptEditorDebugger::_output_clear() {
  1210. //output->clear();
  1211. //output->push_color(Color(0,0,0));
  1212. }
  1213. void ScriptEditorDebugger::_export_csv() {
  1214. file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE);
  1215. file_dialog_mode = SAVE_CSV;
  1216. file_dialog->popup_centered_ratio();
  1217. }
  1218. String ScriptEditorDebugger::get_var_value(const String &p_var) const {
  1219. if (!breaked)
  1220. return String();
  1221. return variables->get_var_value(p_var);
  1222. }
  1223. int ScriptEditorDebugger::_get_node_path_cache(const NodePath &p_path) {
  1224. const int *r = node_path_cache.getptr(p_path);
  1225. if (r)
  1226. return *r;
  1227. last_path_id++;
  1228. node_path_cache[p_path] = last_path_id;
  1229. Array msg;
  1230. msg.push_back("live_node_path");
  1231. msg.push_back(p_path);
  1232. msg.push_back(last_path_id);
  1233. ppeer->put_var(msg);
  1234. return last_path_id;
  1235. }
  1236. int ScriptEditorDebugger::_get_res_path_cache(const String &p_path) {
  1237. Map<String, int>::Element *E = res_path_cache.find(p_path);
  1238. if (E)
  1239. return E->get();
  1240. last_path_id++;
  1241. res_path_cache[p_path] = last_path_id;
  1242. Array msg;
  1243. msg.push_back("live_res_path");
  1244. msg.push_back(p_path);
  1245. msg.push_back(last_path_id);
  1246. ppeer->put_var(msg);
  1247. return last_path_id;
  1248. }
  1249. void ScriptEditorDebugger::_method_changed(Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE) {
  1250. if (!p_base || !live_debug || !connection.is_valid() || !editor->get_edited_scene())
  1251. return;
  1252. Node *node = Object::cast_to<Node>(p_base);
  1253. VARIANT_ARGPTRS
  1254. for (int i = 0; i < VARIANT_ARG_MAX; i++) {
  1255. //no pointers, sorry
  1256. if (argptr[i] && (argptr[i]->get_type() == Variant::OBJECT || argptr[i]->get_type() == Variant::_RID))
  1257. return;
  1258. }
  1259. if (node) {
  1260. NodePath path = editor->get_edited_scene()->get_path_to(node);
  1261. int pathid = _get_node_path_cache(path);
  1262. Array msg;
  1263. msg.push_back("live_node_call");
  1264. msg.push_back(pathid);
  1265. msg.push_back(p_name);
  1266. for (int i = 0; i < VARIANT_ARG_MAX; i++) {
  1267. //no pointers, sorry
  1268. msg.push_back(*argptr[i]);
  1269. }
  1270. ppeer->put_var(msg);
  1271. return;
  1272. }
  1273. Resource *res = Object::cast_to<Resource>(p_base);
  1274. if (res && res->get_path() != String()) {
  1275. String respath = res->get_path();
  1276. int pathid = _get_res_path_cache(respath);
  1277. Array msg;
  1278. msg.push_back("live_res_call");
  1279. msg.push_back(pathid);
  1280. msg.push_back(p_name);
  1281. for (int i = 0; i < VARIANT_ARG_MAX; i++) {
  1282. //no pointers, sorry
  1283. msg.push_back(*argptr[i]);
  1284. }
  1285. ppeer->put_var(msg);
  1286. return;
  1287. }
  1288. }
  1289. void ScriptEditorDebugger::_property_changed(Object *p_base, const StringName &p_property, const Variant &p_value) {
  1290. if (!p_base || !live_debug || !connection.is_valid() || !editor->get_edited_scene())
  1291. return;
  1292. Node *node = Object::cast_to<Node>(p_base);
  1293. if (node) {
  1294. NodePath path = editor->get_edited_scene()->get_path_to(node);
  1295. int pathid = _get_node_path_cache(path);
  1296. if (p_value.is_ref()) {
  1297. Ref<Resource> res = p_value;
  1298. if (res.is_valid() && res->get_path() != String()) {
  1299. Array msg;
  1300. msg.push_back("live_node_prop_res");
  1301. msg.push_back(pathid);
  1302. msg.push_back(p_property);
  1303. msg.push_back(res->get_path());
  1304. ppeer->put_var(msg);
  1305. }
  1306. } else {
  1307. Array msg;
  1308. msg.push_back("live_node_prop");
  1309. msg.push_back(pathid);
  1310. msg.push_back(p_property);
  1311. msg.push_back(p_value);
  1312. ppeer->put_var(msg);
  1313. }
  1314. return;
  1315. }
  1316. Resource *res = Object::cast_to<Resource>(p_base);
  1317. if (res && res->get_path() != String()) {
  1318. String respath = res->get_path();
  1319. int pathid = _get_res_path_cache(respath);
  1320. if (p_value.is_ref()) {
  1321. Ref<Resource> res2 = p_value;
  1322. if (res2.is_valid() && res2->get_path() != String()) {
  1323. Array msg;
  1324. msg.push_back("live_res_prop_res");
  1325. msg.push_back(pathid);
  1326. msg.push_back(p_property);
  1327. msg.push_back(res2->get_path());
  1328. ppeer->put_var(msg);
  1329. }
  1330. } else {
  1331. Array msg;
  1332. msg.push_back("live_res_prop");
  1333. msg.push_back(pathid);
  1334. msg.push_back(p_property);
  1335. msg.push_back(p_value);
  1336. ppeer->put_var(msg);
  1337. }
  1338. return;
  1339. }
  1340. }
  1341. void ScriptEditorDebugger::_method_changeds(void *p_ud, Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE) {
  1342. ScriptEditorDebugger *sed = (ScriptEditorDebugger *)p_ud;
  1343. sed->_method_changed(p_base, p_name, VARIANT_ARG_PASS);
  1344. }
  1345. void ScriptEditorDebugger::_property_changeds(void *p_ud, Object *p_base, const StringName &p_property, const Variant &p_value) {
  1346. ScriptEditorDebugger *sed = (ScriptEditorDebugger *)p_ud;
  1347. sed->_property_changed(p_base, p_property, p_value);
  1348. }
  1349. void ScriptEditorDebugger::set_live_debugging(bool p_enable) {
  1350. live_debug = p_enable;
  1351. }
  1352. void ScriptEditorDebugger::_live_edit_set() {
  1353. if (!connection.is_valid())
  1354. return;
  1355. TreeItem *ti = inspect_scene_tree->get_selected();
  1356. if (!ti)
  1357. return;
  1358. String path;
  1359. while (ti) {
  1360. String lp = ti->get_text(0);
  1361. path = "/" + lp + path;
  1362. ti = ti->get_parent();
  1363. }
  1364. NodePath np = path;
  1365. editor->get_editor_data().set_edited_scene_live_edit_root(np);
  1366. update_live_edit_root();
  1367. }
  1368. void ScriptEditorDebugger::_live_edit_clear() {
  1369. NodePath np = NodePath("/root");
  1370. editor->get_editor_data().set_edited_scene_live_edit_root(np);
  1371. update_live_edit_root();
  1372. }
  1373. void ScriptEditorDebugger::update_live_edit_root() {
  1374. NodePath np = editor->get_editor_data().get_edited_scene_live_edit_root();
  1375. if (connection.is_valid()) {
  1376. Array msg;
  1377. msg.push_back("live_set_root");
  1378. msg.push_back(np);
  1379. if (editor->get_edited_scene())
  1380. msg.push_back(editor->get_edited_scene()->get_filename());
  1381. else
  1382. msg.push_back("");
  1383. ppeer->put_var(msg);
  1384. }
  1385. live_edit_root->set_text(np);
  1386. }
  1387. void ScriptEditorDebugger::live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name) {
  1388. if (live_debug && connection.is_valid()) {
  1389. Array msg;
  1390. msg.push_back("live_create_node");
  1391. msg.push_back(p_parent);
  1392. msg.push_back(p_type);
  1393. msg.push_back(p_name);
  1394. ppeer->put_var(msg);
  1395. }
  1396. }
  1397. void ScriptEditorDebugger::live_debug_instance_node(const NodePath &p_parent, const String &p_path, const String &p_name) {
  1398. if (live_debug && connection.is_valid()) {
  1399. Array msg;
  1400. msg.push_back("live_instance_node");
  1401. msg.push_back(p_parent);
  1402. msg.push_back(p_path);
  1403. msg.push_back(p_name);
  1404. ppeer->put_var(msg);
  1405. }
  1406. }
  1407. void ScriptEditorDebugger::live_debug_remove_node(const NodePath &p_at) {
  1408. if (live_debug && connection.is_valid()) {
  1409. Array msg;
  1410. msg.push_back("live_remove_node");
  1411. msg.push_back(p_at);
  1412. ppeer->put_var(msg);
  1413. }
  1414. }
  1415. void ScriptEditorDebugger::live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id) {
  1416. if (live_debug && connection.is_valid()) {
  1417. Array msg;
  1418. msg.push_back("live_remove_and_keep_node");
  1419. msg.push_back(p_at);
  1420. msg.push_back(p_keep_id);
  1421. ppeer->put_var(msg);
  1422. }
  1423. }
  1424. void ScriptEditorDebugger::live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos) {
  1425. if (live_debug && connection.is_valid()) {
  1426. Array msg;
  1427. msg.push_back("live_restore_node");
  1428. msg.push_back(p_id);
  1429. msg.push_back(p_at);
  1430. msg.push_back(p_at_pos);
  1431. ppeer->put_var(msg);
  1432. }
  1433. }
  1434. void ScriptEditorDebugger::live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name) {
  1435. if (live_debug && connection.is_valid()) {
  1436. Array msg;
  1437. msg.push_back("live_duplicate_node");
  1438. msg.push_back(p_at);
  1439. msg.push_back(p_new_name);
  1440. ppeer->put_var(msg);
  1441. }
  1442. }
  1443. void ScriptEditorDebugger::live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos) {
  1444. if (live_debug && connection.is_valid()) {
  1445. Array msg;
  1446. msg.push_back("live_reparent_node");
  1447. msg.push_back(p_at);
  1448. msg.push_back(p_new_place);
  1449. msg.push_back(p_new_name);
  1450. msg.push_back(p_at_pos);
  1451. ppeer->put_var(msg);
  1452. }
  1453. }
  1454. void ScriptEditorDebugger::set_breakpoint(const String &p_path, int p_line, bool p_enabled) {
  1455. if (connection.is_valid()) {
  1456. Array msg;
  1457. msg.push_back("breakpoint");
  1458. msg.push_back(p_path);
  1459. msg.push_back(p_line);
  1460. msg.push_back(p_enabled);
  1461. ppeer->put_var(msg);
  1462. }
  1463. }
  1464. void ScriptEditorDebugger::reload_scripts() {
  1465. if (connection.is_valid()) {
  1466. Array msg;
  1467. msg.push_back("reload_scripts");
  1468. ppeer->put_var(msg);
  1469. }
  1470. }
  1471. bool ScriptEditorDebugger::is_skip_breakpoints() {
  1472. return skip_breakpoints_value;
  1473. }
  1474. void ScriptEditorDebugger::_error_activated() {
  1475. TreeItem *selected = error_tree->get_selected();
  1476. TreeItem *ci = selected->get_children();
  1477. if (ci) {
  1478. selected->set_collapsed(!selected->is_collapsed());
  1479. }
  1480. }
  1481. void ScriptEditorDebugger::_error_selected() {
  1482. TreeItem *selected = error_tree->get_selected();
  1483. Array meta = selected->get_metadata(0);
  1484. if (meta.size() == 0) {
  1485. return;
  1486. }
  1487. Ref<Script> s = ResourceLoader::load(meta[0]);
  1488. emit_signal("goto_script_line", s, int(meta[1]) - 1);
  1489. }
  1490. void ScriptEditorDebugger::_expand_errors_list() {
  1491. TreeItem *root = error_tree->get_root();
  1492. if (!root)
  1493. return;
  1494. TreeItem *item = root->get_children();
  1495. while (item) {
  1496. item->set_collapsed(false);
  1497. item = item->get_next();
  1498. }
  1499. }
  1500. void ScriptEditorDebugger::_collapse_errors_list() {
  1501. TreeItem *root = error_tree->get_root();
  1502. if (!root)
  1503. return;
  1504. TreeItem *item = root->get_children();
  1505. while (item) {
  1506. item->set_collapsed(true);
  1507. item = item->get_next();
  1508. }
  1509. }
  1510. void ScriptEditorDebugger::set_hide_on_stop(bool p_hide) {
  1511. hide_on_stop = p_hide;
  1512. }
  1513. bool ScriptEditorDebugger::get_debug_with_external_editor() const {
  1514. return enable_external_editor;
  1515. }
  1516. void ScriptEditorDebugger::set_debug_with_external_editor(bool p_enabled) {
  1517. enable_external_editor = p_enabled;
  1518. }
  1519. Ref<Script> ScriptEditorDebugger::get_dump_stack_script() const {
  1520. return stack_script;
  1521. }
  1522. void ScriptEditorDebugger::_paused() {
  1523. ERR_FAIL_COND(connection.is_null());
  1524. ERR_FAIL_COND(!connection->is_connected_to_host());
  1525. if (!breaked && EditorNode::get_singleton()->get_pause_button()->is_pressed()) {
  1526. debug_break();
  1527. }
  1528. if (breaked && !EditorNode::get_singleton()->get_pause_button()->is_pressed()) {
  1529. debug_continue();
  1530. }
  1531. }
  1532. void ScriptEditorDebugger::_set_remote_object(ObjectID p_id, ScriptEditorDebuggerInspectedObject *p_obj) {
  1533. if (remote_objects.has(p_id))
  1534. memdelete(remote_objects[p_id]);
  1535. remote_objects[p_id] = p_obj;
  1536. }
  1537. void ScriptEditorDebugger::_clear_remote_objects() {
  1538. for (Map<ObjectID, ScriptEditorDebuggerInspectedObject *>::Element *E = remote_objects.front(); E; E = E->next()) {
  1539. if (editor->get_editor_history()->get_current() == E->value()->get_instance_id()) {
  1540. editor->push_item(NULL);
  1541. }
  1542. memdelete(E->value());
  1543. }
  1544. remote_objects.clear();
  1545. }
  1546. void ScriptEditorDebugger::_clear_errors_list() {
  1547. error_tree->clear();
  1548. error_count = 0;
  1549. warning_count = 0;
  1550. _notification(NOTIFICATION_PROCESS);
  1551. }
  1552. // Right click on specific file(s) or folder(s).
  1553. void ScriptEditorDebugger::_error_tree_item_rmb_selected(const Vector2 &p_pos) {
  1554. item_menu->clear();
  1555. item_menu->set_size(Size2(1, 1));
  1556. if (error_tree->is_anything_selected()) {
  1557. item_menu->add_icon_item(get_icon("ActionCopy", "EditorIcons"), TTR("Copy Error"), ITEM_MENU_COPY_ERROR);
  1558. }
  1559. if (item_menu->get_item_count() > 0) {
  1560. item_menu->set_position(error_tree->get_global_position() + p_pos);
  1561. item_menu->popup();
  1562. }
  1563. }
  1564. void ScriptEditorDebugger::_item_menu_id_pressed(int p_option) {
  1565. switch (p_option) {
  1566. case ITEM_MENU_COPY_ERROR: {
  1567. TreeItem *ti = error_tree->get_selected();
  1568. while (ti->get_parent() != error_tree->get_root())
  1569. ti = ti->get_parent();
  1570. String type;
  1571. if (ti->get_icon(0) == get_icon("Warning", "EditorIcons")) {
  1572. type = "W ";
  1573. } else if (ti->get_icon(0) == get_icon("Error", "EditorIcons")) {
  1574. type = "E ";
  1575. }
  1576. String text = ti->get_text(0) + " ";
  1577. int rpad_len = text.length();
  1578. text = type + text + ti->get_text(1) + "\n";
  1579. TreeItem *ci = ti->get_children();
  1580. while (ci) {
  1581. text += " " + ci->get_text(0).rpad(rpad_len) + ci->get_text(1) + "\n";
  1582. ci = ci->get_next();
  1583. }
  1584. OS::get_singleton()->set_clipboard(text);
  1585. } break;
  1586. case ITEM_MENU_SAVE_REMOTE_NODE: {
  1587. file_dialog->set_access(EditorFileDialog::ACCESS_RESOURCES);
  1588. file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE);
  1589. file_dialog_mode = SAVE_NODE;
  1590. List<String> extensions;
  1591. Ref<PackedScene> sd = memnew(PackedScene);
  1592. ResourceSaver::get_recognized_extensions(sd, &extensions);
  1593. file_dialog->clear_filters();
  1594. for (int i = 0; i < extensions.size(); i++) {
  1595. file_dialog->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper());
  1596. }
  1597. file_dialog->popup_centered_ratio();
  1598. } break;
  1599. case ITEM_MENU_COPY_NODE_PATH: {
  1600. TreeItem *ti = inspect_scene_tree->get_selected();
  1601. String text = ti->get_text(0);
  1602. if (ti->get_parent() == NULL) {
  1603. text = ".";
  1604. } else if (ti->get_parent()->get_parent() == NULL) {
  1605. text = ".";
  1606. } else {
  1607. while (ti->get_parent()->get_parent() != inspect_scene_tree->get_root()) {
  1608. ti = ti->get_parent();
  1609. text = ti->get_text(0) + "/" + text;
  1610. }
  1611. }
  1612. OS::get_singleton()->set_clipboard(text);
  1613. } break;
  1614. }
  1615. }
  1616. void ScriptEditorDebugger::_bind_methods() {
  1617. ClassDB::bind_method(D_METHOD("_stack_dump_frame_selected"), &ScriptEditorDebugger::_stack_dump_frame_selected);
  1618. ClassDB::bind_method(D_METHOD("debug_skip_breakpoints"), &ScriptEditorDebugger::debug_skip_breakpoints);
  1619. ClassDB::bind_method(D_METHOD("debug_copy"), &ScriptEditorDebugger::debug_copy);
  1620. ClassDB::bind_method(D_METHOD("debug_next"), &ScriptEditorDebugger::debug_next);
  1621. ClassDB::bind_method(D_METHOD("debug_step"), &ScriptEditorDebugger::debug_step);
  1622. ClassDB::bind_method(D_METHOD("debug_break"), &ScriptEditorDebugger::debug_break);
  1623. ClassDB::bind_method(D_METHOD("debug_continue"), &ScriptEditorDebugger::debug_continue);
  1624. ClassDB::bind_method(D_METHOD("_output_clear"), &ScriptEditorDebugger::_output_clear);
  1625. ClassDB::bind_method(D_METHOD("_export_csv"), &ScriptEditorDebugger::_export_csv);
  1626. ClassDB::bind_method(D_METHOD("_performance_draw"), &ScriptEditorDebugger::_performance_draw);
  1627. ClassDB::bind_method(D_METHOD("_performance_select"), &ScriptEditorDebugger::_performance_select);
  1628. ClassDB::bind_method(D_METHOD("_scene_tree_request"), &ScriptEditorDebugger::_scene_tree_request);
  1629. ClassDB::bind_method(D_METHOD("_video_mem_request"), &ScriptEditorDebugger::_video_mem_request);
  1630. ClassDB::bind_method(D_METHOD("_live_edit_set"), &ScriptEditorDebugger::_live_edit_set);
  1631. ClassDB::bind_method(D_METHOD("_live_edit_clear"), &ScriptEditorDebugger::_live_edit_clear);
  1632. ClassDB::bind_method(D_METHOD("_error_selected"), &ScriptEditorDebugger::_error_selected);
  1633. ClassDB::bind_method(D_METHOD("_error_activated"), &ScriptEditorDebugger::_error_activated);
  1634. ClassDB::bind_method(D_METHOD("_expand_errors_list"), &ScriptEditorDebugger::_expand_errors_list);
  1635. ClassDB::bind_method(D_METHOD("_collapse_errors_list"), &ScriptEditorDebugger::_collapse_errors_list);
  1636. ClassDB::bind_method(D_METHOD("_profiler_activate"), &ScriptEditorDebugger::_profiler_activate);
  1637. ClassDB::bind_method(D_METHOD("_network_profiler_activate"), &ScriptEditorDebugger::_network_profiler_activate);
  1638. ClassDB::bind_method(D_METHOD("_profiler_seeked"), &ScriptEditorDebugger::_profiler_seeked);
  1639. ClassDB::bind_method(D_METHOD("_clear_errors_list"), &ScriptEditorDebugger::_clear_errors_list);
  1640. ClassDB::bind_method(D_METHOD("_error_tree_item_rmb_selected"), &ScriptEditorDebugger::_error_tree_item_rmb_selected);
  1641. ClassDB::bind_method(D_METHOD("_item_menu_id_pressed"), &ScriptEditorDebugger::_item_menu_id_pressed);
  1642. ClassDB::bind_method(D_METHOD("_paused"), &ScriptEditorDebugger::_paused);
  1643. ClassDB::bind_method(D_METHOD("_scene_tree_selected"), &ScriptEditorDebugger::_scene_tree_selected);
  1644. ClassDB::bind_method(D_METHOD("_scene_tree_folded"), &ScriptEditorDebugger::_scene_tree_folded);
  1645. ClassDB::bind_method(D_METHOD("_scene_tree_rmb_selected"), &ScriptEditorDebugger::_scene_tree_rmb_selected);
  1646. ClassDB::bind_method(D_METHOD("_file_selected"), &ScriptEditorDebugger::_file_selected);
  1647. ClassDB::bind_method(D_METHOD("live_debug_create_node"), &ScriptEditorDebugger::live_debug_create_node);
  1648. ClassDB::bind_method(D_METHOD("live_debug_instance_node"), &ScriptEditorDebugger::live_debug_instance_node);
  1649. ClassDB::bind_method(D_METHOD("live_debug_remove_node"), &ScriptEditorDebugger::live_debug_remove_node);
  1650. ClassDB::bind_method(D_METHOD("live_debug_remove_and_keep_node"), &ScriptEditorDebugger::live_debug_remove_and_keep_node);
  1651. ClassDB::bind_method(D_METHOD("live_debug_restore_node"), &ScriptEditorDebugger::live_debug_restore_node);
  1652. ClassDB::bind_method(D_METHOD("live_debug_duplicate_node"), &ScriptEditorDebugger::live_debug_duplicate_node);
  1653. ClassDB::bind_method(D_METHOD("live_debug_reparent_node"), &ScriptEditorDebugger::live_debug_reparent_node);
  1654. ClassDB::bind_method(D_METHOD("_scene_tree_property_select_object"), &ScriptEditorDebugger::_scene_tree_property_select_object);
  1655. ClassDB::bind_method(D_METHOD("_scene_tree_property_value_edited"), &ScriptEditorDebugger::_scene_tree_property_value_edited);
  1656. ADD_SIGNAL(MethodInfo("goto_script_line"));
  1657. ADD_SIGNAL(MethodInfo("set_execution", PropertyInfo("script"), PropertyInfo(Variant::INT, "line")));
  1658. ADD_SIGNAL(MethodInfo("clear_execution", PropertyInfo("script")));
  1659. ADD_SIGNAL(MethodInfo("breaked", PropertyInfo(Variant::BOOL, "reallydid"), PropertyInfo(Variant::BOOL, "can_debug")));
  1660. ADD_SIGNAL(MethodInfo("show_debugger", PropertyInfo(Variant::BOOL, "reallydid")));
  1661. }
  1662. ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) {
  1663. ppeer = Ref<PacketPeerStream>(memnew(PacketPeerStream));
  1664. ppeer->set_input_buffer_max_size(1024 * 1024 * 8); //8mb should be enough
  1665. editor = p_editor;
  1666. editor->get_inspector()->connect("object_id_selected", this, "_scene_tree_property_select_object");
  1667. tabs = memnew(TabContainer);
  1668. tabs->set_tab_align(TabContainer::ALIGN_LEFT);
  1669. tabs->add_style_override("panel", editor->get_gui_base()->get_stylebox("DebuggerPanel", "EditorStyles"));
  1670. tabs->add_style_override("tab_fg", editor->get_gui_base()->get_stylebox("DebuggerTabFG", "EditorStyles"));
  1671. tabs->add_style_override("tab_bg", editor->get_gui_base()->get_stylebox("DebuggerTabBG", "EditorStyles"));
  1672. tabs->set_anchors_and_margins_preset(Control::PRESET_WIDE);
  1673. tabs->set_margin(MARGIN_LEFT, -editor->get_gui_base()->get_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_LEFT));
  1674. tabs->set_margin(MARGIN_RIGHT, editor->get_gui_base()->get_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_RIGHT));
  1675. add_child(tabs);
  1676. { //debugger
  1677. VBoxContainer *vbc = memnew(VBoxContainer);
  1678. vbc->set_name(TTR("Debugger"));
  1679. //tabs->add_child(vbc);
  1680. Control *dbg = vbc;
  1681. HBoxContainer *hbc = memnew(HBoxContainer);
  1682. vbc->add_child(hbc);
  1683. reason = memnew(Label);
  1684. reason->set_text("");
  1685. hbc->add_child(reason);
  1686. reason->set_h_size_flags(SIZE_EXPAND_FILL);
  1687. reason->set_autowrap(true);
  1688. reason->set_max_lines_visible(3);
  1689. reason->set_mouse_filter(Control::MOUSE_FILTER_PASS);
  1690. hbc->add_child(memnew(VSeparator));
  1691. skip_breakpoints = memnew(ToolButton);
  1692. hbc->add_child(skip_breakpoints);
  1693. skip_breakpoints->set_tooltip(TTR("Skip Breakpoints"));
  1694. skip_breakpoints->connect("pressed", this, "debug_skip_breakpoints");
  1695. hbc->add_child(memnew(VSeparator));
  1696. copy = memnew(ToolButton);
  1697. hbc->add_child(copy);
  1698. copy->set_tooltip(TTR("Copy Error"));
  1699. copy->connect("pressed", this, "debug_copy");
  1700. hbc->add_child(memnew(VSeparator));
  1701. step = memnew(ToolButton);
  1702. hbc->add_child(step);
  1703. step->set_tooltip(TTR("Step Into"));
  1704. step->set_shortcut(ED_GET_SHORTCUT("debugger/step_into"));
  1705. step->connect("pressed", this, "debug_step");
  1706. next = memnew(ToolButton);
  1707. hbc->add_child(next);
  1708. next->set_tooltip(TTR("Step Over"));
  1709. next->set_shortcut(ED_GET_SHORTCUT("debugger/step_over"));
  1710. next->connect("pressed", this, "debug_next");
  1711. hbc->add_child(memnew(VSeparator));
  1712. dobreak = memnew(ToolButton);
  1713. hbc->add_child(dobreak);
  1714. dobreak->set_tooltip(TTR("Break"));
  1715. dobreak->set_shortcut(ED_GET_SHORTCUT("debugger/break"));
  1716. dobreak->connect("pressed", this, "debug_break");
  1717. docontinue = memnew(ToolButton);
  1718. hbc->add_child(docontinue);
  1719. docontinue->set_tooltip(TTR("Continue"));
  1720. docontinue->set_shortcut(ED_GET_SHORTCUT("debugger/continue"));
  1721. docontinue->connect("pressed", this, "debug_continue");
  1722. back = memnew(Button);
  1723. hbc->add_child(back);
  1724. back->set_tooltip(TTR("Inspect Previous Instance"));
  1725. back->hide();
  1726. forward = memnew(Button);
  1727. hbc->add_child(forward);
  1728. forward->set_tooltip(TTR("Inspect Next Instance"));
  1729. forward->hide();
  1730. HSplitContainer *sc = memnew(HSplitContainer);
  1731. vbc->add_child(sc);
  1732. sc->set_v_size_flags(SIZE_EXPAND_FILL);
  1733. stack_dump = memnew(Tree);
  1734. stack_dump->set_allow_reselect(true);
  1735. stack_dump->set_columns(1);
  1736. stack_dump->set_column_titles_visible(true);
  1737. stack_dump->set_column_title(0, TTR("Stack Frames"));
  1738. stack_dump->set_h_size_flags(SIZE_EXPAND_FILL);
  1739. stack_dump->set_hide_root(true);
  1740. stack_dump->connect("cell_selected", this, "_stack_dump_frame_selected");
  1741. sc->add_child(stack_dump);
  1742. inspector = memnew(EditorInspector);
  1743. inspector->set_h_size_flags(SIZE_EXPAND_FILL);
  1744. inspector->set_enable_capitalize_paths(false);
  1745. inspector->set_read_only(true);
  1746. inspector->connect("object_id_selected", this, "_scene_tree_property_select_object");
  1747. sc->add_child(inspector);
  1748. server.instance();
  1749. pending_in_queue = 0;
  1750. variables = memnew(ScriptEditorDebuggerVariables);
  1751. breaked = false;
  1752. tabs->add_child(dbg);
  1753. }
  1754. { //errors
  1755. errors_tab = memnew(VBoxContainer);
  1756. errors_tab->set_name(TTR("Errors"));
  1757. HBoxContainer *errhb = memnew(HBoxContainer);
  1758. errors_tab->add_child(errhb);
  1759. Button *expand_all = memnew(Button);
  1760. expand_all->set_text(TTR("Expand All"));
  1761. expand_all->connect("pressed", this, "_expand_errors_list");
  1762. errhb->add_child(expand_all);
  1763. Button *collapse_all = memnew(Button);
  1764. collapse_all->set_text(TTR("Collapse All"));
  1765. collapse_all->connect("pressed", this, "_collapse_errors_list");
  1766. errhb->add_child(collapse_all);
  1767. Control *space = memnew(Control);
  1768. space->set_h_size_flags(SIZE_EXPAND_FILL);
  1769. errhb->add_child(space);
  1770. clearbutton = memnew(Button);
  1771. clearbutton->set_text(TTR("Clear"));
  1772. clearbutton->set_h_size_flags(0);
  1773. clearbutton->connect("pressed", this, "_clear_errors_list");
  1774. errhb->add_child(clearbutton);
  1775. error_tree = memnew(Tree);
  1776. error_tree->set_columns(2);
  1777. error_tree->set_column_expand(0, false);
  1778. error_tree->set_column_min_width(0, 140);
  1779. error_tree->set_column_expand(1, true);
  1780. error_tree->set_select_mode(Tree::SELECT_ROW);
  1781. error_tree->set_hide_root(true);
  1782. error_tree->set_v_size_flags(SIZE_EXPAND_FILL);
  1783. error_tree->set_allow_rmb_select(true);
  1784. error_tree->connect("item_rmb_selected", this, "_error_tree_item_rmb_selected");
  1785. errors_tab->add_child(error_tree);
  1786. item_menu = memnew(PopupMenu);
  1787. item_menu->connect("id_pressed", this, "_item_menu_id_pressed");
  1788. error_tree->add_child(item_menu);
  1789. tabs->add_child(errors_tab);
  1790. }
  1791. { // remote scene tree
  1792. inspect_scene_tree = memnew(Tree);
  1793. EditorNode::get_singleton()->get_scene_tree_dock()->add_remote_tree_editor(inspect_scene_tree);
  1794. EditorNode::get_singleton()->get_scene_tree_dock()->connect("remote_tree_selected", this, "_scene_tree_selected");
  1795. inspect_scene_tree->set_v_size_flags(SIZE_EXPAND_FILL);
  1796. inspect_scene_tree->connect("cell_selected", this, "_scene_tree_selected");
  1797. inspect_scene_tree->connect("item_collapsed", this, "_scene_tree_folded");
  1798. inspect_scene_tree->set_allow_rmb_select(true);
  1799. inspect_scene_tree->connect("item_rmb_selected", this, "_scene_tree_rmb_selected");
  1800. auto_switch_remote_scene_tree = EDITOR_DEF("debugger/auto_switch_to_remote_scene_tree", false);
  1801. inspect_scene_tree_timeout = EDITOR_DEF("debugger/remote_scene_tree_refresh_interval", 1.0);
  1802. inspect_edited_object_timeout = EDITOR_DEF("debugger/remote_inspect_refresh_interval", 0.2);
  1803. inspected_object_id = 0;
  1804. updating_scene_tree = false;
  1805. }
  1806. { // File dialog
  1807. file_dialog = memnew(EditorFileDialog);
  1808. file_dialog->connect("file_selected", this, "_file_selected");
  1809. add_child(file_dialog);
  1810. }
  1811. { //profiler
  1812. profiler = memnew(EditorProfiler);
  1813. profiler->set_name(TTR("Profiler"));
  1814. tabs->add_child(profiler);
  1815. profiler->connect("enable_profiling", this, "_profiler_activate");
  1816. profiler->connect("break_request", this, "_profiler_seeked");
  1817. }
  1818. { //network profiler
  1819. network_profiler = memnew(EditorNetworkProfiler);
  1820. network_profiler->set_name(TTR("Network Profiler"));
  1821. tabs->add_child(network_profiler);
  1822. network_profiler->connect("enable_profiling", this, "_network_profiler_activate");
  1823. }
  1824. { //monitors
  1825. HSplitContainer *hsp = memnew(HSplitContainer);
  1826. perf_monitors = memnew(Tree);
  1827. perf_monitors->set_columns(2);
  1828. perf_monitors->set_column_title(0, TTR("Monitor"));
  1829. perf_monitors->set_column_title(1, TTR("Value"));
  1830. perf_monitors->set_column_titles_visible(true);
  1831. perf_monitors->connect("item_edited", this, "_performance_select");
  1832. hsp->add_child(perf_monitors);
  1833. perf_draw = memnew(Control);
  1834. perf_draw->set_clip_contents(true);
  1835. perf_draw->connect("draw", this, "_performance_draw");
  1836. hsp->add_child(perf_draw);
  1837. hsp->set_name(TTR("Monitors"));
  1838. hsp->set_split_offset(340 * EDSCALE);
  1839. tabs->add_child(hsp);
  1840. perf_max.resize(Performance::MONITOR_MAX);
  1841. Map<String, TreeItem *> bases;
  1842. TreeItem *root = perf_monitors->create_item();
  1843. perf_monitors->set_hide_root(true);
  1844. for (int i = 0; i < Performance::MONITOR_MAX; i++) {
  1845. String n = Performance::get_singleton()->get_monitor_name(Performance::Monitor(i));
  1846. Performance::MonitorType mtype = Performance::get_singleton()->get_monitor_type(Performance::Monitor(i));
  1847. String base = n.get_slice("/", 0);
  1848. String name = n.get_slice("/", 1);
  1849. if (!bases.has(base)) {
  1850. TreeItem *b = perf_monitors->create_item(root);
  1851. b->set_text(0, base.capitalize());
  1852. b->set_editable(0, false);
  1853. b->set_selectable(0, false);
  1854. b->set_expand_right(0, true);
  1855. bases[base] = b;
  1856. }
  1857. TreeItem *it = perf_monitors->create_item(bases[base]);
  1858. it->set_metadata(1, mtype);
  1859. it->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  1860. it->set_editable(0, true);
  1861. it->set_selectable(0, false);
  1862. it->set_selectable(1, false);
  1863. it->set_text(0, name.capitalize());
  1864. perf_items.push_back(it);
  1865. perf_max.write[i] = 0;
  1866. }
  1867. info_message = memnew(Label);
  1868. info_message->set_text(TTR("Pick one or more items from the list to display the graph."));
  1869. info_message->set_valign(Label::VALIGN_CENTER);
  1870. info_message->set_align(Label::ALIGN_CENTER);
  1871. info_message->set_autowrap(true);
  1872. info_message->set_anchors_and_margins_preset(PRESET_WIDE, PRESET_MODE_KEEP_SIZE, 8 * EDSCALE);
  1873. perf_draw->add_child(info_message);
  1874. }
  1875. { //vmem inspect
  1876. VBoxContainer *vmem_vb = memnew(VBoxContainer);
  1877. HBoxContainer *vmem_hb = memnew(HBoxContainer);
  1878. Label *vmlb = memnew(Label(TTR("List of Video Memory Usage by Resource:") + " "));
  1879. vmlb->set_h_size_flags(SIZE_EXPAND_FILL);
  1880. vmem_hb->add_child(vmlb);
  1881. vmem_hb->add_child(memnew(Label(TTR("Total:") + " ")));
  1882. vmem_total = memnew(LineEdit);
  1883. vmem_total->set_editable(false);
  1884. vmem_total->set_custom_minimum_size(Size2(100, 0) * EDSCALE);
  1885. vmem_hb->add_child(vmem_total);
  1886. vmem_refresh = memnew(ToolButton);
  1887. vmem_hb->add_child(vmem_refresh);
  1888. vmem_vb->add_child(vmem_hb);
  1889. vmem_refresh->connect("pressed", this, "_video_mem_request");
  1890. VBoxContainer *vmmc = memnew(VBoxContainer);
  1891. vmem_tree = memnew(Tree);
  1892. vmem_tree->set_v_size_flags(SIZE_EXPAND_FILL);
  1893. vmem_tree->set_h_size_flags(SIZE_EXPAND_FILL);
  1894. vmmc->add_child(vmem_tree);
  1895. vmmc->set_v_size_flags(SIZE_EXPAND_FILL);
  1896. vmem_vb->add_child(vmmc);
  1897. vmem_vb->set_name(TTR("Video Mem"));
  1898. vmem_tree->set_columns(4);
  1899. vmem_tree->set_column_titles_visible(true);
  1900. vmem_tree->set_column_title(0, TTR("Resource Path"));
  1901. vmem_tree->set_column_expand(0, true);
  1902. vmem_tree->set_column_expand(1, false);
  1903. vmem_tree->set_column_title(1, TTR("Type"));
  1904. vmem_tree->set_column_min_width(1, 100);
  1905. vmem_tree->set_column_expand(2, false);
  1906. vmem_tree->set_column_title(2, TTR("Format"));
  1907. vmem_tree->set_column_min_width(2, 150);
  1908. vmem_tree->set_column_expand(3, false);
  1909. vmem_tree->set_column_title(3, TTR("Usage"));
  1910. vmem_tree->set_column_min_width(3, 80);
  1911. vmem_tree->set_hide_root(true);
  1912. tabs->add_child(vmem_vb);
  1913. }
  1914. { // misc
  1915. VBoxContainer *misc = memnew(VBoxContainer);
  1916. misc->set_name(TTR("Misc"));
  1917. tabs->add_child(misc);
  1918. GridContainer *info_left = memnew(GridContainer);
  1919. info_left->set_columns(2);
  1920. misc->add_child(info_left);
  1921. clicked_ctrl = memnew(LineEdit);
  1922. clicked_ctrl->set_h_size_flags(SIZE_EXPAND_FILL);
  1923. info_left->add_child(memnew(Label(TTR("Clicked Control:"))));
  1924. info_left->add_child(clicked_ctrl);
  1925. clicked_ctrl_type = memnew(LineEdit);
  1926. info_left->add_child(memnew(Label(TTR("Clicked Control Type:"))));
  1927. info_left->add_child(clicked_ctrl_type);
  1928. live_edit_root = memnew(LineEdit);
  1929. live_edit_root->set_h_size_flags(SIZE_EXPAND_FILL);
  1930. {
  1931. HBoxContainer *lehb = memnew(HBoxContainer);
  1932. Label *l = memnew(Label(TTR("Live Edit Root:")));
  1933. info_left->add_child(l);
  1934. lehb->add_child(live_edit_root);
  1935. le_set = memnew(Button(TTR("Set From Tree")));
  1936. lehb->add_child(le_set);
  1937. le_clear = memnew(Button(TTR("Clear")));
  1938. lehb->add_child(le_clear);
  1939. info_left->add_child(lehb);
  1940. le_set->set_disabled(true);
  1941. le_clear->set_disabled(true);
  1942. }
  1943. misc->add_child(memnew(VSeparator));
  1944. HBoxContainer *buttons = memnew(HBoxContainer);
  1945. export_csv = memnew(Button(TTR("Export measures as CSV")));
  1946. export_csv->connect("pressed", this, "_export_csv");
  1947. buttons->add_child(export_csv);
  1948. misc->add_child(buttons);
  1949. }
  1950. msgdialog = memnew(AcceptDialog);
  1951. add_child(msgdialog);
  1952. p_editor->get_undo_redo()->set_method_notify_callback(_method_changeds, this);
  1953. p_editor->get_undo_redo()->set_property_notify_callback(_property_changeds, this);
  1954. live_debug = true;
  1955. last_path_id = false;
  1956. error_count = 0;
  1957. warning_count = 0;
  1958. hide_on_stop = true;
  1959. enable_external_editor = false;
  1960. last_error_count = 0;
  1961. last_warning_count = 0;
  1962. EditorNode::get_singleton()->get_pause_button()->connect("pressed", this, "_paused");
  1963. }
  1964. ScriptEditorDebugger::~ScriptEditorDebugger() {
  1965. memdelete(variables);
  1966. ppeer->set_stream_peer(Ref<StreamPeer>());
  1967. server->stop();
  1968. _clear_remote_objects();
  1969. }