script_editor_debugger.cpp 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916
  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-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. Ref<Font> graph_font = get_font("font", "TextEdit");
  616. if (which.empty()) {
  617. perf_draw->draw_string(graph_font, Point2(0, graph_font->get_ascent()), TTR("Pick one or more items from the list to display the graph."), get_color("font_color", "Label"), perf_draw->get_size().x);
  618. return;
  619. }
  620. Ref<StyleBox> graph_sb = get_stylebox("normal", "TextEdit");
  621. int cols = Math::ceil(Math::sqrt((float)which.size()));
  622. int rows = Math::ceil((float)which.size() / cols);
  623. if (which.size() == 1)
  624. rows = 1;
  625. int margin = 3;
  626. int point_sep = 5;
  627. Size2i s = Size2i(perf_draw->get_size()) / Size2i(cols, rows);
  628. for (int i = 0; i < which.size(); i++) {
  629. Point2i p(i % cols, i / cols);
  630. Rect2i r(p * s, s);
  631. r.position += Point2(margin, margin);
  632. r.size -= Point2(margin, margin) * 2.0;
  633. perf_draw->draw_style_box(graph_sb, r);
  634. r.position += graph_sb->get_offset();
  635. r.size -= graph_sb->get_minimum_size();
  636. int pi = which[i];
  637. Color c = get_color("success_color", "Editor");
  638. c.set_hsv(Math::fmod(c.get_h() + pi * 0.7654, 1), c.get_s(), c.get_v());
  639. //c = c.linear_interpolate(get_color("base_color", "Editor"), 0.9);
  640. c.a = 0.8;
  641. perf_draw->draw_string(graph_font, r.position + Point2(0, graph_font->get_ascent()), perf_items[pi]->get_text(0), c, r.size.x);
  642. c.a = 0.6;
  643. 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);
  644. float spacing = point_sep / float(cols);
  645. float from = r.size.width;
  646. List<Vector<float> >::Element *E = perf_history.front();
  647. float prev = -1;
  648. while (from >= 0 && E) {
  649. float m = perf_max[pi];
  650. if (m == 0)
  651. m = 0.00001;
  652. float h = E->get()[pi] / m;
  653. h = (1.0 - h) * r.size.y;
  654. c.a = 0.7;
  655. if (E != perf_history.front())
  656. perf_draw->draw_line(r.position + Point2(from, h), r.position + Point2(from + spacing, prev), c, 2.0);
  657. prev = h;
  658. E = E->next();
  659. from -= spacing;
  660. }
  661. }
  662. }
  663. void ScriptEditorDebugger::_notification(int p_what) {
  664. switch (p_what) {
  665. case NOTIFICATION_ENTER_TREE: {
  666. inspector->edit(variables);
  667. step->set_icon(get_icon("DebugStep", "EditorIcons"));
  668. next->set_icon(get_icon("DebugNext", "EditorIcons"));
  669. back->set_icon(get_icon("Back", "EditorIcons"));
  670. forward->set_icon(get_icon("Forward", "EditorIcons"));
  671. dobreak->set_icon(get_icon("Pause", "EditorIcons"));
  672. docontinue->set_icon(get_icon("DebugContinue", "EditorIcons"));
  673. //scene_tree_refresh->set_icon( get_icon("Reload","EditorIcons"));
  674. le_set->connect("pressed", this, "_live_edit_set");
  675. le_clear->connect("pressed", this, "_live_edit_clear");
  676. error_list->connect("item_selected", this, "_error_selected");
  677. error_stack->connect("item_selected", this, "_error_stack_selected");
  678. vmem_refresh->set_icon(get_icon("Reload", "EditorIcons"));
  679. reason->add_color_override("font_color", get_color("error_color", "Editor"));
  680. } break;
  681. case NOTIFICATION_PROCESS: {
  682. if (connection.is_valid()) {
  683. inspect_scene_tree_timeout -= get_process_delta_time();
  684. if (inspect_scene_tree_timeout < 0) {
  685. inspect_scene_tree_timeout = EditorSettings::get_singleton()->get("debugger/scene_tree_refresh_interval");
  686. if (inspect_scene_tree->is_visible_in_tree()) {
  687. _scene_tree_request();
  688. if (inspected_object_id != 0) {
  689. //take the chance and re-inspect selected object
  690. Array msg;
  691. msg.push_back("inspect_object");
  692. msg.push_back(inspected_object_id);
  693. ppeer->put_var(msg);
  694. }
  695. }
  696. }
  697. inspect_edited_object_timeout -= get_process_delta_time();
  698. if (inspect_edited_object_timeout < 0) {
  699. inspect_edited_object_timeout = EditorSettings::get_singleton()->get("debugger/remote_inspect_refresh_interval");
  700. if (inspect_scene_tree->is_visible_in_tree() && inspected_object_id) {
  701. //take the chance and re-inspect selected object
  702. Array msg;
  703. msg.push_back("inspect_object");
  704. msg.push_back(inspected_object_id);
  705. ppeer->put_var(msg);
  706. }
  707. }
  708. }
  709. if (error_count != last_error_count) {
  710. if (error_count == 0) {
  711. error_split->set_name(TTR("Errors"));
  712. debugger_button->set_text(TTR("Debugger"));
  713. debugger_button->set_icon(Ref<Texture>());
  714. tabs->set_tab_icon(error_split->get_index(), Ref<Texture>());
  715. } else {
  716. error_split->set_name(TTR("Errors") + " (" + itos(error_count) + ")");
  717. debugger_button->set_text(TTR("Debugger") + " (" + itos(error_count) + ")");
  718. debugger_button->set_icon(get_icon("Error", "EditorIcons"));
  719. tabs->set_tab_icon(error_split->get_index(), get_icon("Error", "EditorIcons"));
  720. }
  721. last_error_count = error_count;
  722. }
  723. if (connection.is_null()) {
  724. if (server->is_connection_available()) {
  725. connection = server->take_connection();
  726. if (connection.is_null())
  727. break;
  728. EditorNode::get_log()->add_message("** Debug Process Started **");
  729. ppeer->set_stream_peer(connection);
  730. //EditorNode::get_singleton()->make_bottom_panel_item_visible(this);
  731. //emit_signal("show_debugger",true);
  732. dobreak->set_disabled(false);
  733. tabs->set_current_tab(0);
  734. _set_reason_text(TTR("Child Process Connected"), MESSAGE_SUCCESS);
  735. profiler->clear();
  736. inspect_scene_tree->clear();
  737. le_set->set_disabled(true);
  738. le_clear->set_disabled(false);
  739. error_list->clear();
  740. error_stack->clear();
  741. error_count = 0;
  742. profiler_signature.clear();
  743. //live_edit_root->set_text("/root");
  744. EditorNode::get_singleton()->get_pause_button()->set_pressed(false);
  745. EditorNode::get_singleton()->get_pause_button()->set_disabled(false);
  746. update_live_edit_root();
  747. if (profiler->is_profiling()) {
  748. _profiler_activate(true);
  749. }
  750. } else {
  751. break;
  752. }
  753. };
  754. if (!connection->is_connected_to_host()) {
  755. stop();
  756. editor->notify_child_process_exited(); //somehow, exited
  757. break;
  758. };
  759. if (ppeer->get_available_packet_count() <= 0) {
  760. break;
  761. };
  762. while (ppeer->get_available_packet_count() > 0) {
  763. if (pending_in_queue) {
  764. int todo = MIN(ppeer->get_available_packet_count(), pending_in_queue);
  765. for (int i = 0; i < todo; i++) {
  766. Variant cmd;
  767. Error ret = ppeer->get_var(cmd);
  768. if (ret != OK) {
  769. stop();
  770. ERR_FAIL_COND(ret != OK);
  771. }
  772. message.push_back(cmd);
  773. pending_in_queue--;
  774. }
  775. if (pending_in_queue == 0) {
  776. _parse_message(message_type, message);
  777. message.clear();
  778. }
  779. } else {
  780. if (ppeer->get_available_packet_count() >= 2) {
  781. Variant cmd;
  782. Error ret = ppeer->get_var(cmd);
  783. if (ret != OK) {
  784. stop();
  785. ERR_FAIL_COND(ret != OK);
  786. }
  787. if (cmd.get_type() != Variant::STRING) {
  788. stop();
  789. ERR_FAIL_COND(cmd.get_type() != Variant::STRING);
  790. }
  791. message_type = cmd;
  792. //print_line("GOT: "+message_type);
  793. ret = ppeer->get_var(cmd);
  794. if (ret != OK) {
  795. stop();
  796. ERR_FAIL_COND(ret != OK);
  797. }
  798. if (cmd.get_type() != Variant::INT) {
  799. stop();
  800. ERR_FAIL_COND(cmd.get_type() != Variant::INT);
  801. }
  802. pending_in_queue = cmd;
  803. if (pending_in_queue == 0) {
  804. _parse_message(message_type, Array());
  805. message.clear();
  806. }
  807. } else {
  808. break;
  809. }
  810. }
  811. }
  812. } break;
  813. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  814. tabs->add_style_override("panel", editor->get_gui_base()->get_stylebox("DebuggerPanel", "EditorStyles"));
  815. tabs->add_style_override("tab_fg", editor->get_gui_base()->get_stylebox("DebuggerTabFG", "EditorStyles"));
  816. tabs->add_style_override("tab_bg", editor->get_gui_base()->get_stylebox("DebuggerTabBG", "EditorStyles"));
  817. } break;
  818. }
  819. }
  820. void ScriptEditorDebugger::start() {
  821. stop();
  822. if (is_visible_in_tree()) {
  823. EditorNode::get_singleton()->make_bottom_panel_item_visible(this);
  824. }
  825. perf_history.clear();
  826. for (int i = 0; i < Performance::MONITOR_MAX; i++) {
  827. perf_max[i] = 0;
  828. }
  829. int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port");
  830. if (server->listen(remote_port) != OK) {
  831. EditorNode::get_log()->add_message(String("** Error listening on port ") + itos(remote_port) + String(" **"));
  832. return;
  833. }
  834. set_process(true);
  835. }
  836. void ScriptEditorDebugger::pause() {
  837. }
  838. void ScriptEditorDebugger::unpause() {
  839. }
  840. void ScriptEditorDebugger::stop() {
  841. set_process(false);
  842. server->stop();
  843. ppeer->set_stream_peer(Ref<StreamPeer>());
  844. if (connection.is_valid()) {
  845. EditorNode::get_log()->add_message("** Debug Process Stopped **");
  846. connection.unref();
  847. }
  848. pending_in_queue = 0;
  849. message.clear();
  850. node_path_cache.clear();
  851. res_path_cache.clear();
  852. profiler_signature.clear();
  853. le_clear->set_disabled(false);
  854. le_set->set_disabled(true);
  855. profiler->set_enabled(true);
  856. inspect_properties->edit(NULL);
  857. inspect_scene_tree->clear();
  858. EditorNode::get_singleton()->get_pause_button()->set_pressed(false);
  859. EditorNode::get_singleton()->get_pause_button()->set_disabled(true);
  860. if (hide_on_stop) {
  861. if (is_visible_in_tree())
  862. EditorNode::get_singleton()->hide_bottom_panel();
  863. emit_signal("show_debugger", false);
  864. }
  865. }
  866. void ScriptEditorDebugger::_profiler_activate(bool p_enable) {
  867. if (!connection.is_valid())
  868. return;
  869. if (p_enable) {
  870. profiler_signature.clear();
  871. Array msg;
  872. msg.push_back("start_profiling");
  873. int max_funcs = EditorSettings::get_singleton()->get("debugger/profiler_frame_max_functions");
  874. max_funcs = CLAMP(max_funcs, 16, 512);
  875. msg.push_back(max_funcs);
  876. ppeer->put_var(msg);
  877. print_line("BEGIN PROFILING!");
  878. } else {
  879. Array msg;
  880. msg.push_back("stop_profiling");
  881. ppeer->put_var(msg);
  882. print_line("END PROFILING!");
  883. }
  884. }
  885. void ScriptEditorDebugger::_profiler_seeked() {
  886. if (!connection.is_valid() || !connection->is_connected_to_host())
  887. return;
  888. if (breaked)
  889. return;
  890. debug_break();
  891. }
  892. void ScriptEditorDebugger::_stack_dump_frame_selected() {
  893. TreeItem *ti = stack_dump->get_selected();
  894. if (!ti)
  895. return;
  896. Dictionary d = ti->get_metadata(0);
  897. stack_script = ResourceLoader::load(d["file"]);
  898. emit_signal("goto_script_line", stack_script, int(d["line"]) - 1);
  899. stack_script.unref();
  900. ERR_FAIL_COND(connection.is_null());
  901. ERR_FAIL_COND(!connection->is_connected_to_host());
  902. ///
  903. Array msg;
  904. msg.push_back("get_stack_frame_vars");
  905. msg.push_back(d["frame"]);
  906. ppeer->put_var(msg);
  907. }
  908. void ScriptEditorDebugger::_output_clear() {
  909. //output->clear();
  910. //output->push_color(Color(0,0,0));
  911. }
  912. String ScriptEditorDebugger::get_var_value(const String &p_var) const {
  913. if (!breaked)
  914. return String();
  915. return variables->get_var_value(p_var);
  916. }
  917. int ScriptEditorDebugger::_get_node_path_cache(const NodePath &p_path) {
  918. const int *r = node_path_cache.getptr(p_path);
  919. if (r)
  920. return *r;
  921. last_path_id++;
  922. node_path_cache[p_path] = last_path_id;
  923. Array msg;
  924. msg.push_back("live_node_path");
  925. msg.push_back(p_path);
  926. msg.push_back(last_path_id);
  927. ppeer->put_var(msg);
  928. return last_path_id;
  929. }
  930. int ScriptEditorDebugger::_get_res_path_cache(const String &p_path) {
  931. Map<String, int>::Element *E = res_path_cache.find(p_path);
  932. if (E)
  933. return E->get();
  934. last_path_id++;
  935. res_path_cache[p_path] = last_path_id;
  936. Array msg;
  937. msg.push_back("live_res_path");
  938. msg.push_back(p_path);
  939. msg.push_back(last_path_id);
  940. ppeer->put_var(msg);
  941. return last_path_id;
  942. }
  943. void ScriptEditorDebugger::_method_changed(Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE) {
  944. if (!p_base || !live_debug || !connection.is_valid() || !editor->get_edited_scene())
  945. return;
  946. Node *node = Object::cast_to<Node>(p_base);
  947. VARIANT_ARGPTRS
  948. for (int i = 0; i < VARIANT_ARG_MAX; i++) {
  949. //no pointers, sorry
  950. if (argptr[i] && (argptr[i]->get_type() == Variant::OBJECT || argptr[i]->get_type() == Variant::_RID))
  951. return;
  952. }
  953. if (node) {
  954. NodePath path = editor->get_edited_scene()->get_path_to(node);
  955. int pathid = _get_node_path_cache(path);
  956. Array msg;
  957. msg.push_back("live_node_call");
  958. msg.push_back(pathid);
  959. msg.push_back(p_name);
  960. for (int i = 0; i < VARIANT_ARG_MAX; i++) {
  961. //no pointers, sorry
  962. msg.push_back(*argptr[i]);
  963. }
  964. ppeer->put_var(msg);
  965. return;
  966. }
  967. Resource *res = Object::cast_to<Resource>(p_base);
  968. if (res && res->get_path() != String()) {
  969. String respath = res->get_path();
  970. int pathid = _get_res_path_cache(respath);
  971. Array msg;
  972. msg.push_back("live_res_call");
  973. msg.push_back(pathid);
  974. msg.push_back(p_name);
  975. for (int i = 0; i < VARIANT_ARG_MAX; i++) {
  976. //no pointers, sorry
  977. msg.push_back(*argptr[i]);
  978. }
  979. ppeer->put_var(msg);
  980. return;
  981. }
  982. //print_line("method");
  983. }
  984. void ScriptEditorDebugger::_property_changed(Object *p_base, const StringName &p_property, const Variant &p_value) {
  985. if (!p_base || !live_debug || !connection.is_valid() || !editor->get_edited_scene())
  986. return;
  987. Node *node = Object::cast_to<Node>(p_base);
  988. if (node) {
  989. NodePath path = editor->get_edited_scene()->get_path_to(node);
  990. int pathid = _get_node_path_cache(path);
  991. if (p_value.is_ref()) {
  992. Ref<Resource> res = p_value;
  993. if (res.is_valid() && res->get_path() != String()) {
  994. Array msg;
  995. msg.push_back("live_node_prop_res");
  996. msg.push_back(pathid);
  997. msg.push_back(p_property);
  998. msg.push_back(res->get_path());
  999. ppeer->put_var(msg);
  1000. }
  1001. } else {
  1002. Array msg;
  1003. msg.push_back("live_node_prop");
  1004. msg.push_back(pathid);
  1005. msg.push_back(p_property);
  1006. msg.push_back(p_value);
  1007. ppeer->put_var(msg);
  1008. }
  1009. return;
  1010. }
  1011. Resource *res = Object::cast_to<Resource>(p_base);
  1012. if (res && res->get_path() != String()) {
  1013. String respath = res->get_path();
  1014. int pathid = _get_res_path_cache(respath);
  1015. if (p_value.is_ref()) {
  1016. Ref<Resource> res = p_value;
  1017. if (res.is_valid() && res->get_path() != String()) {
  1018. Array msg;
  1019. msg.push_back("live_res_prop_res");
  1020. msg.push_back(pathid);
  1021. msg.push_back(p_property);
  1022. msg.push_back(res->get_path());
  1023. ppeer->put_var(msg);
  1024. }
  1025. } else {
  1026. Array msg;
  1027. msg.push_back("live_res_prop");
  1028. msg.push_back(pathid);
  1029. msg.push_back(p_property);
  1030. msg.push_back(p_value);
  1031. ppeer->put_var(msg);
  1032. }
  1033. return;
  1034. }
  1035. //print_line("prop");
  1036. }
  1037. void ScriptEditorDebugger::_method_changeds(void *p_ud, Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE) {
  1038. ScriptEditorDebugger *sed = (ScriptEditorDebugger *)p_ud;
  1039. sed->_method_changed(p_base, p_name, VARIANT_ARG_PASS);
  1040. }
  1041. void ScriptEditorDebugger::_property_changeds(void *p_ud, Object *p_base, const StringName &p_property, const Variant &p_value) {
  1042. ScriptEditorDebugger *sed = (ScriptEditorDebugger *)p_ud;
  1043. sed->_property_changed(p_base, p_property, p_value);
  1044. }
  1045. void ScriptEditorDebugger::set_live_debugging(bool p_enable) {
  1046. live_debug = p_enable;
  1047. }
  1048. void ScriptEditorDebugger::_live_edit_set() {
  1049. if (!connection.is_valid())
  1050. return;
  1051. TreeItem *ti = inspect_scene_tree->get_selected();
  1052. if (!ti)
  1053. return;
  1054. String path;
  1055. while (ti) {
  1056. String lp = ti->get_text(0);
  1057. path = "/" + lp + path;
  1058. ti = ti->get_parent();
  1059. }
  1060. NodePath np = path;
  1061. editor->get_editor_data().set_edited_scene_live_edit_root(np);
  1062. update_live_edit_root();
  1063. }
  1064. void ScriptEditorDebugger::_live_edit_clear() {
  1065. NodePath np = NodePath("/root");
  1066. editor->get_editor_data().set_edited_scene_live_edit_root(np);
  1067. update_live_edit_root();
  1068. }
  1069. void ScriptEditorDebugger::update_live_edit_root() {
  1070. NodePath np = editor->get_editor_data().get_edited_scene_live_edit_root();
  1071. if (connection.is_valid()) {
  1072. Array msg;
  1073. msg.push_back("live_set_root");
  1074. msg.push_back(np);
  1075. if (editor->get_edited_scene())
  1076. msg.push_back(editor->get_edited_scene()->get_filename());
  1077. else
  1078. msg.push_back("");
  1079. ppeer->put_var(msg);
  1080. }
  1081. live_edit_root->set_text(np);
  1082. }
  1083. void ScriptEditorDebugger::live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name) {
  1084. if (live_debug && connection.is_valid()) {
  1085. Array msg;
  1086. msg.push_back("live_create_node");
  1087. msg.push_back(p_parent);
  1088. msg.push_back(p_type);
  1089. msg.push_back(p_name);
  1090. ppeer->put_var(msg);
  1091. }
  1092. }
  1093. void ScriptEditorDebugger::live_debug_instance_node(const NodePath &p_parent, const String &p_path, const String &p_name) {
  1094. if (live_debug && connection.is_valid()) {
  1095. Array msg;
  1096. msg.push_back("live_instance_node");
  1097. msg.push_back(p_parent);
  1098. msg.push_back(p_path);
  1099. msg.push_back(p_name);
  1100. ppeer->put_var(msg);
  1101. }
  1102. }
  1103. void ScriptEditorDebugger::live_debug_remove_node(const NodePath &p_at) {
  1104. if (live_debug && connection.is_valid()) {
  1105. Array msg;
  1106. msg.push_back("live_remove_node");
  1107. msg.push_back(p_at);
  1108. ppeer->put_var(msg);
  1109. }
  1110. }
  1111. void ScriptEditorDebugger::live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id) {
  1112. if (live_debug && connection.is_valid()) {
  1113. Array msg;
  1114. msg.push_back("live_remove_and_keep_node");
  1115. msg.push_back(p_at);
  1116. msg.push_back(p_keep_id);
  1117. ppeer->put_var(msg);
  1118. }
  1119. }
  1120. void ScriptEditorDebugger::live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos) {
  1121. if (live_debug && connection.is_valid()) {
  1122. Array msg;
  1123. msg.push_back("live_restore_node");
  1124. msg.push_back(p_id);
  1125. msg.push_back(p_at);
  1126. msg.push_back(p_at_pos);
  1127. ppeer->put_var(msg);
  1128. }
  1129. }
  1130. void ScriptEditorDebugger::live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name) {
  1131. if (live_debug && connection.is_valid()) {
  1132. Array msg;
  1133. msg.push_back("live_duplicate_node");
  1134. msg.push_back(p_at);
  1135. msg.push_back(p_new_name);
  1136. ppeer->put_var(msg);
  1137. }
  1138. }
  1139. void ScriptEditorDebugger::live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos) {
  1140. if (live_debug && connection.is_valid()) {
  1141. Array msg;
  1142. msg.push_back("live_reparent_node");
  1143. msg.push_back(p_at);
  1144. msg.push_back(p_new_place);
  1145. msg.push_back(p_new_name);
  1146. msg.push_back(p_at_pos);
  1147. ppeer->put_var(msg);
  1148. }
  1149. }
  1150. void ScriptEditorDebugger::set_breakpoint(const String &p_path, int p_line, bool p_enabled) {
  1151. if (connection.is_valid()) {
  1152. Array msg;
  1153. msg.push_back("breakpoint");
  1154. msg.push_back(p_path);
  1155. msg.push_back(p_line);
  1156. msg.push_back(p_enabled);
  1157. ppeer->put_var(msg);
  1158. }
  1159. }
  1160. void ScriptEditorDebugger::reload_scripts() {
  1161. if (connection.is_valid()) {
  1162. Array msg;
  1163. msg.push_back("reload_scripts");
  1164. ppeer->put_var(msg);
  1165. }
  1166. }
  1167. void ScriptEditorDebugger::_error_selected(int p_idx) {
  1168. error_stack->clear();
  1169. Array st = error_list->get_item_metadata(p_idx);
  1170. for (int i = 0; i < st.size(); i += 2) {
  1171. String script = st[i];
  1172. int line = st[i + 1];
  1173. Array md;
  1174. md.push_back(st[i]);
  1175. md.push_back(st[i + 1]);
  1176. String str = script.get_file() + ":" + itos(line);
  1177. error_stack->add_item(str);
  1178. error_stack->set_item_metadata(error_stack->get_item_count() - 1, md);
  1179. error_stack->set_item_tooltip(error_stack->get_item_count() - 1, TTR("File:") + " " + String(st[i]) + "\n" + TTR("Line:") + " " + itos(line));
  1180. }
  1181. }
  1182. void ScriptEditorDebugger::_error_stack_selected(int p_idx) {
  1183. Array arr = error_stack->get_item_metadata(p_idx);
  1184. if (arr.size() != 2)
  1185. return;
  1186. Ref<Script> s = ResourceLoader::load(arr[0]);
  1187. emit_signal("goto_script_line", s, int(arr[1]) - 1);
  1188. }
  1189. void ScriptEditorDebugger::set_hide_on_stop(bool p_hide) {
  1190. hide_on_stop = p_hide;
  1191. }
  1192. bool ScriptEditorDebugger::get_debug_with_external_editor() const {
  1193. return enable_external_editor;
  1194. }
  1195. void ScriptEditorDebugger::set_debug_with_external_editor(bool p_enabled) {
  1196. enable_external_editor = p_enabled;
  1197. }
  1198. Ref<Script> ScriptEditorDebugger::get_dump_stack_script() const {
  1199. return stack_script;
  1200. }
  1201. void ScriptEditorDebugger::_paused() {
  1202. ERR_FAIL_COND(connection.is_null());
  1203. ERR_FAIL_COND(!connection->is_connected_to_host());
  1204. if (!breaked && EditorNode::get_singleton()->get_pause_button()->is_pressed()) {
  1205. debug_break();
  1206. }
  1207. if (breaked && !EditorNode::get_singleton()->get_pause_button()->is_pressed()) {
  1208. debug_continue();
  1209. }
  1210. }
  1211. void ScriptEditorDebugger::_bind_methods() {
  1212. ClassDB::bind_method(D_METHOD("_stack_dump_frame_selected"), &ScriptEditorDebugger::_stack_dump_frame_selected);
  1213. ClassDB::bind_method(D_METHOD("debug_next"), &ScriptEditorDebugger::debug_next);
  1214. ClassDB::bind_method(D_METHOD("debug_step"), &ScriptEditorDebugger::debug_step);
  1215. ClassDB::bind_method(D_METHOD("debug_break"), &ScriptEditorDebugger::debug_break);
  1216. ClassDB::bind_method(D_METHOD("debug_continue"), &ScriptEditorDebugger::debug_continue);
  1217. ClassDB::bind_method(D_METHOD("_output_clear"), &ScriptEditorDebugger::_output_clear);
  1218. ClassDB::bind_method(D_METHOD("_performance_draw"), &ScriptEditorDebugger::_performance_draw);
  1219. ClassDB::bind_method(D_METHOD("_performance_select"), &ScriptEditorDebugger::_performance_select);
  1220. ClassDB::bind_method(D_METHOD("_scene_tree_request"), &ScriptEditorDebugger::_scene_tree_request);
  1221. ClassDB::bind_method(D_METHOD("_video_mem_request"), &ScriptEditorDebugger::_video_mem_request);
  1222. ClassDB::bind_method(D_METHOD("_live_edit_set"), &ScriptEditorDebugger::_live_edit_set);
  1223. ClassDB::bind_method(D_METHOD("_live_edit_clear"), &ScriptEditorDebugger::_live_edit_clear);
  1224. ClassDB::bind_method(D_METHOD("_error_selected"), &ScriptEditorDebugger::_error_selected);
  1225. ClassDB::bind_method(D_METHOD("_error_stack_selected"), &ScriptEditorDebugger::_error_stack_selected);
  1226. ClassDB::bind_method(D_METHOD("_profiler_activate"), &ScriptEditorDebugger::_profiler_activate);
  1227. ClassDB::bind_method(D_METHOD("_profiler_seeked"), &ScriptEditorDebugger::_profiler_seeked);
  1228. ClassDB::bind_method(D_METHOD("_paused"), &ScriptEditorDebugger::_paused);
  1229. ClassDB::bind_method(D_METHOD("_scene_tree_selected"), &ScriptEditorDebugger::_scene_tree_selected);
  1230. ClassDB::bind_method(D_METHOD("_scene_tree_folded"), &ScriptEditorDebugger::_scene_tree_folded);
  1231. ClassDB::bind_method(D_METHOD("live_debug_create_node"), &ScriptEditorDebugger::live_debug_create_node);
  1232. ClassDB::bind_method(D_METHOD("live_debug_instance_node"), &ScriptEditorDebugger::live_debug_instance_node);
  1233. ClassDB::bind_method(D_METHOD("live_debug_remove_node"), &ScriptEditorDebugger::live_debug_remove_node);
  1234. ClassDB::bind_method(D_METHOD("live_debug_remove_and_keep_node"), &ScriptEditorDebugger::live_debug_remove_and_keep_node);
  1235. ClassDB::bind_method(D_METHOD("live_debug_restore_node"), &ScriptEditorDebugger::live_debug_restore_node);
  1236. ClassDB::bind_method(D_METHOD("live_debug_duplicate_node"), &ScriptEditorDebugger::live_debug_duplicate_node);
  1237. ClassDB::bind_method(D_METHOD("live_debug_reparent_node"), &ScriptEditorDebugger::live_debug_reparent_node);
  1238. ClassDB::bind_method(D_METHOD("_scene_tree_property_select_object"), &ScriptEditorDebugger::_scene_tree_property_select_object);
  1239. ClassDB::bind_method(D_METHOD("_scene_tree_property_value_edited"), &ScriptEditorDebugger::_scene_tree_property_value_edited);
  1240. ADD_SIGNAL(MethodInfo("goto_script_line"));
  1241. ADD_SIGNAL(MethodInfo("breaked", PropertyInfo(Variant::BOOL, "reallydid"), PropertyInfo(Variant::BOOL, "can_debug")));
  1242. ADD_SIGNAL(MethodInfo("show_debugger", PropertyInfo(Variant::BOOL, "reallydid")));
  1243. }
  1244. ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) {
  1245. ppeer = Ref<PacketPeerStream>(memnew(PacketPeerStream));
  1246. ppeer->set_input_buffer_max_size(1024 * 1024 * 8); //8mb should be enough
  1247. editor = p_editor;
  1248. tabs = memnew(TabContainer);
  1249. tabs->set_tab_align(TabContainer::ALIGN_LEFT);
  1250. tabs->add_style_override("panel", editor->get_gui_base()->get_stylebox("DebuggerPanel", "EditorStyles"));
  1251. tabs->add_style_override("tab_fg", editor->get_gui_base()->get_stylebox("DebuggerTabFG", "EditorStyles"));
  1252. tabs->add_style_override("tab_bg", editor->get_gui_base()->get_stylebox("DebuggerTabBG", "EditorStyles"));
  1253. tabs->set_anchors_and_margins_preset(Control::PRESET_WIDE);
  1254. add_child(tabs);
  1255. { //debugger
  1256. VBoxContainer *vbc = memnew(VBoxContainer);
  1257. vbc->set_name(TTR("Debugger"));
  1258. //tabs->add_child(vbc);
  1259. Control *dbg = vbc;
  1260. HBoxContainer *hbc = memnew(HBoxContainer);
  1261. vbc->add_child(hbc);
  1262. reason = memnew(Label);
  1263. reason->set_text("");
  1264. hbc->add_child(reason);
  1265. reason->set_h_size_flags(SIZE_EXPAND_FILL);
  1266. hbc->add_child(memnew(VSeparator));
  1267. step = memnew(ToolButton);
  1268. hbc->add_child(step);
  1269. step->set_tooltip(TTR("Step Into"));
  1270. step->connect("pressed", this, "debug_step");
  1271. next = memnew(ToolButton);
  1272. hbc->add_child(next);
  1273. next->set_tooltip(TTR("Step Over"));
  1274. next->connect("pressed", this, "debug_next");
  1275. hbc->add_child(memnew(VSeparator));
  1276. dobreak = memnew(ToolButton);
  1277. hbc->add_child(dobreak);
  1278. dobreak->set_tooltip(TTR("Break"));
  1279. dobreak->connect("pressed", this, "debug_break");
  1280. docontinue = memnew(ToolButton);
  1281. hbc->add_child(docontinue);
  1282. docontinue->set_tooltip(TTR("Continue"));
  1283. docontinue->connect("pressed", this, "debug_continue");
  1284. back = memnew(Button);
  1285. hbc->add_child(back);
  1286. back->set_tooltip(TTR("Inspect Previous Instance"));
  1287. back->hide();
  1288. forward = memnew(Button);
  1289. hbc->add_child(forward);
  1290. forward->set_tooltip(TTR("Inspect Next Instance"));
  1291. forward->hide();
  1292. HSplitContainer *sc = memnew(HSplitContainer);
  1293. vbc->add_child(sc);
  1294. sc->set_v_size_flags(SIZE_EXPAND_FILL);
  1295. stack_dump = memnew(Tree);
  1296. stack_dump->set_columns(1);
  1297. stack_dump->set_column_titles_visible(true);
  1298. stack_dump->set_column_title(0, TTR("Stack Frames"));
  1299. stack_dump->set_h_size_flags(SIZE_EXPAND_FILL);
  1300. stack_dump->set_hide_root(true);
  1301. stack_dump->connect("cell_selected", this, "_stack_dump_frame_selected");
  1302. sc->add_child(stack_dump);
  1303. inspector = memnew(PropertyEditor);
  1304. inspector->set_h_size_flags(SIZE_EXPAND_FILL);
  1305. inspector->hide_top_label();
  1306. inspector->get_scene_tree()->set_column_title(0, TTR("Variable"));
  1307. inspector->set_enable_capitalize_paths(false);
  1308. inspector->set_read_only(true);
  1309. inspector->connect("object_id_selected", this, "_scene_tree_property_select_object");
  1310. sc->add_child(inspector);
  1311. server = TCP_Server::create_ref();
  1312. pending_in_queue = 0;
  1313. variables = memnew(ScriptEditorDebuggerVariables);
  1314. breaked = false;
  1315. tabs->add_child(dbg);
  1316. }
  1317. { //errors
  1318. error_split = memnew(HSplitContainer);
  1319. VBoxContainer *errvb = memnew(VBoxContainer);
  1320. errvb->set_h_size_flags(SIZE_EXPAND_FILL);
  1321. error_list = memnew(ItemList);
  1322. errvb->add_margin_child(TTR("Errors:"), error_list, true);
  1323. error_split->add_child(errvb);
  1324. errvb = memnew(VBoxContainer);
  1325. errvb->set_h_size_flags(SIZE_EXPAND_FILL);
  1326. error_stack = memnew(ItemList);
  1327. errvb->add_margin_child(TTR("Stack Trace (if applicable):"), error_stack, true);
  1328. error_split->add_child(errvb);
  1329. error_split->set_name(TTR("Errors"));
  1330. tabs->add_child(error_split);
  1331. }
  1332. { // inquire
  1333. inspect_info = memnew(HSplitContainer);
  1334. inspect_info->set_name(TTR("Remote Inspector"));
  1335. tabs->add_child(inspect_info);
  1336. VBoxContainer *info_left = memnew(VBoxContainer);
  1337. info_left->set_h_size_flags(SIZE_EXPAND_FILL);
  1338. inspect_info->add_child(info_left);
  1339. inspect_scene_tree = memnew(Tree);
  1340. info_left->add_margin_child(TTR("Live Scene Tree:"), inspect_scene_tree, true);
  1341. inspect_scene_tree->connect("cell_selected", this, "_scene_tree_selected");
  1342. inspect_scene_tree->connect("item_collapsed", this, "_scene_tree_folded");
  1343. //
  1344. VBoxContainer *info_right = memnew(VBoxContainer);
  1345. info_right->set_h_size_flags(SIZE_EXPAND_FILL);
  1346. inspect_info->add_child(info_right);
  1347. inspect_properties = memnew(PropertyEditor);
  1348. inspect_properties->hide_top_label();
  1349. inspect_properties->set_show_categories(true);
  1350. inspect_properties->connect("object_id_selected", this, "_scene_tree_property_select_object");
  1351. info_right->add_margin_child(TTR("Remote Object Properties: "), inspect_properties, true);
  1352. inspect_scene_tree_timeout = EDITOR_DEF("debugger/scene_tree_refresh_interval", 1.0);
  1353. inspect_edited_object_timeout = EDITOR_DEF("debugger/remote_inspect_refresh_interval", 0.2);
  1354. inspected_object_id = 0;
  1355. updating_scene_tree = false;
  1356. inspected_object = memnew(ScriptEditorDebuggerInspectedObject);
  1357. inspected_object->connect("value_edited", this, "_scene_tree_property_value_edited");
  1358. }
  1359. { //profiler
  1360. profiler = memnew(EditorProfiler);
  1361. profiler->set_name(TTR("Profiler"));
  1362. tabs->add_child(profiler);
  1363. profiler->connect("enable_profiling", this, "_profiler_activate");
  1364. profiler->connect("break_request", this, "_profiler_seeked");
  1365. }
  1366. { //monitors
  1367. HSplitContainer *hsp = memnew(HSplitContainer);
  1368. perf_monitors = memnew(Tree);
  1369. perf_monitors->set_columns(2);
  1370. perf_monitors->set_column_title(0, TTR("Monitor"));
  1371. perf_monitors->set_column_title(1, TTR("Value"));
  1372. perf_monitors->set_column_titles_visible(true);
  1373. hsp->add_child(perf_monitors);
  1374. perf_monitors->set_select_mode(Tree::SELECT_MULTI);
  1375. perf_monitors->connect("multi_selected", this, "_performance_select");
  1376. perf_draw = memnew(Control);
  1377. perf_draw->connect("draw", this, "_performance_draw");
  1378. hsp->add_child(perf_draw);
  1379. hsp->set_name(TTR("Monitors"));
  1380. hsp->set_split_offset(300);
  1381. tabs->add_child(hsp);
  1382. perf_max.resize(Performance::MONITOR_MAX);
  1383. Map<String, TreeItem *> bases;
  1384. TreeItem *root = perf_monitors->create_item();
  1385. perf_monitors->set_hide_root(true);
  1386. for (int i = 0; i < Performance::MONITOR_MAX; i++) {
  1387. String n = Performance::get_singleton()->get_monitor_name(Performance::Monitor(i));
  1388. String base = n.get_slice("/", 0);
  1389. String name = n.get_slice("/", 1);
  1390. if (!bases.has(base)) {
  1391. TreeItem *b = perf_monitors->create_item(root);
  1392. b->set_text(0, base.capitalize());
  1393. b->set_editable(0, false);
  1394. b->set_selectable(0, false);
  1395. bases[base] = b;
  1396. }
  1397. TreeItem *it = perf_monitors->create_item(bases[base]);
  1398. it->set_editable(0, false);
  1399. it->set_selectable(0, true);
  1400. it->set_text(0, name.capitalize());
  1401. perf_items.push_back(it);
  1402. perf_max[i] = 0;
  1403. }
  1404. }
  1405. { //vmem inspect
  1406. VBoxContainer *vmem_vb = memnew(VBoxContainer);
  1407. HBoxContainer *vmem_hb = memnew(HBoxContainer);
  1408. Label *vmlb = memnew(Label(TTR("List of Video Memory Usage by Resource:") + " "));
  1409. vmlb->set_h_size_flags(SIZE_EXPAND_FILL);
  1410. vmem_hb->add_child(vmlb);
  1411. vmem_hb->add_child(memnew(Label(TTR("Total:") + " ")));
  1412. vmem_total = memnew(LineEdit);
  1413. vmem_total->set_editable(false);
  1414. vmem_total->set_custom_minimum_size(Size2(100, 1) * EDSCALE);
  1415. vmem_hb->add_child(vmem_total);
  1416. vmem_refresh = memnew(ToolButton);
  1417. vmem_hb->add_child(vmem_refresh);
  1418. vmem_vb->add_child(vmem_hb);
  1419. vmem_refresh->connect("pressed", this, "_video_mem_request");
  1420. VBoxContainer *vmmc = memnew(VBoxContainer);
  1421. vmem_tree = memnew(Tree);
  1422. vmem_tree->set_v_size_flags(SIZE_EXPAND_FILL);
  1423. vmem_tree->set_h_size_flags(SIZE_EXPAND_FILL);
  1424. vmmc->add_child(vmem_tree);
  1425. vmmc->set_v_size_flags(SIZE_EXPAND_FILL);
  1426. vmem_vb->add_child(vmmc);
  1427. vmem_vb->set_name(TTR("Video Mem"));
  1428. vmem_tree->set_columns(4);
  1429. vmem_tree->set_column_titles_visible(true);
  1430. vmem_tree->set_column_title(0, TTR("Resource Path"));
  1431. vmem_tree->set_column_expand(0, true);
  1432. vmem_tree->set_column_expand(1, false);
  1433. vmem_tree->set_column_title(1, TTR("Type"));
  1434. vmem_tree->set_column_min_width(1, 100);
  1435. vmem_tree->set_column_expand(2, false);
  1436. vmem_tree->set_column_title(2, TTR("Format"));
  1437. vmem_tree->set_column_min_width(2, 150);
  1438. vmem_tree->set_column_expand(3, false);
  1439. vmem_tree->set_column_title(3, TTR("Usage"));
  1440. vmem_tree->set_column_min_width(3, 80);
  1441. vmem_tree->set_hide_root(true);
  1442. tabs->add_child(vmem_vb);
  1443. }
  1444. { // misc
  1445. GridContainer *info_left = memnew(GridContainer);
  1446. info_left->set_columns(2);
  1447. info_left->set_name(TTR("Misc"));
  1448. tabs->add_child(info_left);
  1449. clicked_ctrl = memnew(LineEdit);
  1450. clicked_ctrl->set_h_size_flags(SIZE_EXPAND_FILL);
  1451. info_left->add_child(memnew(Label(TTR("Clicked Control:"))));
  1452. info_left->add_child(clicked_ctrl);
  1453. clicked_ctrl_type = memnew(LineEdit);
  1454. info_left->add_child(memnew(Label(TTR("Clicked Control Type:"))));
  1455. info_left->add_child(clicked_ctrl_type);
  1456. live_edit_root = memnew(LineEdit);
  1457. live_edit_root->set_h_size_flags(SIZE_EXPAND_FILL);
  1458. {
  1459. HBoxContainer *lehb = memnew(HBoxContainer);
  1460. Label *l = memnew(Label(TTR("Live Edit Root:")));
  1461. info_left->add_child(l);
  1462. lehb->add_child(live_edit_root);
  1463. le_set = memnew(Button(TTR("Set From Tree")));
  1464. lehb->add_child(le_set);
  1465. le_clear = memnew(Button(TTR("Clear")));
  1466. lehb->add_child(le_clear);
  1467. info_left->add_child(lehb);
  1468. le_set->set_disabled(true);
  1469. le_clear->set_disabled(true);
  1470. }
  1471. }
  1472. msgdialog = memnew(AcceptDialog);
  1473. add_child(msgdialog);
  1474. p_editor->get_undo_redo()->set_method_notify_callback(_method_changeds, this);
  1475. p_editor->get_undo_redo()->set_property_notify_callback(_property_changeds, this);
  1476. live_debug = false;
  1477. last_path_id = false;
  1478. error_count = 0;
  1479. hide_on_stop = true;
  1480. enable_external_editor = false;
  1481. last_error_count = 0;
  1482. EditorNode::get_singleton()->get_pause_button()->connect("pressed", this, "_paused");
  1483. }
  1484. ScriptEditorDebugger::~ScriptEditorDebugger() {
  1485. //inspector->edit(NULL);
  1486. memdelete(variables);
  1487. ppeer->set_stream_peer(Ref<StreamPeer>());
  1488. server->stop();
  1489. memdelete(inspected_object);
  1490. }