script_editor_debugger.cpp 71 KB

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