script_editor_debugger.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  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-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "script_editor_debugger.h"
  30. #include "scene/gui/separator.h"
  31. #include "scene/gui/label.h"
  32. #include "scene/gui/split_container.h"
  33. #include "scene/gui/tree.h"
  34. #include "scene/gui/texture_button.h"
  35. #include "scene/gui/tab_container.h"
  36. #include "scene/gui/line_edit.h"
  37. #include "scene/gui/dialogs.h"
  38. #include "scene/gui/rich_text_label.h"
  39. #include "scene/gui/margin_container.h"
  40. #include "property_editor.h"
  41. #include "globals.h"
  42. #include "editor_node.h"
  43. #include "main/performance.h"
  44. class ScriptEditorDebuggerVariables : public Object {
  45. OBJ_TYPE( ScriptEditorDebuggerVariables, Object );
  46. List<PropertyInfo> props;
  47. Map<StringName,Variant> values;
  48. protected:
  49. bool _set(const StringName& p_name, const Variant& p_value) {
  50. return false;
  51. }
  52. bool _get(const StringName& p_name,Variant &r_ret) const {
  53. if (!values.has(p_name))
  54. return false;
  55. r_ret=values[p_name];
  56. return true;
  57. }
  58. void _get_property_list( List<PropertyInfo> *p_list) const {
  59. for(const List<PropertyInfo>::Element *E=props.front();E;E=E->next() )
  60. p_list->push_back(E->get());
  61. }
  62. public:
  63. void clear() {
  64. props.clear();
  65. values.clear();
  66. }
  67. String get_var_value(const String& p_var) const {
  68. for(Map<StringName,Variant>::Element *E=values.front();E;E=E->next()) {
  69. String v = E->key().operator String().get_slice("/",1);
  70. if (v==p_var)
  71. return E->get();
  72. }
  73. return "";
  74. }
  75. void add_property(const String &p_name, const Variant& p_value) {
  76. PropertyInfo pinfo;
  77. pinfo.name=p_name;
  78. pinfo.type=p_value.get_type();
  79. props.push_back(pinfo);
  80. values[p_name]=p_value;
  81. }
  82. void update() {
  83. _change_notify();
  84. }
  85. ScriptEditorDebuggerVariables() {
  86. }
  87. };
  88. void ScriptEditorDebugger::debug_next() {
  89. ERR_FAIL_COND(!breaked);
  90. ERR_FAIL_COND(connection.is_null());
  91. ERR_FAIL_COND(!connection->is_connected());
  92. Array msg;
  93. msg.push_back("next");
  94. ppeer->put_var(msg);
  95. stack_dump->clear();
  96. inspector->edit(NULL);
  97. }
  98. void ScriptEditorDebugger::debug_step() {
  99. ERR_FAIL_COND(!breaked);
  100. ERR_FAIL_COND(connection.is_null());
  101. ERR_FAIL_COND(!connection->is_connected());
  102. Array msg;
  103. msg.push_back("step");
  104. ppeer->put_var(msg);
  105. stack_dump->clear();
  106. inspector->edit(NULL);
  107. }
  108. void ScriptEditorDebugger::debug_break() {
  109. ERR_FAIL_COND(breaked);
  110. ERR_FAIL_COND(connection.is_null());
  111. ERR_FAIL_COND(!connection->is_connected());
  112. Array msg;
  113. msg.push_back("break");
  114. ppeer->put_var(msg);
  115. }
  116. void ScriptEditorDebugger::debug_continue() {
  117. ERR_FAIL_COND(!breaked);
  118. ERR_FAIL_COND(connection.is_null());
  119. ERR_FAIL_COND(!connection->is_connected());
  120. Array msg;
  121. msg.push_back("continue");
  122. ppeer->put_var(msg);
  123. }
  124. void ScriptEditorDebugger::_scene_tree_request() {
  125. ERR_FAIL_COND(connection.is_null());
  126. ERR_FAIL_COND(!connection->is_connected());
  127. Array msg;
  128. msg.push_back("request_scene_tree");
  129. ppeer->put_var(msg);
  130. }
  131. Size2 ScriptEditorDebugger::get_minimum_size() const {
  132. Size2 ms = Control::get_minimum_size();
  133. ms.y = MAX(ms.y , 250 );
  134. return ms;
  135. }
  136. void ScriptEditorDebugger::_parse_message(const String& p_msg,const Array& p_data) {
  137. if (p_msg=="debug_enter") {
  138. Array msg;
  139. msg.push_back("get_stack_dump");
  140. ppeer->put_var(msg);
  141. ERR_FAIL_COND(p_data.size()!=2);
  142. bool can_continue=p_data[0];
  143. String error = p_data[1];
  144. step->set_disabled(!can_continue);
  145. next->set_disabled(!can_continue);
  146. reason->set_text(error);
  147. reason->set_tooltip(error);
  148. breaked=true;
  149. dobreak->set_disabled(true);
  150. docontinue->set_disabled(false);
  151. emit_signal("breaked",true,can_continue);
  152. OS::get_singleton()->move_window_to_foreground();
  153. tabs->set_current_tab(0);
  154. } else if (p_msg=="debug_exit") {
  155. breaked=false;
  156. step->set_disabled(true);
  157. next->set_disabled(true);
  158. reason->set_text("");
  159. reason->set_tooltip("");
  160. back->set_disabled(true);
  161. forward->set_disabled(true);
  162. dobreak->set_disabled(false);
  163. docontinue->set_disabled(true);
  164. emit_signal("breaked",false,false);
  165. //tabs->set_current_tab(0);
  166. } else if (p_msg=="message:click_ctrl") {
  167. clicked_ctrl->set_text(p_data[0]);
  168. clicked_ctrl_type->set_text(p_data[1]);
  169. } else if (p_msg=="message:scene_tree") {
  170. scene_tree->clear();
  171. Map<int,TreeItem*> lv;
  172. for(int i=0;i<p_data.size();i+=3) {
  173. TreeItem *p;
  174. int level = p_data[i];
  175. if (level==0) {
  176. p = NULL;
  177. } else {
  178. ERR_CONTINUE(!lv.has(level-1));
  179. p=lv[level-1];
  180. }
  181. TreeItem *it = scene_tree->create_item(p);
  182. it->set_text(0,p_data[i+1]);
  183. if (has_icon(p_data[i+2],"EditorIcons"))
  184. it->set_icon(0,get_icon(p_data[i+2],"EditorIcons"));
  185. lv[level]=it;
  186. }
  187. } else if (p_msg=="stack_dump") {
  188. stack_dump->clear();
  189. TreeItem *r = stack_dump->create_item();
  190. for(int i=0;i<p_data.size();i++) {
  191. Dictionary d = p_data[i];
  192. ERR_CONTINUE(!d.has("function"));
  193. ERR_CONTINUE(!d.has("file"));
  194. ERR_CONTINUE(!d.has("line"));
  195. ERR_CONTINUE(!d.has("id"));
  196. TreeItem *s = stack_dump->create_item(r);
  197. d["frame"]=i;
  198. s->set_metadata(0,d);
  199. // String line = itos(i)+" - "+String(d["file"])+":"+itos(d["line"])+" - at func: "+d["function"];
  200. String line = itos(i)+" - "+String(d["file"])+":"+itos(d["line"]);
  201. s->set_text(0,line);
  202. if (i==0)
  203. s->select(0);
  204. }
  205. } else if (p_msg=="stack_frame_vars") {
  206. variables->clear();
  207. int ofs =0;
  208. int mcount = p_data[ofs];
  209. ofs++;
  210. for(int i=0;i<mcount;i++) {
  211. String n = p_data[ofs+i*2+0];
  212. Variant v = p_data[ofs+i*2+1];
  213. if (n.begins_with("*")) {
  214. n=n.substr(1,n.length());
  215. }
  216. variables->add_property("members/"+n,v);
  217. }
  218. ofs+=mcount*2;
  219. mcount = p_data[ofs];
  220. ofs++;
  221. for(int i=0;i<mcount;i++) {
  222. String n = p_data[ofs+i*2+0];
  223. Variant v = p_data[ofs+i*2+1];
  224. if (n.begins_with("*")) {
  225. n=n.substr(1,n.length());
  226. }
  227. variables->add_property("locals/"+n,v);
  228. }
  229. variables->update();
  230. inspector->edit(variables);
  231. } else if (p_msg=="output") {
  232. //OUT
  233. for(int i=0;i<p_data.size();i++) {
  234. String t = p_data[i];
  235. //LOG
  236. if (EditorNode::get_log()->is_hidden()) {
  237. log_forced_visible=true;
  238. EditorNode::get_log()->show();
  239. }
  240. EditorNode::get_log()->add_message(t);
  241. }
  242. } else if (p_msg=="performance") {
  243. Array arr = p_data[0];
  244. Vector<float> p;
  245. p.resize(arr.size());
  246. for(int i=0;i<arr.size();i++) {
  247. p[i]=arr[i];
  248. if (i<perf_items.size()) {
  249. perf_items[i]->set_text(1,rtos(p[i]));
  250. if (p[i]>perf_max[i])
  251. perf_max[i]=p[i];
  252. }
  253. }
  254. perf_history.push_front(p);
  255. perf_draw->update();
  256. } else if (p_msg=="kill_me") {
  257. editor->call_deferred("stop_child_process");
  258. }
  259. }
  260. void ScriptEditorDebugger::_performance_select(Object*,int,bool) {
  261. perf_draw->update();
  262. }
  263. void ScriptEditorDebugger::_performance_draw() {
  264. Vector<int> which;
  265. for(int i=0;i<perf_items.size();i++) {
  266. if (perf_items[i]->is_selected(0))
  267. which.push_back(i);
  268. }
  269. if(which.empty())
  270. return;
  271. Color graph_color=get_color("font_color","TextEdit");
  272. Ref<StyleBox> graph_sb = get_stylebox("normal","TextEdit");
  273. Ref<Font> graph_font = get_font("font","TextEdit");
  274. int cols = Math::ceil(Math::sqrt(which.size()));
  275. int rows = (which.size()+1)/cols;
  276. if (which.size()==1)
  277. rows=1;
  278. int margin =3;
  279. int point_sep=5;
  280. Size2i s = Size2i(perf_draw->get_size())/Size2i(cols,rows);
  281. for(int i=0;i<which.size();i++) {
  282. Point2i p(i%cols,i/cols);
  283. Rect2i r(p*s,s);
  284. r.pos+=Point2(margin,margin);
  285. r.size-=Point2(margin,margin)*2.0;
  286. perf_draw->draw_style_box(graph_sb,r);
  287. r.pos+=graph_sb->get_offset();
  288. r.size-=graph_sb->get_minimum_size();
  289. int pi=which[i];
  290. Color c = Color(0.7,0.9,0.5);
  291. c.set_hsv(Math::fmod(c.get_h()+pi*0.7654,1),c.get_s(),c.get_v());
  292. c.a=0.8;
  293. perf_draw->draw_string(graph_font,r.pos+Point2(0,graph_font->get_ascent()),perf_items[pi]->get_text(0),c,r.size.x);
  294. c.a=0.6;
  295. perf_draw->draw_string(graph_font,r.pos+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);
  296. float spacing=point_sep/float(cols);
  297. float from = r.size.width;
  298. List<Vector<float> >::Element *E=perf_history.front();
  299. float prev=-1;
  300. while(from>=0 && E) {
  301. float m = perf_max[pi];
  302. if (m==0)
  303. m=0.00001;
  304. float h = E->get()[pi]/m;
  305. h=(1.0-h)*r.size.y;
  306. c.a=0.7;
  307. if (E!=perf_history.front())
  308. perf_draw->draw_line(r.pos+Point2(from,h),r.pos+Point2(from+spacing,prev),c,2.0);
  309. prev=h;
  310. E=E->next();
  311. from-=spacing;
  312. }
  313. }
  314. }
  315. void ScriptEditorDebugger::_notification(int p_what) {
  316. switch(p_what) {
  317. case NOTIFICATION_ENTER_SCENE: {
  318. step->set_icon( get_icon("DebugStep","EditorIcons"));
  319. next->set_icon( get_icon("DebugNext","EditorIcons"));
  320. back->set_icon( get_icon("Back","EditorIcons"));
  321. forward->set_icon( get_icon("Forward","EditorIcons"));
  322. dobreak->set_icon( get_icon("Pause","EditorIcons"));
  323. docontinue->set_icon( get_icon("DebugContinue","EditorIcons"));
  324. tb->set_normal_texture( get_icon("Close","EditorIcons"));
  325. tb->set_hover_texture( get_icon("CloseHover","EditorIcons"));
  326. tb->set_pressed_texture( get_icon("Close","EditorIcons"));
  327. scene_tree_refresh->set_icon( get_icon("Reload","EditorIcons"));
  328. } break;
  329. case NOTIFICATION_PROCESS: {
  330. if (connection.is_null()) {
  331. if (server->is_connection_available()) {
  332. connection = server->take_connection();
  333. if (connection.is_null())
  334. break;
  335. EditorNode::get_log()->add_message("** Debug Process Started **");
  336. log_forced_visible=false;
  337. ppeer->set_stream_peer(connection);
  338. show();
  339. dobreak->set_disabled(false);
  340. tabs->set_current_tab(0);
  341. emit_signal("show_debugger",true);
  342. reason->set_text("Child Process Connected");
  343. reason->set_tooltip("Child Process Connected");
  344. } else {
  345. break;
  346. }
  347. };
  348. if (!connection->is_connected()) {
  349. stop();
  350. editor->notify_child_process_exited(); //somehow, exited
  351. msgdialog->set_text("Process being debugged exited.");
  352. msgdialog->popup_centered(Size2(250,100));
  353. break;
  354. };
  355. if (ppeer->get_available_packet_count() <= 0) {
  356. break;
  357. };
  358. while(ppeer->get_available_packet_count() > 0) {
  359. if (pending_in_queue) {
  360. int todo = MIN( ppeer->get_available_packet_count(), pending_in_queue );
  361. for(int i=0;i<todo;i++) {
  362. Variant cmd;
  363. Error ret = ppeer->get_var(cmd);
  364. if (ret!=OK) {
  365. stop();
  366. ERR_FAIL_COND(ret!=OK);
  367. }
  368. message.push_back(cmd);
  369. pending_in_queue--;
  370. }
  371. if (pending_in_queue==0) {
  372. _parse_message(message_type,message);
  373. message.clear();
  374. }
  375. } else {
  376. if (ppeer->get_available_packet_count()>=2) {
  377. Variant cmd;
  378. Error ret = ppeer->get_var(cmd);
  379. if (ret!=OK) {
  380. stop();
  381. ERR_FAIL_COND(ret!=OK);
  382. }
  383. if (cmd.get_type()!=Variant::STRING) {
  384. stop();
  385. ERR_FAIL_COND(cmd.get_type()!=Variant::STRING);
  386. }
  387. message_type=cmd;
  388. ret = ppeer->get_var(cmd);
  389. if (ret!=OK) {
  390. stop();
  391. ERR_FAIL_COND(ret!=OK);
  392. }
  393. if (cmd.get_type()!=Variant::INT) {
  394. stop();
  395. ERR_FAIL_COND(cmd.get_type()!=Variant::INT);
  396. }
  397. pending_in_queue=cmd;
  398. if (pending_in_queue==0) {
  399. _parse_message(message_type,Array());
  400. message.clear();
  401. }
  402. } else {
  403. break;
  404. }
  405. }
  406. }
  407. } break;
  408. }
  409. }
  410. void ScriptEditorDebugger::start() {
  411. stop();
  412. uint16_t port = GLOBAL_DEF("debug/remote_port",6007);
  413. perf_history.clear();
  414. for(int i=0;i<Performance::MONITOR_MAX;i++) {
  415. perf_max[i]=0;
  416. }
  417. server->listen(port);
  418. set_process(true);
  419. }
  420. void ScriptEditorDebugger::pause(){
  421. }
  422. void ScriptEditorDebugger::unpause(){
  423. }
  424. void ScriptEditorDebugger::stop(){
  425. set_process(false);
  426. server->stop();
  427. ppeer->set_stream_peer(Ref<StreamPeer>());
  428. if (connection.is_valid()) {
  429. EditorNode::get_log()->add_message("** Debug Process Stopped **");
  430. connection.unref();
  431. }
  432. pending_in_queue=0;
  433. message.clear();
  434. if (log_forced_visible) {
  435. EditorNode::get_log()->hide();
  436. log_forced_visible=false;
  437. }
  438. hide();
  439. emit_signal("show_debugger",false);
  440. }
  441. void ScriptEditorDebugger::_stack_dump_frame_selected() {
  442. TreeItem *ti = stack_dump->get_selected();
  443. if (!ti)
  444. return;
  445. Dictionary d = ti->get_metadata(0);
  446. Ref<Script> s = ResourceLoader::load(d["file"]);
  447. emit_signal("goto_script_line",s,int(d["line"])-1);
  448. ERR_FAIL_COND(connection.is_null());
  449. ERR_FAIL_COND(!connection->is_connected());
  450. ///
  451. Array msg;
  452. msg.push_back("get_stack_frame_vars");
  453. msg.push_back(d["frame"]);
  454. ppeer->put_var(msg);
  455. }
  456. void ScriptEditorDebugger::_hide_request() {
  457. hide();
  458. emit_signal("show_debugger",false);
  459. }
  460. void ScriptEditorDebugger::_output_clear() {
  461. //output->clear();
  462. //output->push_color(Color(0,0,0));
  463. }
  464. String ScriptEditorDebugger::get_var_value(const String& p_var) const {
  465. if (!breaked)
  466. return String();
  467. return variables->get_var_value(p_var);
  468. }
  469. void ScriptEditorDebugger::_bind_methods() {
  470. ObjectTypeDB::bind_method(_MD("_stack_dump_frame_selected"),&ScriptEditorDebugger::_stack_dump_frame_selected);
  471. ObjectTypeDB::bind_method(_MD("debug_next"),&ScriptEditorDebugger::debug_next);
  472. ObjectTypeDB::bind_method(_MD("debug_step"),&ScriptEditorDebugger::debug_step);
  473. ObjectTypeDB::bind_method(_MD("debug_break"),&ScriptEditorDebugger::debug_break);
  474. ObjectTypeDB::bind_method(_MD("debug_continue"),&ScriptEditorDebugger::debug_continue);
  475. ObjectTypeDB::bind_method(_MD("_output_clear"),&ScriptEditorDebugger::_output_clear);
  476. ObjectTypeDB::bind_method(_MD("_hide_request"),&ScriptEditorDebugger::_hide_request);
  477. ObjectTypeDB::bind_method(_MD("_performance_draw"),&ScriptEditorDebugger::_performance_draw);
  478. ObjectTypeDB::bind_method(_MD("_performance_select"),&ScriptEditorDebugger::_performance_select);
  479. ObjectTypeDB::bind_method(_MD("_scene_tree_request"),&ScriptEditorDebugger::_scene_tree_request);
  480. ADD_SIGNAL(MethodInfo("goto_script_line"));
  481. ADD_SIGNAL(MethodInfo("breaked",PropertyInfo(Variant::BOOL,"reallydid")));
  482. ADD_SIGNAL(MethodInfo("show_debugger",PropertyInfo(Variant::BOOL,"reallydid")));
  483. }
  484. ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor){
  485. ppeer = Ref<PacketPeerStream>( memnew( PacketPeerStream ) );
  486. editor=p_editor;
  487. tabs = memnew( TabContainer );
  488. tabs->set_v_size_flags(SIZE_EXPAND_FILL);
  489. tabs->set_area_as_parent_rect();
  490. add_child(tabs);
  491. tb = memnew( TextureButton );
  492. tb->connect("pressed",this,"_hide_request");
  493. tb->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_END,20);
  494. tb->set_margin(MARGIN_TOP,2);
  495. add_child(tb);
  496. VBoxContainer *vbc = memnew( VBoxContainer );
  497. vbc->set_name("Debugger");
  498. //tabs->add_child(vbc);
  499. Control *dbg=vbc;
  500. HBoxContainer *hbc = memnew( HBoxContainer );
  501. vbc->add_child(hbc);
  502. reason = memnew( Label );
  503. reason->set_text("");
  504. hbc->add_child(reason);
  505. reason->add_color_override("font_color",Color(1,0.4,0.0,0.8));
  506. reason->set_h_size_flags(SIZE_EXPAND_FILL);
  507. reason->set_clip_text(true);
  508. hbc->add_child( memnew( VSeparator) );
  509. step = memnew( Button );
  510. hbc->add_child(step);
  511. step->set_tooltip("Step Into");
  512. step->connect("pressed",this,"debug_step");
  513. next = memnew( Button );
  514. hbc->add_child(next);
  515. next->set_tooltip("Step Over");
  516. next->connect("pressed",this,"debug_next");
  517. hbc->add_child( memnew( VSeparator) );
  518. dobreak = memnew( Button );
  519. hbc->add_child(dobreak);
  520. dobreak->set_tooltip("Break");
  521. dobreak->connect("pressed",this,"debug_break");
  522. docontinue = memnew( Button );
  523. hbc->add_child(docontinue);
  524. docontinue->set_tooltip("Continue");
  525. docontinue->connect("pressed",this,"debug_continue");
  526. hbc->add_child( memnew( VSeparator) );
  527. back = memnew( Button );
  528. hbc->add_child(back);
  529. back->set_tooltip("Inspect Previous Instance");
  530. forward = memnew( Button );
  531. hbc->add_child(forward);
  532. back->set_tooltip("Inspect Next Instance");
  533. HSplitContainer *sc = memnew( HSplitContainer );
  534. vbc->add_child(sc);
  535. sc->set_v_size_flags(SIZE_EXPAND_FILL);
  536. stack_dump = memnew( Tree );
  537. stack_dump->set_columns(1);
  538. stack_dump->set_column_titles_visible(true);
  539. stack_dump->set_column_title(0,"Stack Frames");
  540. stack_dump->set_h_size_flags(SIZE_EXPAND_FILL);
  541. stack_dump->set_hide_root(true);
  542. stack_dump->connect("cell_selected",this,"_stack_dump_frame_selected");
  543. sc->add_child(stack_dump);
  544. inspector = memnew( PropertyEditor );
  545. inspector->set_h_size_flags(SIZE_EXPAND_FILL);
  546. inspector->hide_top_label();
  547. inspector->get_tree()->set_column_title(0,"Variable");
  548. inspector->set_capitalize_paths(false);
  549. inspector->set_read_only(true);
  550. sc->add_child(inspector);
  551. server = TCP_Server::create_ref();
  552. pending_in_queue=0;
  553. variables = memnew( ScriptEditorDebuggerVariables );
  554. inspector->edit(variables);
  555. breaked=false;
  556. tabs->add_child(dbg);
  557. //tabs->move_child(vbc,0);
  558. hbc = memnew( HBoxContainer );
  559. vbc->add_child(hbc);
  560. HSplitContainer *hsp = memnew( HSplitContainer );
  561. perf_monitors = memnew(Tree);
  562. perf_monitors->set_columns(2);
  563. perf_monitors->set_column_title(0,"Monitor");
  564. perf_monitors->set_column_title(1,"Value");
  565. perf_monitors->set_column_titles_visible(true);
  566. hsp->add_child(perf_monitors);
  567. perf_monitors->set_select_mode(Tree::SELECT_MULTI);
  568. perf_monitors->connect("multi_selected",this,"_performance_select");
  569. perf_draw = memnew( Control );
  570. perf_draw->connect("draw",this,"_performance_draw");
  571. hsp->add_child(perf_draw);
  572. hsp->set_name("Performance");
  573. hsp->set_split_offset(300);
  574. tabs->add_child(hsp);
  575. perf_max.resize(Performance::MONITOR_MAX);
  576. Map<String,TreeItem*> bases;
  577. TreeItem *root=perf_monitors->create_item();
  578. perf_monitors->set_hide_root(true);
  579. for(int i=0;i<Performance::MONITOR_MAX;i++) {
  580. String n = Performance::get_singleton()->get_monitor_name(Performance::Monitor(i));
  581. String base = n.get_slice("/",0);
  582. String name = n.get_slice("/",1);
  583. if (!bases.has(base)) {
  584. TreeItem *b = perf_monitors->create_item(root);
  585. b->set_text(0,base.capitalize());
  586. b->set_editable(0,false);
  587. b->set_selectable(0,false);
  588. bases[base]=b;
  589. }
  590. TreeItem *it = perf_monitors->create_item(bases[base]);
  591. it->set_editable(0,false);
  592. it->set_selectable(0,true);
  593. it->set_text(0,name.capitalize());
  594. perf_items.push_back(it);
  595. perf_max[i]=0;
  596. }
  597. info = memnew( HSplitContainer );
  598. info->set_name("Info");
  599. tabs->add_child(info);
  600. VBoxContainer *info_left = memnew( VBoxContainer );
  601. info_left->set_h_size_flags(SIZE_EXPAND_FILL);
  602. info->add_child(info_left);
  603. clicked_ctrl = memnew( LineEdit );
  604. info_left->add_margin_child("Clicked Control:",clicked_ctrl);
  605. clicked_ctrl_type = memnew( LineEdit );
  606. info_left->add_margin_child("Clicked Control Type:",clicked_ctrl_type);
  607. VBoxContainer *info_right = memnew(VBoxContainer);
  608. info_right->set_h_size_flags(SIZE_EXPAND_FILL);
  609. info->add_child(info_right);
  610. HBoxContainer *inforhb = memnew( HBoxContainer );
  611. info_right->add_child(inforhb);
  612. Label *l2 = memnew( Label("Scene Tree:" ) );
  613. l2->set_h_size_flags(SIZE_EXPAND_FILL);
  614. inforhb->add_child( l2 );
  615. Button *refresh = memnew( Button );
  616. inforhb->add_child(refresh);
  617. refresh->connect("pressed",this,"_scene_tree_request");
  618. scene_tree_refresh=refresh;
  619. MarginContainer *infomc = memnew( MarginContainer );
  620. info_right->add_child(infomc);
  621. infomc->set_v_size_flags(SIZE_EXPAND_FILL);
  622. scene_tree = memnew( Tree );
  623. infomc->add_child(scene_tree);
  624. msgdialog = memnew( AcceptDialog );
  625. add_child(msgdialog);
  626. hide();
  627. log_forced_visible=false;
  628. }
  629. ScriptEditorDebugger::~ScriptEditorDebugger() {
  630. // inspector->edit(NULL);
  631. memdelete(variables);
  632. ppeer->set_stream_peer(Ref<StreamPeer>());
  633. server->stop();
  634. }