script_editor_debugger.cpp 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914
  1. /*************************************************************************/
  2. /* script_editor_debugger.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 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 "editor_node.h"
  32. #include "editor_profiler.h"
  33. #include "editor_settings.h"
  34. #include "main/performance.h"
  35. #include "project_settings.h"
  36. #include "property_editor.h"
  37. #include "scene/gui/dialogs.h"
  38. #include "scene/gui/label.h"
  39. #include "scene/gui/line_edit.h"
  40. #include "scene/gui/margin_container.h"
  41. #include "scene/gui/rich_text_label.h"
  42. #include "scene/gui/separator.h"
  43. #include "scene/gui/split_container.h"
  44. #include "scene/gui/tab_container.h"
  45. #include "scene/gui/texture_button.h"
  46. #include "scene/gui/tree.h"
  47. class ScriptEditorDebuggerVariables : public Object {
  48. GDCLASS(ScriptEditorDebuggerVariables, Object);
  49. List<PropertyInfo> props;
  50. Map<StringName, Variant> values;
  51. protected:
  52. bool _set(const StringName &p_name, const Variant &p_value) {
  53. return false;
  54. }
  55. bool _get(const StringName &p_name, Variant &r_ret) const {
  56. if (!values.has(p_name))
  57. return false;
  58. r_ret = values[p_name];
  59. return true;
  60. }
  61. void _get_property_list(List<PropertyInfo> *p_list) const {
  62. for (const List<PropertyInfo>::Element *E = props.front(); E; E = E->next())
  63. p_list->push_back(E->get());
  64. }
  65. public:
  66. void clear() {
  67. props.clear();
  68. values.clear();
  69. }
  70. String get_var_value(const String &p_var) const {
  71. for (Map<StringName, Variant>::Element *E = values.front(); E; E = E->next()) {
  72. String v = E->key().operator String().get_slice("/", 1);
  73. if (v == p_var)
  74. return E->get();
  75. }
  76. return "";
  77. }
  78. void add_property(const String &p_name, const Variant &p_value, const PropertyHint &p_hint, const String p_hint_string) {
  79. PropertyInfo pinfo;
  80. pinfo.name = p_name;
  81. pinfo.type = p_value.get_type();
  82. pinfo.hint = p_hint;
  83. pinfo.hint_string = p_hint_string;
  84. props.push_back(pinfo);
  85. values[p_name] = p_value;
  86. }
  87. void update() {
  88. _change_notify();
  89. }
  90. ScriptEditorDebuggerVariables() {
  91. }
  92. };
  93. class ScriptEditorDebuggerInspectedObject : public Object {
  94. GDCLASS(ScriptEditorDebuggerInspectedObject, Object);
  95. protected:
  96. bool _set(const StringName &p_name, const Variant &p_value) {
  97. if (!prop_values.has(p_name))
  98. return false;
  99. emit_signal("value_edited", p_name, p_value);
  100. prop_values[p_name] = p_value;
  101. return true;
  102. }
  103. bool _get(const StringName &p_name, Variant &r_ret) const {
  104. if (!prop_values.has(p_name))
  105. return false;
  106. r_ret = prop_values[p_name];
  107. return true;
  108. }
  109. void _get_property_list(List<PropertyInfo> *p_list) const {
  110. p_list->clear(); //sorry, no want category
  111. for (const List<PropertyInfo>::Element *E = prop_list.front(); E; E = E->next()) {
  112. p_list->push_back(E->get());
  113. }
  114. }
  115. static void _bind_methods() {
  116. ADD_SIGNAL(MethodInfo("value_edited"));
  117. }
  118. public:
  119. ObjectID last_edited_id;
  120. List<PropertyInfo> prop_list;
  121. Map<StringName, Variant> prop_values;
  122. void update() {
  123. _change_notify();
  124. }
  125. void update_single(const char *p_prop) {
  126. _change_notify(p_prop);
  127. }
  128. ScriptEditorDebuggerInspectedObject() { last_edited_id = 0; }
  129. };
  130. void ScriptEditorDebugger::debug_next() {
  131. ERR_FAIL_COND(!breaked);
  132. ERR_FAIL_COND(connection.is_null());
  133. ERR_FAIL_COND(!connection->is_connected_to_host());
  134. Array msg;
  135. msg.push_back("next");
  136. ppeer->put_var(msg);
  137. stack_dump->clear();
  138. inspector->edit(NULL);
  139. }
  140. void ScriptEditorDebugger::debug_step() {
  141. ERR_FAIL_COND(!breaked);
  142. ERR_FAIL_COND(connection.is_null());
  143. ERR_FAIL_COND(!connection->is_connected_to_host());
  144. Array msg;
  145. msg.push_back("step");
  146. ppeer->put_var(msg);
  147. stack_dump->clear();
  148. inspector->edit(NULL);
  149. }
  150. void ScriptEditorDebugger::debug_break() {
  151. ERR_FAIL_COND(breaked);
  152. ERR_FAIL_COND(connection.is_null());
  153. ERR_FAIL_COND(!connection->is_connected_to_host());
  154. Array msg;
  155. msg.push_back("break");
  156. ppeer->put_var(msg);
  157. }
  158. void ScriptEditorDebugger::debug_continue() {
  159. ERR_FAIL_COND(!breaked);
  160. ERR_FAIL_COND(connection.is_null());
  161. ERR_FAIL_COND(!connection->is_connected_to_host());
  162. OS::get_singleton()->enable_for_stealing_focus(EditorNode::get_singleton()->get_child_process_id());
  163. Array msg;
  164. msg.push_back("continue");
  165. ppeer->put_var(msg);
  166. }
  167. void ScriptEditorDebugger::_scene_tree_folded(Object *obj) {
  168. if (updating_scene_tree) {
  169. return;
  170. }
  171. TreeItem *item = Object::cast_to<TreeItem>(obj);
  172. if (!item)
  173. return;
  174. ObjectID id = item->get_metadata(0);
  175. if (item->is_collapsed()) {
  176. unfold_cache.erase(id);
  177. } else {
  178. unfold_cache.insert(id);
  179. }
  180. }
  181. void ScriptEditorDebugger::_scene_tree_selected() {
  182. if (updating_scene_tree) {
  183. return;
  184. }
  185. TreeItem *item = inspect_scene_tree->get_selected();
  186. if (!item) {
  187. return;
  188. }
  189. inspected_object_id = item->get_metadata(0);
  190. Array msg;
  191. msg.push_back("inspect_object");
  192. msg.push_back(inspected_object_id);
  193. ppeer->put_var(msg);
  194. }
  195. void ScriptEditorDebugger::_scene_tree_property_value_edited(const String &p_prop, const Variant &p_value) {
  196. Array msg;
  197. msg.push_back("set_object_property");
  198. msg.push_back(inspected_object_id);
  199. msg.push_back(p_prop);
  200. msg.push_back(p_value);
  201. ppeer->put_var(msg);
  202. inspect_edited_object_timeout = 0.7; //avoid annoyance, don't request soon after editing
  203. }
  204. void ScriptEditorDebugger::_scene_tree_property_select_object(ObjectID p_object) {
  205. inspected_object_id = p_object;
  206. Array msg;
  207. msg.push_back("inspect_object");
  208. msg.push_back(inspected_object_id);
  209. ppeer->put_var(msg);
  210. }
  211. void ScriptEditorDebugger::_scene_tree_request() {
  212. ERR_FAIL_COND(connection.is_null());
  213. ERR_FAIL_COND(!connection->is_connected_to_host());
  214. Array msg;
  215. msg.push_back("request_scene_tree");
  216. ppeer->put_var(msg);
  217. }
  218. void ScriptEditorDebugger::_video_mem_request() {
  219. ERR_FAIL_COND(connection.is_null());
  220. ERR_FAIL_COND(!connection->is_connected_to_host());
  221. Array msg;
  222. msg.push_back("request_video_mem");
  223. ppeer->put_var(msg);
  224. }
  225. Size2 ScriptEditorDebugger::get_minimum_size() const {
  226. Size2 ms = Control::get_minimum_size();
  227. ms.y = MAX(ms.y, 250);
  228. return ms;
  229. }
  230. void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_data) {
  231. if (p_msg == "debug_enter") {
  232. Array msg;
  233. msg.push_back("get_stack_dump");
  234. ppeer->put_var(msg);
  235. ERR_FAIL_COND(p_data.size() != 2);
  236. bool can_continue = p_data[0];
  237. String error = p_data[1];
  238. step->set_disabled(!can_continue);
  239. next->set_disabled(!can_continue);
  240. _set_reason_text(error, MESSAGE_ERROR);
  241. breaked = true;
  242. dobreak->set_disabled(true);
  243. docontinue->set_disabled(false);
  244. emit_signal("breaked", true, can_continue);
  245. OS::get_singleton()->move_window_to_foreground();
  246. if (error != "") {
  247. tabs->set_current_tab(0);
  248. }
  249. profiler->set_enabled(false);
  250. EditorNode::get_singleton()->get_pause_button()->set_pressed(true);
  251. EditorNode::get_singleton()->make_bottom_panel_item_visible(this);
  252. } else if (p_msg == "debug_exit") {
  253. breaked = false;
  254. step->set_disabled(true);
  255. next->set_disabled(true);
  256. reason->set_text("");
  257. reason->set_tooltip("");
  258. back->set_disabled(true);
  259. forward->set_disabled(true);
  260. dobreak->set_disabled(false);
  261. docontinue->set_disabled(true);
  262. emit_signal("breaked", false, false, Variant());
  263. //tabs->set_current_tab(0);
  264. profiler->set_enabled(true);
  265. profiler->disable_seeking();
  266. EditorNode::get_singleton()->get_pause_button()->set_pressed(false);
  267. } else if (p_msg == "message:click_ctrl") {
  268. clicked_ctrl->set_text(p_data[0]);
  269. clicked_ctrl_type->set_text(p_data[1]);
  270. } else if (p_msg == "message:scene_tree") {
  271. inspect_scene_tree->clear();
  272. Map<int, TreeItem *> lv;
  273. updating_scene_tree = true;
  274. for (int i = 0; i < p_data.size(); i += 4) {
  275. TreeItem *p;
  276. int level = p_data[i];
  277. if (level == 0) {
  278. p = NULL;
  279. } else {
  280. ERR_CONTINUE(!lv.has(level - 1));
  281. p = lv[level - 1];
  282. }
  283. TreeItem *it = inspect_scene_tree->create_item(p);
  284. ObjectID id = ObjectID(p_data[i + 3]);
  285. it->set_text(0, p_data[i + 1]);
  286. if (has_icon(p_data[i + 2], "EditorIcons"))
  287. it->set_icon(0, get_icon(p_data[i + 2], "EditorIcons"));
  288. it->set_metadata(0, id);
  289. if (id == inspected_object_id) {
  290. TreeItem *cti = it->get_parent(); //ensure selected is always uncollapsed
  291. while (cti) {
  292. cti->set_collapsed(false);
  293. cti = cti->get_parent();
  294. }
  295. it->select(0);
  296. }
  297. if (p) {
  298. if (!unfold_cache.has(id)) {
  299. it->set_collapsed(true);
  300. }
  301. } else {
  302. if (unfold_cache.has(id)) { //reverse for root
  303. it->set_collapsed(true);
  304. }
  305. }
  306. lv[level] = it;
  307. }
  308. updating_scene_tree = false;
  309. le_clear->set_disabled(false);
  310. le_set->set_disabled(false);
  311. } else if (p_msg == "message:inspect_object") {
  312. ObjectID id = p_data[0];
  313. String type = p_data[1];
  314. Variant path = p_data[2]; //what to do yet, i don't know
  315. int prop_count = p_data[3];
  316. int idx = 4;
  317. if (inspected_object->last_edited_id != id) {
  318. inspected_object->prop_list.clear();
  319. inspected_object->prop_values.clear();
  320. }
  321. for (int i = 0; i < prop_count; i++) {
  322. PropertyInfo pinfo;
  323. pinfo.name = p_data[idx++];
  324. pinfo.type = Variant::Type(int(p_data[idx++]));
  325. pinfo.hint = PropertyHint(int(p_data[idx++]));
  326. pinfo.hint_string = p_data[idx++];
  327. if (pinfo.name.begins_with("*")) {
  328. pinfo.name = pinfo.name.substr(1, pinfo.name.length());
  329. pinfo.usage = PROPERTY_USAGE_CATEGORY;
  330. } else {
  331. pinfo.usage = PROPERTY_USAGE_EDITOR;
  332. }
  333. if (inspected_object->last_edited_id != id) {
  334. //don't update.. it's the same, instead refresh
  335. inspected_object->prop_list.push_back(pinfo);
  336. }
  337. inspected_object->prop_values[pinfo.name] = p_data[idx++];
  338. if (inspected_object->last_edited_id == id) {
  339. //same, just update value, don't rebuild
  340. inspected_object->update_single(pinfo.name.ascii().get_data());
  341. }
  342. }
  343. if (inspected_object->last_edited_id != id) {
  344. //only if different
  345. inspected_object->update();
  346. }
  347. inspected_object->last_edited_id = id;
  348. tabs->set_current_tab(inspect_info->get_index());
  349. inspect_properties->edit(inspected_object);
  350. } else if (p_msg == "message:video_mem") {
  351. vmem_tree->clear();
  352. TreeItem *root = vmem_tree->create_item();
  353. int total = 0;
  354. for (int i = 0; i < p_data.size(); i += 4) {
  355. TreeItem *it = vmem_tree->create_item(root);
  356. String type = p_data[i + 1];
  357. int bytes = p_data[i + 3].operator int();
  358. it->set_text(0, p_data[i + 0]); //path
  359. it->set_text(1, type); //type
  360. it->set_text(2, p_data[i + 2]); //type
  361. it->set_text(3, String::humanize_size(bytes)); //type
  362. total += bytes;
  363. if (has_icon(type, "EditorIcons"))
  364. it->set_icon(0, get_icon(type, "EditorIcons"));
  365. }
  366. vmem_total->set_tooltip(TTR("Bytes:") + " " + itos(total));
  367. vmem_total->set_text(String::humanize_size(total));
  368. } else if (p_msg == "stack_dump") {
  369. stack_dump->clear();
  370. TreeItem *r = stack_dump->create_item();
  371. for (int i = 0; i < p_data.size(); i++) {
  372. Dictionary d = p_data[i];
  373. ERR_CONTINUE(!d.has("function"));
  374. ERR_CONTINUE(!d.has("file"));
  375. ERR_CONTINUE(!d.has("line"));
  376. ERR_CONTINUE(!d.has("id"));
  377. TreeItem *s = stack_dump->create_item(r);
  378. d["frame"] = i;
  379. s->set_metadata(0, d);
  380. //String line = itos(i)+" - "+String(d["file"])+":"+itos(d["line"])+" - at func: "+d["function"];
  381. String line = itos(i) + " - " + String(d["file"]) + ":" + itos(d["line"]);
  382. s->set_text(0, line);
  383. if (i == 0)
  384. s->select(0);
  385. }
  386. } else if (p_msg == "stack_frame_vars") {
  387. variables->clear();
  388. int ofs = 0;
  389. int mcount = p_data[ofs];
  390. ofs++;
  391. for (int i = 0; i < mcount; i++) {
  392. String n = p_data[ofs + i * 2 + 0];
  393. Variant v = p_data[ofs + i * 2 + 1];
  394. PropertyHint h = PROPERTY_HINT_NONE;
  395. String hs = String();
  396. if (n.begins_with("*")) {
  397. n = n.substr(1, n.length());
  398. h = PROPERTY_HINT_OBJECT_ID;
  399. String s = v;
  400. s = s.replace("[", "");
  401. hs = s.get_slice(":", 0);
  402. v = s.get_slice(":", 1).to_int();
  403. }
  404. variables->add_property("members/" + n, v, h, hs);
  405. }
  406. ofs += mcount * 2;
  407. mcount = p_data[ofs];
  408. ofs++;
  409. for (int i = 0; i < mcount; i++) {
  410. String n = p_data[ofs + i * 2 + 0];
  411. Variant v = p_data[ofs + i * 2 + 1];
  412. PropertyHint h = PROPERTY_HINT_NONE;
  413. String hs = String();
  414. if (n.begins_with("*")) {
  415. n = n.substr(1, n.length());
  416. h = PROPERTY_HINT_OBJECT_ID;
  417. String s = v;
  418. s = s.replace("[", "");
  419. hs = s.get_slice(":", 0);
  420. v = s.get_slice(":", 1).to_int();
  421. }
  422. variables->add_property("locals/" + n, v, h, hs);
  423. }
  424. variables->update();
  425. inspector->edit(variables);
  426. } else if (p_msg == "output") {
  427. //OUT
  428. for (int i = 0; i < p_data.size(); i++) {
  429. String t = p_data[i];
  430. //LOG
  431. if (!EditorNode::get_log()->is_visible()) {
  432. if (EditorNode::get_singleton()->are_bottom_panels_hidden()) {
  433. EditorNode::get_singleton()->make_bottom_panel_item_visible(EditorNode::get_log());
  434. }
  435. }
  436. EditorNode::get_log()->add_message(t);
  437. }
  438. } else if (p_msg == "performance") {
  439. Array arr = p_data[0];
  440. Vector<float> p;
  441. p.resize(arr.size());
  442. for (int i = 0; i < arr.size(); i++) {
  443. p[i] = arr[i];
  444. if (i < perf_items.size()) {
  445. perf_items[i]->set_text(1, rtos(p[i]));
  446. if (p[i] > perf_max[i])
  447. perf_max[i] = p[i];
  448. }
  449. }
  450. perf_history.push_front(p);
  451. perf_draw->update();
  452. } else if (p_msg == "error") {
  453. Array err = p_data[0];
  454. Array vals;
  455. vals.push_back(err[0]);
  456. vals.push_back(err[1]);
  457. vals.push_back(err[2]);
  458. vals.push_back(err[3]);
  459. bool warning = err[9];
  460. bool e;
  461. String time = String("%d:%02d:%02d:%04d").sprintf(vals, &e);
  462. String txt = time + " - " + (err[8].is_zero() ? String(err[7]) : String(err[8]));
  463. String tooltip = TTR("Type:") + String(warning ? TTR("Warning") : TTR("Error"));
  464. tooltip += "\n" + TTR("Description:") + " " + String(err[8]);
  465. tooltip += "\n" + TTR("Time:") + " " + time;
  466. tooltip += "\nC " + TTR("Error:") + " " + String(err[7]);
  467. tooltip += "\nC " + TTR("Source:") + " " + String(err[5]) + ":" + String(err[6]);
  468. tooltip += "\nC " + TTR("Function:") + " " + String(err[4]);
  469. error_list->add_item(txt, EditorNode::get_singleton()->get_gui_base()->get_icon(warning ? "Warning" : "Error", "EditorIcons"));
  470. error_list->set_item_tooltip(error_list->get_item_count() - 1, tooltip);
  471. int scc = p_data[1];
  472. Array stack;
  473. stack.resize(scc);
  474. for (int i = 0; i < scc; i++) {
  475. stack[i] = p_data[2 + i];
  476. }
  477. error_list->set_item_metadata(error_list->get_item_count() - 1, stack);
  478. error_count++;
  479. /*
  480. int count = p_data[1];
  481. Array cstack;
  482. OutputError oe = errors.front()->get();
  483. packet_peer_stream->put_var(oe.hr);
  484. packet_peer_stream->put_var(oe.min);
  485. packet_peer_stream->put_var(oe.sec);
  486. packet_peer_stream->put_var(oe.msec);
  487. packet_peer_stream->put_var(oe.source_func);
  488. packet_peer_stream->put_var(oe.source_file);
  489. packet_peer_stream->put_var(oe.source_line);
  490. packet_peer_stream->put_var(oe.error);
  491. packet_peer_stream->put_var(oe.error_descr);
  492. packet_peer_stream->put_var(oe.warning);
  493. packet_peer_stream->put_var(oe.callstack);
  494. */
  495. } else if (p_msg == "profile_sig") {
  496. //cache a signature
  497. profiler_signature[p_data[1]] = p_data[0];
  498. } else if (p_msg == "profile_frame" || p_msg == "profile_total") {
  499. EditorProfiler::Metric metric;
  500. metric.valid = true;
  501. metric.frame_number = p_data[0];
  502. metric.frame_time = p_data[1];
  503. metric.idle_time = p_data[2];
  504. metric.fixed_time = p_data[3];
  505. metric.fixed_frame_time = p_data[4];
  506. int frame_data_amount = p_data[6];
  507. int frame_function_amount = p_data[7];
  508. if (frame_data_amount) {
  509. EditorProfiler::Metric::Category frame_time;
  510. frame_time.signature = "category_frame_time";
  511. frame_time.name = "Frame Time";
  512. frame_time.total_time = metric.frame_time;
  513. EditorProfiler::Metric::Category::Item item;
  514. item.calls = 1;
  515. item.line = 0;
  516. item.name = "Fixed Time";
  517. item.total = metric.fixed_time;
  518. item.self = item.total;
  519. item.signature = "fixed_time";
  520. frame_time.items.push_back(item);
  521. item.name = "Idle Time";
  522. item.total = metric.idle_time;
  523. item.self = item.total;
  524. item.signature = "idle_time";
  525. frame_time.items.push_back(item);
  526. item.name = "Fixed Frame Time";
  527. item.total = metric.fixed_frame_time;
  528. item.self = item.total;
  529. item.signature = "fixed_frame_time";
  530. frame_time.items.push_back(item);
  531. metric.categories.push_back(frame_time);
  532. }
  533. int idx = 8;
  534. for (int i = 0; i < frame_data_amount; i++) {
  535. EditorProfiler::Metric::Category c;
  536. String name = p_data[idx++];
  537. Array values = p_data[idx++];
  538. c.name = name.capitalize();
  539. c.items.resize(values.size() / 2);
  540. c.total_time = 0;
  541. c.signature = "categ::" + name;
  542. for (int i = 0; i < values.size(); i += 2) {
  543. EditorProfiler::Metric::Category::Item item;
  544. item.name = values[i];
  545. item.calls = 1;
  546. item.self = values[i + 1];
  547. item.total = item.self;
  548. item.signature = "categ::" + name + "::" + item.name;
  549. item.name = item.name.capitalize();
  550. c.total_time += item.total;
  551. c.items[i / 2] = item;
  552. }
  553. metric.categories.push_back(c);
  554. }
  555. EditorProfiler::Metric::Category funcs;
  556. funcs.total_time = p_data[5]; //script time
  557. funcs.items.resize(frame_function_amount);
  558. funcs.name = "Script Functions";
  559. funcs.signature = "script_functions";
  560. for (int i = 0; i < frame_function_amount; i++) {
  561. int signature = p_data[idx++];
  562. int calls = p_data[idx++];
  563. float total = p_data[idx++];
  564. float self = p_data[idx++];
  565. EditorProfiler::Metric::Category::Item item;
  566. if (profiler_signature.has(signature)) {
  567. item.signature = profiler_signature[signature];
  568. String name = profiler_signature[signature];
  569. Vector<String> strings = name.split("::");
  570. if (strings.size() == 3) {
  571. item.name = strings[2];
  572. item.script = strings[0];
  573. item.line = strings[1].to_int();
  574. }
  575. } else {
  576. item.name = "SigErr " + itos(signature);
  577. }
  578. item.calls = calls;
  579. item.self = self;
  580. item.total = total;
  581. funcs.items[i] = item;
  582. }
  583. metric.categories.push_back(funcs);
  584. if (p_msg == "profile_frame")
  585. profiler->add_frame_metric(metric, false);
  586. else
  587. profiler->add_frame_metric(metric, true);
  588. } else if (p_msg == "kill_me") {
  589. editor->call_deferred("stop_child_process");
  590. }
  591. }
  592. void ScriptEditorDebugger::_set_reason_text(const String &p_reason, MessageType p_type) {
  593. switch (p_type) {
  594. case MESSAGE_ERROR:
  595. reason->add_color_override("font_color", get_color("error_color", "Editor"));
  596. break;
  597. case MESSAGE_WARNING:
  598. reason->add_color_override("font_color", get_color("warning_color", "Editor"));
  599. break;
  600. default:
  601. reason->add_color_override("font_color", get_color("success_color", "Editor"));
  602. }
  603. reason->set_text(p_reason);
  604. reason->set_tooltip(p_reason);
  605. }
  606. void ScriptEditorDebugger::_performance_select(Object *, int, bool) {
  607. perf_draw->update();
  608. }
  609. void ScriptEditorDebugger::_performance_draw() {
  610. Vector<int> which;
  611. for (int i = 0; i < perf_items.size(); i++) {
  612. if (perf_items[i]->is_selected(0))
  613. which.push_back(i);
  614. }
  615. if (which.empty())
  616. return;
  617. Ref<StyleBox> graph_sb = get_stylebox("normal", "TextEdit");
  618. Ref<Font> graph_font = get_font("font", "TextEdit");
  619. int cols = Math::ceil(Math::sqrt((float)which.size()));
  620. int rows = (which.size() + 1) / cols;
  621. if (which.size() == 1)
  622. rows = 1;
  623. int margin = 3;
  624. int point_sep = 5;
  625. Size2i s = Size2i(perf_draw->get_size()) / Size2i(cols, rows);
  626. for (int i = 0; i < which.size(); i++) {
  627. Point2i p(i % cols, i / cols);
  628. Rect2i r(p * s, s);
  629. r.position += Point2(margin, margin);
  630. r.size -= Point2(margin, margin) * 2.0;
  631. perf_draw->draw_style_box(graph_sb, r);
  632. r.position += graph_sb->get_offset();
  633. r.size -= graph_sb->get_minimum_size();
  634. int pi = which[i];
  635. Color c = get_color("success_color", "Editor");
  636. c.set_hsv(Math::fmod(c.get_h() + pi * 0.7654, 1), c.get_s(), c.get_v());
  637. //c = c.linear_interpolate(get_color("base_color", "Editor"), 0.9);
  638. c.a = 0.8;
  639. perf_draw->draw_string(graph_font, r.position + Point2(0, graph_font->get_ascent()), perf_items[pi]->get_text(0), c, r.size.x);
  640. c.a = 0.6;
  641. perf_draw->draw_string(graph_font, r.position + Point2(graph_font->get_char_size('X').width, graph_font->get_ascent() + graph_font->get_height()), perf_items[pi]->get_text(1), c, r.size.y);
  642. float spacing = point_sep / float(cols);
  643. float from = r.size.width;
  644. List<Vector<float> >::Element *E = perf_history.front();
  645. float prev = -1;
  646. while (from >= 0 && E) {
  647. float m = perf_max[pi];
  648. if (m == 0)
  649. m = 0.00001;
  650. float h = E->get()[pi] / m;
  651. h = (1.0 - h) * r.size.y;
  652. c.a = 0.7;
  653. if (E != perf_history.front())
  654. perf_draw->draw_line(r.position + Point2(from, h), r.position + Point2(from + spacing, prev), c, 2.0);
  655. prev = h;
  656. E = E->next();
  657. from -= spacing;
  658. }
  659. }
  660. }
  661. void ScriptEditorDebugger::_notification(int p_what) {
  662. switch (p_what) {
  663. case NOTIFICATION_ENTER_TREE: {
  664. inspector->edit(variables);
  665. step->set_icon(get_icon("DebugStep", "EditorIcons"));
  666. next->set_icon(get_icon("DebugNext", "EditorIcons"));
  667. back->set_icon(get_icon("Back", "EditorIcons"));
  668. forward->set_icon(get_icon("Forward", "EditorIcons"));
  669. dobreak->set_icon(get_icon("Pause", "EditorIcons"));
  670. docontinue->set_icon(get_icon("DebugContinue", "EditorIcons"));
  671. //scene_tree_refresh->set_icon( get_icon("Reload","EditorIcons"));
  672. le_set->connect("pressed", this, "_live_edit_set");
  673. le_clear->connect("pressed", this, "_live_edit_clear");
  674. error_list->connect("item_selected", this, "_error_selected");
  675. error_stack->connect("item_selected", this, "_error_stack_selected");
  676. vmem_refresh->set_icon(get_icon("Reload", "EditorIcons"));
  677. reason->add_color_override("font_color", get_color("error_color", "Editor"));
  678. } break;
  679. case NOTIFICATION_PROCESS: {
  680. if (connection.is_valid()) {
  681. inspect_scene_tree_timeout -= get_process_delta_time();
  682. if (inspect_scene_tree_timeout < 0) {
  683. inspect_scene_tree_timeout = EditorSettings::get_singleton()->get("debugger/scene_tree_refresh_interval");
  684. if (inspect_scene_tree->is_visible_in_tree()) {
  685. _scene_tree_request();
  686. if (inspected_object_id != 0) {
  687. //take the chance and re-inspect selected object
  688. Array msg;
  689. msg.push_back("inspect_object");
  690. msg.push_back(inspected_object_id);
  691. ppeer->put_var(msg);
  692. }
  693. }
  694. }
  695. inspect_edited_object_timeout -= get_process_delta_time();
  696. if (inspect_edited_object_timeout < 0) {
  697. inspect_edited_object_timeout = EditorSettings::get_singleton()->get("debugger/remote_inspect_refresh_interval");
  698. if (inspect_scene_tree->is_visible_in_tree() && inspected_object_id) {
  699. //take the chance and re-inspect selected object
  700. Array msg;
  701. msg.push_back("inspect_object");
  702. msg.push_back(inspected_object_id);
  703. ppeer->put_var(msg);
  704. }
  705. }
  706. }
  707. if (error_count != last_error_count) {
  708. if (error_count == 0) {
  709. error_split->set_name(TTR("Errors"));
  710. debugger_button->set_text(TTR("Debugger"));
  711. debugger_button->set_icon(Ref<Texture>());
  712. tabs->set_tab_icon(error_split->get_index(), Ref<Texture>());
  713. } else {
  714. error_split->set_name(TTR("Errors") + " (" + itos(error_count) + ")");
  715. debugger_button->set_text(TTR("Debugger") + " (" + itos(error_count) + ")");
  716. debugger_button->set_icon(get_icon("Error", "EditorIcons"));
  717. tabs->set_tab_icon(error_split->get_index(), get_icon("Error", "EditorIcons"));
  718. }
  719. last_error_count = error_count;
  720. }
  721. if (connection.is_null()) {
  722. if (server->is_connection_available()) {
  723. connection = server->take_connection();
  724. if (connection.is_null())
  725. break;
  726. EditorNode::get_log()->add_message("** Debug Process Started **");
  727. ppeer->set_stream_peer(connection);
  728. //EditorNode::get_singleton()->make_bottom_panel_item_visible(this);
  729. //emit_signal("show_debugger",true);
  730. dobreak->set_disabled(false);
  731. tabs->set_current_tab(0);
  732. _set_reason_text(TTR("Child Process Connected"), MESSAGE_SUCCESS);
  733. profiler->clear();
  734. inspect_scene_tree->clear();
  735. le_set->set_disabled(true);
  736. le_clear->set_disabled(false);
  737. error_list->clear();
  738. error_stack->clear();
  739. error_count = 0;
  740. profiler_signature.clear();
  741. //live_edit_root->set_text("/root");
  742. EditorNode::get_singleton()->get_pause_button()->set_pressed(false);
  743. EditorNode::get_singleton()->get_pause_button()->set_disabled(false);
  744. update_live_edit_root();
  745. if (profiler->is_profiling()) {
  746. _profiler_activate(true);
  747. }
  748. } else {
  749. break;
  750. }
  751. };
  752. if (!connection->is_connected_to_host()) {
  753. stop();
  754. editor->notify_child_process_exited(); //somehow, exited
  755. break;
  756. };
  757. if (ppeer->get_available_packet_count() <= 0) {
  758. break;
  759. };
  760. while (ppeer->get_available_packet_count() > 0) {
  761. if (pending_in_queue) {
  762. int todo = MIN(ppeer->get_available_packet_count(), pending_in_queue);
  763. for (int i = 0; i < todo; i++) {
  764. Variant cmd;
  765. Error ret = ppeer->get_var(cmd);
  766. if (ret != OK) {
  767. stop();
  768. ERR_FAIL_COND(ret != OK);
  769. }
  770. message.push_back(cmd);
  771. pending_in_queue--;
  772. }
  773. if (pending_in_queue == 0) {
  774. _parse_message(message_type, message);
  775. message.clear();
  776. }
  777. } else {
  778. if (ppeer->get_available_packet_count() >= 2) {
  779. Variant cmd;
  780. Error ret = ppeer->get_var(cmd);
  781. if (ret != OK) {
  782. stop();
  783. ERR_FAIL_COND(ret != OK);
  784. }
  785. if (cmd.get_type() != Variant::STRING) {
  786. stop();
  787. ERR_FAIL_COND(cmd.get_type() != Variant::STRING);
  788. }
  789. message_type = cmd;
  790. //print_line("GOT: "+message_type);
  791. ret = ppeer->get_var(cmd);
  792. if (ret != OK) {
  793. stop();
  794. ERR_FAIL_COND(ret != OK);
  795. }
  796. if (cmd.get_type() != Variant::INT) {
  797. stop();
  798. ERR_FAIL_COND(cmd.get_type() != Variant::INT);
  799. }
  800. pending_in_queue = cmd;
  801. if (pending_in_queue == 0) {
  802. _parse_message(message_type, Array());
  803. message.clear();
  804. }
  805. } else {
  806. break;
  807. }
  808. }
  809. }
  810. } break;
  811. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  812. tabs->add_style_override("panel", editor->get_gui_base()->get_stylebox("DebuggerPanel", "EditorStyles"));
  813. tabs->add_style_override("tab_fg", editor->get_gui_base()->get_stylebox("DebuggerTabFG", "EditorStyles"));
  814. tabs->add_style_override("tab_bg", editor->get_gui_base()->get_stylebox("DebuggerTabBG", "EditorStyles"));
  815. } break;
  816. }
  817. }
  818. void ScriptEditorDebugger::start() {
  819. stop();
  820. if (is_visible_in_tree()) {
  821. EditorNode::get_singleton()->make_bottom_panel_item_visible(this);
  822. }
  823. perf_history.clear();
  824. for (int i = 0; i < Performance::MONITOR_MAX; i++) {
  825. perf_max[i] = 0;
  826. }
  827. int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port");
  828. if (server->listen(remote_port) != OK) {
  829. EditorNode::get_log()->add_message(String("** Error listening on port ") + itos(remote_port) + String(" **"));
  830. return;
  831. }
  832. set_process(true);
  833. }
  834. void ScriptEditorDebugger::pause() {
  835. }
  836. void ScriptEditorDebugger::unpause() {
  837. }
  838. void ScriptEditorDebugger::stop() {
  839. set_process(false);
  840. server->stop();
  841. ppeer->set_stream_peer(Ref<StreamPeer>());
  842. if (connection.is_valid()) {
  843. EditorNode::get_log()->add_message("** Debug Process Stopped **");
  844. connection.unref();
  845. }
  846. pending_in_queue = 0;
  847. message.clear();
  848. node_path_cache.clear();
  849. res_path_cache.clear();
  850. profiler_signature.clear();
  851. le_clear->set_disabled(false);
  852. le_set->set_disabled(true);
  853. profiler->set_enabled(true);
  854. inspect_properties->edit(NULL);
  855. inspect_scene_tree->clear();
  856. EditorNode::get_singleton()->get_pause_button()->set_pressed(false);
  857. EditorNode::get_singleton()->get_pause_button()->set_disabled(true);
  858. if (hide_on_stop) {
  859. if (is_visible_in_tree())
  860. EditorNode::get_singleton()->hide_bottom_panel();
  861. emit_signal("show_debugger", false);
  862. }
  863. }
  864. void ScriptEditorDebugger::_profiler_activate(bool p_enable) {
  865. if (!connection.is_valid())
  866. return;
  867. if (p_enable) {
  868. profiler_signature.clear();
  869. Array msg;
  870. msg.push_back("start_profiling");
  871. int max_funcs = EditorSettings::get_singleton()->get("debugger/profiler_frame_max_functions");
  872. max_funcs = CLAMP(max_funcs, 16, 512);
  873. msg.push_back(max_funcs);
  874. ppeer->put_var(msg);
  875. print_line("BEGIN PROFILING!");
  876. } else {
  877. Array msg;
  878. msg.push_back("stop_profiling");
  879. ppeer->put_var(msg);
  880. print_line("END PROFILING!");
  881. }
  882. }
  883. void ScriptEditorDebugger::_profiler_seeked() {
  884. if (!connection.is_valid() || !connection->is_connected_to_host())
  885. return;
  886. if (breaked)
  887. return;
  888. debug_break();
  889. }
  890. void ScriptEditorDebugger::_stack_dump_frame_selected() {
  891. TreeItem *ti = stack_dump->get_selected();
  892. if (!ti)
  893. return;
  894. Dictionary d = ti->get_metadata(0);
  895. stack_script = ResourceLoader::load(d["file"]);
  896. emit_signal("goto_script_line", stack_script, int(d["line"]) - 1);
  897. stack_script.unref();
  898. ERR_FAIL_COND(connection.is_null());
  899. ERR_FAIL_COND(!connection->is_connected_to_host());
  900. ///
  901. Array msg;
  902. msg.push_back("get_stack_frame_vars");
  903. msg.push_back(d["frame"]);
  904. ppeer->put_var(msg);
  905. }
  906. void ScriptEditorDebugger::_output_clear() {
  907. //output->clear();
  908. //output->push_color(Color(0,0,0));
  909. }
  910. String ScriptEditorDebugger::get_var_value(const String &p_var) const {
  911. if (!breaked)
  912. return String();
  913. return variables->get_var_value(p_var);
  914. }
  915. int ScriptEditorDebugger::_get_node_path_cache(const NodePath &p_path) {
  916. const int *r = node_path_cache.getptr(p_path);
  917. if (r)
  918. return *r;
  919. last_path_id++;
  920. node_path_cache[p_path] = last_path_id;
  921. Array msg;
  922. msg.push_back("live_node_path");
  923. msg.push_back(p_path);
  924. msg.push_back(last_path_id);
  925. ppeer->put_var(msg);
  926. return last_path_id;
  927. }
  928. int ScriptEditorDebugger::_get_res_path_cache(const String &p_path) {
  929. Map<String, int>::Element *E = res_path_cache.find(p_path);
  930. if (E)
  931. return E->get();
  932. last_path_id++;
  933. res_path_cache[p_path] = last_path_id;
  934. Array msg;
  935. msg.push_back("live_res_path");
  936. msg.push_back(p_path);
  937. msg.push_back(last_path_id);
  938. ppeer->put_var(msg);
  939. return last_path_id;
  940. }
  941. void ScriptEditorDebugger::_method_changed(Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE) {
  942. if (!p_base || !live_debug || !connection.is_valid() || !editor->get_edited_scene())
  943. return;
  944. Node *node = Object::cast_to<Node>(p_base);
  945. VARIANT_ARGPTRS
  946. for (int i = 0; i < VARIANT_ARG_MAX; i++) {
  947. //no pointers, sorry
  948. if (argptr[i] && (argptr[i]->get_type() == Variant::OBJECT || argptr[i]->get_type() == Variant::_RID))
  949. return;
  950. }
  951. if (node) {
  952. NodePath path = editor->get_edited_scene()->get_path_to(node);
  953. int pathid = _get_node_path_cache(path);
  954. Array msg;
  955. msg.push_back("live_node_call");
  956. msg.push_back(pathid);
  957. msg.push_back(p_name);
  958. for (int i = 0; i < VARIANT_ARG_MAX; i++) {
  959. //no pointers, sorry
  960. msg.push_back(*argptr[i]);
  961. }
  962. ppeer->put_var(msg);
  963. return;
  964. }
  965. Resource *res = Object::cast_to<Resource>(p_base);
  966. if (res && res->get_path() != String()) {
  967. String respath = res->get_path();
  968. int pathid = _get_res_path_cache(respath);
  969. Array msg;
  970. msg.push_back("live_res_call");
  971. msg.push_back(pathid);
  972. msg.push_back(p_name);
  973. for (int i = 0; i < VARIANT_ARG_MAX; i++) {
  974. //no pointers, sorry
  975. msg.push_back(*argptr[i]);
  976. }
  977. ppeer->put_var(msg);
  978. return;
  979. }
  980. //print_line("method");
  981. }
  982. void ScriptEditorDebugger::_property_changed(Object *p_base, const StringName &p_property, const Variant &p_value) {
  983. if (!p_base || !live_debug || !connection.is_valid() || !editor->get_edited_scene())
  984. return;
  985. Node *node = Object::cast_to<Node>(p_base);
  986. if (node) {
  987. NodePath path = editor->get_edited_scene()->get_path_to(node);
  988. int pathid = _get_node_path_cache(path);
  989. if (p_value.is_ref()) {
  990. Ref<Resource> res = p_value;
  991. if (res.is_valid() && res->get_path() != String()) {
  992. Array msg;
  993. msg.push_back("live_node_prop_res");
  994. msg.push_back(pathid);
  995. msg.push_back(p_property);
  996. msg.push_back(res->get_path());
  997. ppeer->put_var(msg);
  998. }
  999. } else {
  1000. Array msg;
  1001. msg.push_back("live_node_prop");
  1002. msg.push_back(pathid);
  1003. msg.push_back(p_property);
  1004. msg.push_back(p_value);
  1005. ppeer->put_var(msg);
  1006. }
  1007. return;
  1008. }
  1009. Resource *res = Object::cast_to<Resource>(p_base);
  1010. if (res && res->get_path() != String()) {
  1011. String respath = res->get_path();
  1012. int pathid = _get_res_path_cache(respath);
  1013. if (p_value.is_ref()) {
  1014. Ref<Resource> res = p_value;
  1015. if (res.is_valid() && res->get_path() != String()) {
  1016. Array msg;
  1017. msg.push_back("live_res_prop_res");
  1018. msg.push_back(pathid);
  1019. msg.push_back(p_property);
  1020. msg.push_back(res->get_path());
  1021. ppeer->put_var(msg);
  1022. }
  1023. } else {
  1024. Array msg;
  1025. msg.push_back("live_res_prop");
  1026. msg.push_back(pathid);
  1027. msg.push_back(p_property);
  1028. msg.push_back(p_value);
  1029. ppeer->put_var(msg);
  1030. }
  1031. return;
  1032. }
  1033. //print_line("prop");
  1034. }
  1035. void ScriptEditorDebugger::_method_changeds(void *p_ud, Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE) {
  1036. ScriptEditorDebugger *sed = (ScriptEditorDebugger *)p_ud;
  1037. sed->_method_changed(p_base, p_name, VARIANT_ARG_PASS);
  1038. }
  1039. void ScriptEditorDebugger::_property_changeds(void *p_ud, Object *p_base, const StringName &p_property, const Variant &p_value) {
  1040. ScriptEditorDebugger *sed = (ScriptEditorDebugger *)p_ud;
  1041. sed->_property_changed(p_base, p_property, p_value);
  1042. }
  1043. void ScriptEditorDebugger::set_live_debugging(bool p_enable) {
  1044. live_debug = p_enable;
  1045. }
  1046. void ScriptEditorDebugger::_live_edit_set() {
  1047. if (!connection.is_valid())
  1048. return;
  1049. TreeItem *ti = inspect_scene_tree->get_selected();
  1050. if (!ti)
  1051. return;
  1052. String path;
  1053. while (ti) {
  1054. String lp = ti->get_text(0);
  1055. path = "/" + lp + path;
  1056. ti = ti->get_parent();
  1057. }
  1058. NodePath np = path;
  1059. editor->get_editor_data().set_edited_scene_live_edit_root(np);
  1060. update_live_edit_root();
  1061. }
  1062. void ScriptEditorDebugger::_live_edit_clear() {
  1063. NodePath np = NodePath("/root");
  1064. editor->get_editor_data().set_edited_scene_live_edit_root(np);
  1065. update_live_edit_root();
  1066. }
  1067. void ScriptEditorDebugger::update_live_edit_root() {
  1068. NodePath np = editor->get_editor_data().get_edited_scene_live_edit_root();
  1069. if (connection.is_valid()) {
  1070. Array msg;
  1071. msg.push_back("live_set_root");
  1072. msg.push_back(np);
  1073. if (editor->get_edited_scene())
  1074. msg.push_back(editor->get_edited_scene()->get_filename());
  1075. else
  1076. msg.push_back("");
  1077. ppeer->put_var(msg);
  1078. }
  1079. live_edit_root->set_text(np);
  1080. }
  1081. void ScriptEditorDebugger::live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name) {
  1082. if (live_debug && connection.is_valid()) {
  1083. Array msg;
  1084. msg.push_back("live_create_node");
  1085. msg.push_back(p_parent);
  1086. msg.push_back(p_type);
  1087. msg.push_back(p_name);
  1088. ppeer->put_var(msg);
  1089. }
  1090. }
  1091. void ScriptEditorDebugger::live_debug_instance_node(const NodePath &p_parent, const String &p_path, const String &p_name) {
  1092. if (live_debug && connection.is_valid()) {
  1093. Array msg;
  1094. msg.push_back("live_instance_node");
  1095. msg.push_back(p_parent);
  1096. msg.push_back(p_path);
  1097. msg.push_back(p_name);
  1098. ppeer->put_var(msg);
  1099. }
  1100. }
  1101. void ScriptEditorDebugger::live_debug_remove_node(const NodePath &p_at) {
  1102. if (live_debug && connection.is_valid()) {
  1103. Array msg;
  1104. msg.push_back("live_remove_node");
  1105. msg.push_back(p_at);
  1106. ppeer->put_var(msg);
  1107. }
  1108. }
  1109. void ScriptEditorDebugger::live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id) {
  1110. if (live_debug && connection.is_valid()) {
  1111. Array msg;
  1112. msg.push_back("live_remove_and_keep_node");
  1113. msg.push_back(p_at);
  1114. msg.push_back(p_keep_id);
  1115. ppeer->put_var(msg);
  1116. }
  1117. }
  1118. void ScriptEditorDebugger::live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos) {
  1119. if (live_debug && connection.is_valid()) {
  1120. Array msg;
  1121. msg.push_back("live_restore_node");
  1122. msg.push_back(p_id);
  1123. msg.push_back(p_at);
  1124. msg.push_back(p_at_pos);
  1125. ppeer->put_var(msg);
  1126. }
  1127. }
  1128. void ScriptEditorDebugger::live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name) {
  1129. if (live_debug && connection.is_valid()) {
  1130. Array msg;
  1131. msg.push_back("live_duplicate_node");
  1132. msg.push_back(p_at);
  1133. msg.push_back(p_new_name);
  1134. ppeer->put_var(msg);
  1135. }
  1136. }
  1137. void ScriptEditorDebugger::live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos) {
  1138. if (live_debug && connection.is_valid()) {
  1139. Array msg;
  1140. msg.push_back("live_reparent_node");
  1141. msg.push_back(p_at);
  1142. msg.push_back(p_new_place);
  1143. msg.push_back(p_new_name);
  1144. msg.push_back(p_at_pos);
  1145. ppeer->put_var(msg);
  1146. }
  1147. }
  1148. void ScriptEditorDebugger::set_breakpoint(const String &p_path, int p_line, bool p_enabled) {
  1149. if (connection.is_valid()) {
  1150. Array msg;
  1151. msg.push_back("breakpoint");
  1152. msg.push_back(p_path);
  1153. msg.push_back(p_line);
  1154. msg.push_back(p_enabled);
  1155. ppeer->put_var(msg);
  1156. }
  1157. }
  1158. void ScriptEditorDebugger::reload_scripts() {
  1159. if (connection.is_valid()) {
  1160. Array msg;
  1161. msg.push_back("reload_scripts");
  1162. ppeer->put_var(msg);
  1163. }
  1164. }
  1165. void ScriptEditorDebugger::_error_selected(int p_idx) {
  1166. error_stack->clear();
  1167. Array st = error_list->get_item_metadata(p_idx);
  1168. for (int i = 0; i < st.size(); i += 2) {
  1169. String script = st[i];
  1170. int line = st[i + 1];
  1171. Array md;
  1172. md.push_back(st[i]);
  1173. md.push_back(st[i + 1]);
  1174. String str = script.get_file() + ":" + itos(line);
  1175. error_stack->add_item(str);
  1176. error_stack->set_item_metadata(error_stack->get_item_count() - 1, md);
  1177. error_stack->set_item_tooltip(error_stack->get_item_count() - 1, TTR("File:") + " " + String(st[i]) + "\n" + TTR("Line:") + " " + itos(line));
  1178. }
  1179. }
  1180. void ScriptEditorDebugger::_error_stack_selected(int p_idx) {
  1181. Array arr = error_stack->get_item_metadata(p_idx);
  1182. if (arr.size() != 2)
  1183. return;
  1184. Ref<Script> s = ResourceLoader::load(arr[0]);
  1185. emit_signal("goto_script_line", s, int(arr[1]) - 1);
  1186. }
  1187. void ScriptEditorDebugger::set_hide_on_stop(bool p_hide) {
  1188. hide_on_stop = p_hide;
  1189. }
  1190. bool ScriptEditorDebugger::get_debug_with_external_editor() const {
  1191. return enable_external_editor;
  1192. }
  1193. void ScriptEditorDebugger::set_debug_with_external_editor(bool p_enabled) {
  1194. enable_external_editor = p_enabled;
  1195. }
  1196. Ref<Script> ScriptEditorDebugger::get_dump_stack_script() const {
  1197. return stack_script;
  1198. }
  1199. void ScriptEditorDebugger::_paused() {
  1200. ERR_FAIL_COND(connection.is_null());
  1201. ERR_FAIL_COND(!connection->is_connected_to_host());
  1202. if (!breaked && EditorNode::get_singleton()->get_pause_button()->is_pressed()) {
  1203. debug_break();
  1204. }
  1205. if (breaked && !EditorNode::get_singleton()->get_pause_button()->is_pressed()) {
  1206. debug_continue();
  1207. }
  1208. }
  1209. void ScriptEditorDebugger::_bind_methods() {
  1210. ClassDB::bind_method(D_METHOD("_stack_dump_frame_selected"), &ScriptEditorDebugger::_stack_dump_frame_selected);
  1211. ClassDB::bind_method(D_METHOD("debug_next"), &ScriptEditorDebugger::debug_next);
  1212. ClassDB::bind_method(D_METHOD("debug_step"), &ScriptEditorDebugger::debug_step);
  1213. ClassDB::bind_method(D_METHOD("debug_break"), &ScriptEditorDebugger::debug_break);
  1214. ClassDB::bind_method(D_METHOD("debug_continue"), &ScriptEditorDebugger::debug_continue);
  1215. ClassDB::bind_method(D_METHOD("_output_clear"), &ScriptEditorDebugger::_output_clear);
  1216. ClassDB::bind_method(D_METHOD("_performance_draw"), &ScriptEditorDebugger::_performance_draw);
  1217. ClassDB::bind_method(D_METHOD("_performance_select"), &ScriptEditorDebugger::_performance_select);
  1218. ClassDB::bind_method(D_METHOD("_scene_tree_request"), &ScriptEditorDebugger::_scene_tree_request);
  1219. ClassDB::bind_method(D_METHOD("_video_mem_request"), &ScriptEditorDebugger::_video_mem_request);
  1220. ClassDB::bind_method(D_METHOD("_live_edit_set"), &ScriptEditorDebugger::_live_edit_set);
  1221. ClassDB::bind_method(D_METHOD("_live_edit_clear"), &ScriptEditorDebugger::_live_edit_clear);
  1222. ClassDB::bind_method(D_METHOD("_error_selected"), &ScriptEditorDebugger::_error_selected);
  1223. ClassDB::bind_method(D_METHOD("_error_stack_selected"), &ScriptEditorDebugger::_error_stack_selected);
  1224. ClassDB::bind_method(D_METHOD("_profiler_activate"), &ScriptEditorDebugger::_profiler_activate);
  1225. ClassDB::bind_method(D_METHOD("_profiler_seeked"), &ScriptEditorDebugger::_profiler_seeked);
  1226. ClassDB::bind_method(D_METHOD("_paused"), &ScriptEditorDebugger::_paused);
  1227. ClassDB::bind_method(D_METHOD("_scene_tree_selected"), &ScriptEditorDebugger::_scene_tree_selected);
  1228. ClassDB::bind_method(D_METHOD("_scene_tree_folded"), &ScriptEditorDebugger::_scene_tree_folded);
  1229. ClassDB::bind_method(D_METHOD("live_debug_create_node"), &ScriptEditorDebugger::live_debug_create_node);
  1230. ClassDB::bind_method(D_METHOD("live_debug_instance_node"), &ScriptEditorDebugger::live_debug_instance_node);
  1231. ClassDB::bind_method(D_METHOD("live_debug_remove_node"), &ScriptEditorDebugger::live_debug_remove_node);
  1232. ClassDB::bind_method(D_METHOD("live_debug_remove_and_keep_node"), &ScriptEditorDebugger::live_debug_remove_and_keep_node);
  1233. ClassDB::bind_method(D_METHOD("live_debug_restore_node"), &ScriptEditorDebugger::live_debug_restore_node);
  1234. ClassDB::bind_method(D_METHOD("live_debug_duplicate_node"), &ScriptEditorDebugger::live_debug_duplicate_node);
  1235. ClassDB::bind_method(D_METHOD("live_debug_reparent_node"), &ScriptEditorDebugger::live_debug_reparent_node);
  1236. ClassDB::bind_method(D_METHOD("_scene_tree_property_select_object"), &ScriptEditorDebugger::_scene_tree_property_select_object);
  1237. ClassDB::bind_method(D_METHOD("_scene_tree_property_value_edited"), &ScriptEditorDebugger::_scene_tree_property_value_edited);
  1238. ADD_SIGNAL(MethodInfo("goto_script_line"));
  1239. ADD_SIGNAL(MethodInfo("breaked", PropertyInfo(Variant::BOOL, "reallydid"), PropertyInfo(Variant::BOOL, "can_debug")));
  1240. ADD_SIGNAL(MethodInfo("show_debugger", PropertyInfo(Variant::BOOL, "reallydid")));
  1241. }
  1242. ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) {
  1243. ppeer = Ref<PacketPeerStream>(memnew(PacketPeerStream));
  1244. ppeer->set_input_buffer_max_size(1024 * 1024 * 8); //8mb should be enough
  1245. editor = p_editor;
  1246. tabs = memnew(TabContainer);
  1247. tabs->set_tab_align(TabContainer::ALIGN_LEFT);
  1248. tabs->add_style_override("panel", editor->get_gui_base()->get_stylebox("DebuggerPanel", "EditorStyles"));
  1249. tabs->add_style_override("tab_fg", editor->get_gui_base()->get_stylebox("DebuggerTabFG", "EditorStyles"));
  1250. tabs->add_style_override("tab_bg", editor->get_gui_base()->get_stylebox("DebuggerTabBG", "EditorStyles"));
  1251. tabs->set_v_size_flags(SIZE_EXPAND_FILL);
  1252. tabs->set_area_as_parent_rect();
  1253. add_child(tabs);
  1254. { //debugger
  1255. VBoxContainer *vbc = memnew(VBoxContainer);
  1256. vbc->set_name(TTR("Debugger"));
  1257. //tabs->add_child(vbc);
  1258. Control *dbg = vbc;
  1259. HBoxContainer *hbc = memnew(HBoxContainer);
  1260. vbc->add_child(hbc);
  1261. reason = memnew(Label);
  1262. reason->set_text("");
  1263. hbc->add_child(reason);
  1264. reason->set_h_size_flags(SIZE_EXPAND_FILL);
  1265. hbc->add_child(memnew(VSeparator));
  1266. step = memnew(ToolButton);
  1267. hbc->add_child(step);
  1268. step->set_tooltip(TTR("Step Into"));
  1269. step->connect("pressed", this, "debug_step");
  1270. next = memnew(ToolButton);
  1271. hbc->add_child(next);
  1272. next->set_tooltip(TTR("Step Over"));
  1273. next->connect("pressed", this, "debug_next");
  1274. hbc->add_child(memnew(VSeparator));
  1275. dobreak = memnew(ToolButton);
  1276. hbc->add_child(dobreak);
  1277. dobreak->set_tooltip(TTR("Break"));
  1278. dobreak->connect("pressed", this, "debug_break");
  1279. docontinue = memnew(ToolButton);
  1280. hbc->add_child(docontinue);
  1281. docontinue->set_tooltip(TTR("Continue"));
  1282. docontinue->connect("pressed", this, "debug_continue");
  1283. back = memnew(Button);
  1284. hbc->add_child(back);
  1285. back->set_tooltip(TTR("Inspect Previous Instance"));
  1286. back->hide();
  1287. forward = memnew(Button);
  1288. hbc->add_child(forward);
  1289. forward->set_tooltip(TTR("Inspect Next Instance"));
  1290. forward->hide();
  1291. HSplitContainer *sc = memnew(HSplitContainer);
  1292. vbc->add_child(sc);
  1293. sc->set_v_size_flags(SIZE_EXPAND_FILL);
  1294. stack_dump = memnew(Tree);
  1295. stack_dump->set_columns(1);
  1296. stack_dump->set_column_titles_visible(true);
  1297. stack_dump->set_column_title(0, TTR("Stack Frames"));
  1298. stack_dump->set_h_size_flags(SIZE_EXPAND_FILL);
  1299. stack_dump->set_hide_root(true);
  1300. stack_dump->connect("cell_selected", this, "_stack_dump_frame_selected");
  1301. sc->add_child(stack_dump);
  1302. inspector = memnew(PropertyEditor);
  1303. inspector->set_h_size_flags(SIZE_EXPAND_FILL);
  1304. inspector->hide_top_label();
  1305. inspector->get_scene_tree()->set_column_title(0, TTR("Variable"));
  1306. inspector->set_enable_capitalize_paths(false);
  1307. inspector->set_read_only(true);
  1308. inspector->connect("object_id_selected", this, "_scene_tree_property_select_object");
  1309. sc->add_child(inspector);
  1310. server = TCP_Server::create_ref();
  1311. pending_in_queue = 0;
  1312. variables = memnew(ScriptEditorDebuggerVariables);
  1313. breaked = false;
  1314. tabs->add_child(dbg);
  1315. }
  1316. { //errors
  1317. error_split = memnew(HSplitContainer);
  1318. VBoxContainer *errvb = memnew(VBoxContainer);
  1319. errvb->set_h_size_flags(SIZE_EXPAND_FILL);
  1320. error_list = memnew(ItemList);
  1321. errvb->add_margin_child(TTR("Errors:"), error_list, true);
  1322. error_split->add_child(errvb);
  1323. errvb = memnew(VBoxContainer);
  1324. errvb->set_h_size_flags(SIZE_EXPAND_FILL);
  1325. error_stack = memnew(ItemList);
  1326. errvb->add_margin_child(TTR("Stack Trace (if applicable):"), error_stack, true);
  1327. error_split->add_child(errvb);
  1328. error_split->set_name(TTR("Errors"));
  1329. tabs->add_child(error_split);
  1330. }
  1331. { // inquire
  1332. inspect_info = memnew(HSplitContainer);
  1333. inspect_info->set_name(TTR("Remote Inspector"));
  1334. tabs->add_child(inspect_info);
  1335. VBoxContainer *info_left = memnew(VBoxContainer);
  1336. info_left->set_h_size_flags(SIZE_EXPAND_FILL);
  1337. inspect_info->add_child(info_left);
  1338. inspect_scene_tree = memnew(Tree);
  1339. info_left->add_margin_child(TTR("Live Scene Tree:"), inspect_scene_tree, true);
  1340. inspect_scene_tree->connect("cell_selected", this, "_scene_tree_selected");
  1341. inspect_scene_tree->connect("item_collapsed", this, "_scene_tree_folded");
  1342. //
  1343. VBoxContainer *info_right = memnew(VBoxContainer);
  1344. info_right->set_h_size_flags(SIZE_EXPAND_FILL);
  1345. inspect_info->add_child(info_right);
  1346. inspect_properties = memnew(PropertyEditor);
  1347. inspect_properties->hide_top_label();
  1348. inspect_properties->set_show_categories(true);
  1349. inspect_properties->connect("object_id_selected", this, "_scene_tree_property_select_object");
  1350. info_right->add_margin_child(TTR("Remote Object Properties: "), inspect_properties, true);
  1351. inspect_scene_tree_timeout = EDITOR_DEF("debugger/scene_tree_refresh_interval", 1.0);
  1352. inspect_edited_object_timeout = EDITOR_DEF("debugger/remote_inspect_refresh_interval", 0.2);
  1353. inspected_object_id = 0;
  1354. updating_scene_tree = false;
  1355. inspected_object = memnew(ScriptEditorDebuggerInspectedObject);
  1356. inspected_object->connect("value_edited", this, "_scene_tree_property_value_edited");
  1357. }
  1358. { //profiler
  1359. profiler = memnew(EditorProfiler);
  1360. profiler->set_name(TTR("Profiler"));
  1361. tabs->add_child(profiler);
  1362. profiler->connect("enable_profiling", this, "_profiler_activate");
  1363. profiler->connect("break_request", this, "_profiler_seeked");
  1364. }
  1365. { //monitors
  1366. HSplitContainer *hsp = memnew(HSplitContainer);
  1367. perf_monitors = memnew(Tree);
  1368. perf_monitors->set_columns(2);
  1369. perf_monitors->set_column_title(0, TTR("Monitor"));
  1370. perf_monitors->set_column_title(1, TTR("Value"));
  1371. perf_monitors->set_column_titles_visible(true);
  1372. hsp->add_child(perf_monitors);
  1373. perf_monitors->set_select_mode(Tree::SELECT_MULTI);
  1374. perf_monitors->connect("multi_selected", this, "_performance_select");
  1375. perf_draw = memnew(Control);
  1376. perf_draw->connect("draw", this, "_performance_draw");
  1377. hsp->add_child(perf_draw);
  1378. hsp->set_name(TTR("Monitors"));
  1379. hsp->set_split_offset(300);
  1380. tabs->add_child(hsp);
  1381. perf_max.resize(Performance::MONITOR_MAX);
  1382. Map<String, TreeItem *> bases;
  1383. TreeItem *root = perf_monitors->create_item();
  1384. perf_monitors->set_hide_root(true);
  1385. for (int i = 0; i < Performance::MONITOR_MAX; i++) {
  1386. String n = Performance::get_singleton()->get_monitor_name(Performance::Monitor(i));
  1387. String base = n.get_slice("/", 0);
  1388. String name = n.get_slice("/", 1);
  1389. if (!bases.has(base)) {
  1390. TreeItem *b = perf_monitors->create_item(root);
  1391. b->set_text(0, base.capitalize());
  1392. b->set_editable(0, false);
  1393. b->set_selectable(0, false);
  1394. bases[base] = b;
  1395. }
  1396. TreeItem *it = perf_monitors->create_item(bases[base]);
  1397. it->set_editable(0, false);
  1398. it->set_selectable(0, true);
  1399. it->set_text(0, name.capitalize());
  1400. perf_items.push_back(it);
  1401. perf_max[i] = 0;
  1402. }
  1403. }
  1404. { //vmem inspect
  1405. VBoxContainer *vmem_vb = memnew(VBoxContainer);
  1406. HBoxContainer *vmem_hb = memnew(HBoxContainer);
  1407. Label *vmlb = memnew(Label(TTR("List of Video Memory Usage by Resource:") + " "));
  1408. vmlb->set_h_size_flags(SIZE_EXPAND_FILL);
  1409. vmem_hb->add_child(vmlb);
  1410. vmem_hb->add_child(memnew(Label(TTR("Total:") + " ")));
  1411. vmem_total = memnew(LineEdit);
  1412. vmem_total->set_editable(false);
  1413. vmem_total->set_custom_minimum_size(Size2(100, 1) * EDSCALE);
  1414. vmem_hb->add_child(vmem_total);
  1415. vmem_refresh = memnew(ToolButton);
  1416. vmem_hb->add_child(vmem_refresh);
  1417. vmem_vb->add_child(vmem_hb);
  1418. vmem_refresh->connect("pressed", this, "_video_mem_request");
  1419. VBoxContainer *vmmc = memnew(VBoxContainer);
  1420. vmem_tree = memnew(Tree);
  1421. vmem_tree->set_v_size_flags(SIZE_EXPAND_FILL);
  1422. vmem_tree->set_h_size_flags(SIZE_EXPAND_FILL);
  1423. vmmc->add_child(vmem_tree);
  1424. vmmc->set_v_size_flags(SIZE_EXPAND_FILL);
  1425. vmem_vb->add_child(vmmc);
  1426. vmem_vb->set_name(TTR("Video Mem"));
  1427. vmem_tree->set_columns(4);
  1428. vmem_tree->set_column_titles_visible(true);
  1429. vmem_tree->set_column_title(0, TTR("Resource Path"));
  1430. vmem_tree->set_column_expand(0, true);
  1431. vmem_tree->set_column_expand(1, false);
  1432. vmem_tree->set_column_title(1, TTR("Type"));
  1433. vmem_tree->set_column_min_width(1, 100);
  1434. vmem_tree->set_column_expand(2, false);
  1435. vmem_tree->set_column_title(2, TTR("Format"));
  1436. vmem_tree->set_column_min_width(2, 150);
  1437. vmem_tree->set_column_expand(3, false);
  1438. vmem_tree->set_column_title(3, TTR("Usage"));
  1439. vmem_tree->set_column_min_width(3, 80);
  1440. vmem_tree->set_hide_root(true);
  1441. tabs->add_child(vmem_vb);
  1442. }
  1443. { // misc
  1444. GridContainer *info_left = memnew(GridContainer);
  1445. info_left->set_columns(2);
  1446. info_left->set_name(TTR("Misc"));
  1447. tabs->add_child(info_left);
  1448. clicked_ctrl = memnew(LineEdit);
  1449. clicked_ctrl->set_h_size_flags(SIZE_EXPAND_FILL);
  1450. info_left->add_child(memnew(Label(TTR("Clicked Control:"))));
  1451. info_left->add_child(clicked_ctrl);
  1452. clicked_ctrl_type = memnew(LineEdit);
  1453. info_left->add_child(memnew(Label(TTR("Clicked Control Type:"))));
  1454. info_left->add_child(clicked_ctrl_type);
  1455. live_edit_root = memnew(LineEdit);
  1456. live_edit_root->set_h_size_flags(SIZE_EXPAND_FILL);
  1457. {
  1458. HBoxContainer *lehb = memnew(HBoxContainer);
  1459. Label *l = memnew(Label(TTR("Live Edit Root:")));
  1460. info_left->add_child(l);
  1461. lehb->add_child(live_edit_root);
  1462. le_set = memnew(Button(TTR("Set From Tree")));
  1463. lehb->add_child(le_set);
  1464. le_clear = memnew(Button(TTR("Clear")));
  1465. lehb->add_child(le_clear);
  1466. info_left->add_child(lehb);
  1467. le_set->set_disabled(true);
  1468. le_clear->set_disabled(true);
  1469. }
  1470. }
  1471. msgdialog = memnew(AcceptDialog);
  1472. add_child(msgdialog);
  1473. p_editor->get_undo_redo()->set_method_notify_callback(_method_changeds, this);
  1474. p_editor->get_undo_redo()->set_property_notify_callback(_property_changeds, this);
  1475. live_debug = false;
  1476. last_path_id = false;
  1477. error_count = 0;
  1478. hide_on_stop = true;
  1479. enable_external_editor = false;
  1480. last_error_count = 0;
  1481. EditorNode::get_singleton()->get_pause_button()->connect("pressed", this, "_paused");
  1482. }
  1483. ScriptEditorDebugger::~ScriptEditorDebugger() {
  1484. //inspector->edit(NULL);
  1485. memdelete(variables);
  1486. ppeer->set_stream_peer(Ref<StreamPeer>());
  1487. server->stop();
  1488. memdelete(inspected_object);
  1489. }