script_debugger_remote.cpp 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  1. /*************************************************************************/
  2. /* script_debugger_remote.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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_debugger_remote.h"
  31. #include "core/engine.h"
  32. #include "core/io/ip.h"
  33. #include "core/io/marshalls.h"
  34. #include "core/os/input.h"
  35. #include "core/os/os.h"
  36. #include "core/project_settings.h"
  37. #include "scene/main/node.h"
  38. #include "scene/main/scene_tree.h"
  39. #include "scene/main/viewport.h"
  40. #include "scene/resources/packed_scene.h"
  41. #include "servers/visual_server.h"
  42. void ScriptDebuggerRemote::_send_video_memory() {
  43. List<ResourceUsage> usage;
  44. if (resource_usage_func) {
  45. resource_usage_func(&usage);
  46. }
  47. usage.sort();
  48. packet_peer_stream->put_var("message:video_mem");
  49. packet_peer_stream->put_var(usage.size() * 4);
  50. for (List<ResourceUsage>::Element *E = usage.front(); E; E = E->next()) {
  51. packet_peer_stream->put_var(E->get().path);
  52. packet_peer_stream->put_var(E->get().type);
  53. packet_peer_stream->put_var(E->get().format);
  54. packet_peer_stream->put_var(E->get().vram);
  55. }
  56. }
  57. Error ScriptDebuggerRemote::connect_to_host(const String &p_host, uint16_t p_port) {
  58. IP_Address ip;
  59. if (p_host.is_valid_ip_address()) {
  60. ip = p_host;
  61. } else {
  62. ip = IP::get_singleton()->resolve_hostname(p_host);
  63. }
  64. int port = p_port;
  65. const int tries = 6;
  66. int waits[tries] = { 1, 10, 100, 1000, 1000, 1000 };
  67. tcp_client->connect_to_host(ip, port);
  68. for (int i = 0; i < tries; i++) {
  69. if (tcp_client->get_status() == StreamPeerTCP::STATUS_CONNECTED) {
  70. print_verbose("Remote Debugger: Connected!");
  71. break;
  72. } else {
  73. const int ms = waits[i];
  74. OS::get_singleton()->delay_usec(ms * 1000);
  75. print_verbose("Remote Debugger: Connection failed with status: '" + String::num(tcp_client->get_status()) + "', retrying in " + String::num(ms) + " msec.");
  76. };
  77. };
  78. if (tcp_client->get_status() != StreamPeerTCP::STATUS_CONNECTED) {
  79. ERR_PRINT("Remote Debugger: Unable to connect. Status: " + String::num(tcp_client->get_status()) + ".");
  80. return FAILED;
  81. };
  82. packet_peer_stream->set_stream_peer(tcp_client);
  83. return OK;
  84. }
  85. void ScriptDebuggerRemote::_put_variable(const String &p_name, const Variant &p_variable) {
  86. packet_peer_stream->put_var(p_name);
  87. Variant var = p_variable;
  88. if (p_variable.get_type() == Variant::OBJECT && p_variable.operator Object *() == nullptr) {
  89. var = Variant();
  90. }
  91. int len = 0;
  92. Error err = encode_variant(var, nullptr, len, true);
  93. if (err != OK)
  94. ERR_PRINT("Failed to encode variant.");
  95. if (len > packet_peer_stream->get_output_buffer_max_size()) { //limit to max size
  96. packet_peer_stream->put_var(Variant());
  97. } else {
  98. packet_peer_stream->put_var(var);
  99. }
  100. }
  101. void ScriptDebuggerRemote::_save_node(ObjectID id, const String &p_path) {
  102. Node *node = Object::cast_to<Node>(ObjectDB::get_instance(id));
  103. ERR_FAIL_COND(!node);
  104. Ref<PackedScene> ps = memnew(PackedScene);
  105. ps->pack(node);
  106. ResourceSaver::save(p_path, ps);
  107. }
  108. void ScriptDebuggerRemote::debug(ScriptLanguage *p_script, bool p_can_continue, bool p_is_error_breakpoint) {
  109. //this function is called when there is a debugger break (bug on script)
  110. //or when execution is paused from editor
  111. if (skip_breakpoints && !p_is_error_breakpoint) {
  112. return;
  113. }
  114. ERR_FAIL_COND_MSG(!tcp_client->is_connected_to_host(), "Script Debugger failed to connect, but being used anyway.");
  115. if (allow_focus_steal_pid) {
  116. OS::get_singleton()->enable_for_stealing_focus(allow_focus_steal_pid);
  117. }
  118. packet_peer_stream->put_var("debug_enter");
  119. packet_peer_stream->put_var(2);
  120. packet_peer_stream->put_var(p_can_continue);
  121. packet_peer_stream->put_var(p_script->debug_get_error());
  122. skip_profile_frame = true; // to avoid super long frame time for the frame
  123. Input::MouseMode mouse_mode = Input::get_singleton()->get_mouse_mode();
  124. if (mouse_mode != Input::MOUSE_MODE_VISIBLE) {
  125. Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
  126. }
  127. uint64_t loop_begin_usec = 0;
  128. uint64_t loop_time_sec = 0;
  129. while (true) {
  130. loop_begin_usec = OS::get_singleton()->get_ticks_usec();
  131. _get_output();
  132. if (packet_peer_stream->get_available_packet_count() > 0) {
  133. Variant var;
  134. Error err = packet_peer_stream->get_var(var);
  135. ERR_CONTINUE(err != OK);
  136. ERR_CONTINUE(var.get_type() != Variant::ARRAY);
  137. Array cmd = var;
  138. ERR_CONTINUE(cmd.size() == 0);
  139. ERR_CONTINUE(cmd[0].get_type() != Variant::STRING);
  140. String command = cmd[0];
  141. if (command == "get_stack_dump") {
  142. packet_peer_stream->put_var("stack_dump");
  143. int slc = p_script->debug_get_stack_level_count();
  144. packet_peer_stream->put_var(slc);
  145. for (int i = 0; i < slc; i++) {
  146. Dictionary d;
  147. d["file"] = p_script->debug_get_stack_level_source(i);
  148. d["line"] = p_script->debug_get_stack_level_line(i);
  149. d["function"] = p_script->debug_get_stack_level_function(i);
  150. //d["id"]=p_script->debug_get_stack_level_
  151. d["id"] = 0;
  152. packet_peer_stream->put_var(d);
  153. }
  154. } else if (command == "get_stack_frame_vars") {
  155. cmd.remove(0);
  156. ERR_CONTINUE(cmd.size() != 1);
  157. int lv = cmd[0];
  158. List<String> members;
  159. List<Variant> member_vals;
  160. if (ScriptInstance *inst = p_script->debug_get_stack_level_instance(lv)) {
  161. members.push_back("self");
  162. member_vals.push_back(inst->get_owner());
  163. }
  164. p_script->debug_get_stack_level_members(lv, &members, &member_vals);
  165. ERR_CONTINUE(members.size() != member_vals.size());
  166. List<String> locals;
  167. List<Variant> local_vals;
  168. p_script->debug_get_stack_level_locals(lv, &locals, &local_vals);
  169. ERR_CONTINUE(locals.size() != local_vals.size());
  170. List<String> globals;
  171. List<Variant> globals_vals;
  172. p_script->debug_get_globals(&globals, &globals_vals);
  173. ERR_CONTINUE(globals.size() != globals_vals.size());
  174. packet_peer_stream->put_var("stack_frame_vars");
  175. packet_peer_stream->put_var(3 + (locals.size() + members.size() + globals.size()) * 2);
  176. { //locals
  177. packet_peer_stream->put_var(locals.size());
  178. List<String>::Element *E = locals.front();
  179. List<Variant>::Element *F = local_vals.front();
  180. while (E) {
  181. _put_variable(E->get(), F->get());
  182. E = E->next();
  183. F = F->next();
  184. }
  185. }
  186. { //members
  187. packet_peer_stream->put_var(members.size());
  188. List<String>::Element *E = members.front();
  189. List<Variant>::Element *F = member_vals.front();
  190. while (E) {
  191. _put_variable(E->get(), F->get());
  192. E = E->next();
  193. F = F->next();
  194. }
  195. }
  196. { //globals
  197. packet_peer_stream->put_var(globals.size());
  198. List<String>::Element *E = globals.front();
  199. List<Variant>::Element *F = globals_vals.front();
  200. while (E) {
  201. _put_variable(E->get(), F->get());
  202. E = E->next();
  203. F = F->next();
  204. }
  205. }
  206. } else if (command == "step") {
  207. set_depth(-1);
  208. set_lines_left(1);
  209. break;
  210. } else if (command == "next") {
  211. set_depth(0);
  212. set_lines_left(1);
  213. break;
  214. } else if (command == "continue") {
  215. set_depth(-1);
  216. set_lines_left(-1);
  217. OS::get_singleton()->move_window_to_foreground();
  218. break;
  219. } else if (command == "break") {
  220. ERR_PRINT("Got break when already broke!");
  221. break;
  222. } else if (command == "request_scene_tree") {
  223. #ifdef DEBUG_ENABLED
  224. if (scene_tree) {
  225. scene_tree->_debugger_request_tree();
  226. }
  227. #endif
  228. } else if (command == "request_video_mem") {
  229. _send_video_memory();
  230. } else if (command == "inspect_object") {
  231. ObjectID id = cmd[1];
  232. _send_object_id(id);
  233. } else if (command == "set_object_property") {
  234. _set_object_property(cmd[1], cmd[2], cmd[3]);
  235. } else if (command == "override_camera_2D:set") {
  236. bool enforce = cmd[1];
  237. if (scene_tree) {
  238. scene_tree->get_root()->enable_canvas_transform_override(enforce);
  239. }
  240. } else if (command == "override_camera_2D:transform") {
  241. Transform2D transform = cmd[1];
  242. if (scene_tree) {
  243. scene_tree->get_root()->set_canvas_transform_override(transform);
  244. }
  245. } else if (command == "override_camera_3D:set") {
  246. bool enable = cmd[1];
  247. if (scene_tree) {
  248. scene_tree->get_root()->enable_camera_override(enable);
  249. }
  250. } else if (command == "override_camera_3D:transform") {
  251. Transform transform = cmd[1];
  252. bool is_perspective = cmd[2];
  253. float size_or_fov = cmd[3];
  254. float near = cmd[4];
  255. float far = cmd[5];
  256. if (scene_tree) {
  257. if (is_perspective) {
  258. scene_tree->get_root()->set_camera_override_perspective(size_or_fov, near, far);
  259. } else {
  260. scene_tree->get_root()->set_camera_override_orthogonal(size_or_fov, near, far);
  261. }
  262. scene_tree->get_root()->set_camera_override_transform(transform);
  263. }
  264. } else if (command == "reload_scripts") {
  265. reload_all_scripts = true;
  266. } else if (command == "breakpoint") {
  267. bool set = cmd[3];
  268. if (set) {
  269. insert_breakpoint(cmd[2], cmd[1]);
  270. } else {
  271. remove_breakpoint(cmd[2], cmd[1]);
  272. }
  273. } else if (command == "save_node") {
  274. _save_node(cmd[1], cmd[2]);
  275. } else if (command == "set_skip_breakpoints") {
  276. skip_breakpoints = cmd[1];
  277. } else {
  278. _parse_live_edit(cmd);
  279. }
  280. } else {
  281. OS::get_singleton()->delay_usec(10000);
  282. OS::get_singleton()->process_and_drop_events();
  283. }
  284. // This is for the camera override to stay live even when the game is paused from the editor
  285. loop_time_sec = (OS::get_singleton()->get_ticks_usec() - loop_begin_usec) / 1000000.0f;
  286. VisualServer::get_singleton()->sync();
  287. if (VisualServer::get_singleton()->has_changed()) {
  288. VisualServer::get_singleton()->draw(true, loop_time_sec * Engine::get_singleton()->get_time_scale());
  289. }
  290. }
  291. packet_peer_stream->put_var("debug_exit");
  292. packet_peer_stream->put_var(0);
  293. if (mouse_mode != Input::MOUSE_MODE_VISIBLE) {
  294. Input::get_singleton()->set_mouse_mode(mouse_mode);
  295. }
  296. }
  297. void ScriptDebuggerRemote::_get_output() {
  298. mutex.lock();
  299. if (output_strings.size()) {
  300. locking = true;
  301. packet_peer_stream->put_var("output");
  302. packet_peer_stream->put_var(output_strings.size());
  303. while (output_strings.size()) {
  304. const OutputString &output_string = output_strings.front()->get();
  305. Array msg_data;
  306. msg_data.push_back(output_string.message);
  307. msg_data.push_back(output_string.type);
  308. packet_peer_stream->put_var(msg_data);
  309. output_strings.pop_front();
  310. }
  311. locking = false;
  312. }
  313. if (n_messages_dropped > 0) {
  314. Message msg;
  315. msg.message = "Too many messages! " + String::num_int64(n_messages_dropped) + " messages were dropped.";
  316. messages.push_back(msg);
  317. n_messages_dropped = 0;
  318. }
  319. while (messages.size()) {
  320. locking = true;
  321. packet_peer_stream->put_var("message:" + messages.front()->get().message);
  322. packet_peer_stream->put_var(messages.front()->get().data.size());
  323. for (int i = 0; i < messages.front()->get().data.size(); i++) {
  324. packet_peer_stream->put_var(messages.front()->get().data[i]);
  325. }
  326. messages.pop_front();
  327. locking = false;
  328. }
  329. if (n_errors_dropped == 1) {
  330. // Only print one message about dropping per second
  331. OutputError oe;
  332. oe.error = "TOO_MANY_ERRORS";
  333. oe.error_descr = "Too many errors! Ignoring errors for up to 1 second.";
  334. oe.warning = false;
  335. uint64_t time = OS::get_singleton()->get_ticks_msec();
  336. oe.hr = time / 3600000;
  337. oe.min = (time / 60000) % 60;
  338. oe.sec = (time / 1000) % 60;
  339. oe.msec = time % 1000;
  340. errors.push_back(oe);
  341. }
  342. if (n_warnings_dropped == 1) {
  343. // Only print one message about dropping per second
  344. OutputError oe;
  345. oe.error = "TOO_MANY_WARNINGS";
  346. oe.error_descr = "Too many warnings! Ignoring warnings for up to 1 second.";
  347. oe.warning = true;
  348. uint64_t time = OS::get_singleton()->get_ticks_msec();
  349. oe.hr = time / 3600000;
  350. oe.min = (time / 60000) % 60;
  351. oe.sec = (time / 1000) % 60;
  352. oe.msec = time % 1000;
  353. errors.push_back(oe);
  354. }
  355. while (errors.size()) {
  356. locking = true;
  357. packet_peer_stream->put_var("error");
  358. OutputError oe = errors.front()->get();
  359. packet_peer_stream->put_var(oe.callstack.size() + 2);
  360. Array error_data;
  361. error_data.push_back(oe.hr);
  362. error_data.push_back(oe.min);
  363. error_data.push_back(oe.sec);
  364. error_data.push_back(oe.msec);
  365. error_data.push_back(oe.source_func);
  366. error_data.push_back(oe.source_file);
  367. error_data.push_back(oe.source_line);
  368. error_data.push_back(oe.error);
  369. error_data.push_back(oe.error_descr);
  370. error_data.push_back(oe.warning);
  371. packet_peer_stream->put_var(error_data);
  372. packet_peer_stream->put_var(oe.callstack.size());
  373. for (int i = 0; i < oe.callstack.size(); i++) {
  374. packet_peer_stream->put_var(oe.callstack[i]);
  375. }
  376. errors.pop_front();
  377. locking = false;
  378. }
  379. mutex.unlock();
  380. }
  381. void ScriptDebuggerRemote::line_poll() {
  382. //the purpose of this is just processing events every now and then when the script might get too busy
  383. //otherwise bugs like infinite loops can't be caught
  384. if (poll_every % 2048 == 0) {
  385. _poll_events();
  386. }
  387. poll_every++;
  388. }
  389. void ScriptDebuggerRemote::_err_handler(void *ud, const char *p_func, const char *p_file, int p_line, const char *p_err, const char *p_descr, ErrorHandlerType p_type) {
  390. if (p_type == ERR_HANDLER_SCRIPT) {
  391. return; //ignore script errors, those go through debugger
  392. }
  393. Vector<ScriptLanguage::StackInfo> si;
  394. for (int i = 0; i < ScriptServer::get_language_count(); i++) {
  395. si = ScriptServer::get_language(i)->debug_get_current_stack_info();
  396. if (si.size()) {
  397. break;
  398. }
  399. }
  400. ScriptDebuggerRemote *sdr = (ScriptDebuggerRemote *)ud;
  401. sdr->send_error(p_func, p_file, p_line, p_err, p_descr, p_type, si);
  402. }
  403. bool ScriptDebuggerRemote::_parse_live_edit(const Array &p_command) {
  404. #ifdef DEBUG_ENABLED
  405. String cmdstr = p_command[0];
  406. if (!scene_tree || !cmdstr.begins_with("live_")) {
  407. return false;
  408. }
  409. if (cmdstr == "live_set_root") {
  410. scene_tree->_live_edit_root_func(p_command[1], p_command[2]);
  411. } else if (cmdstr == "live_node_path") {
  412. scene_tree->_live_edit_node_path_func(p_command[1], p_command[2]);
  413. } else if (cmdstr == "live_res_path") {
  414. scene_tree->_live_edit_res_path_func(p_command[1], p_command[2]);
  415. } else if (cmdstr == "live_node_prop_res") {
  416. scene_tree->_live_edit_node_set_res_func(p_command[1], p_command[2], p_command[3]);
  417. } else if (cmdstr == "live_node_prop") {
  418. scene_tree->_live_edit_node_set_func(p_command[1], p_command[2], p_command[3]);
  419. } else if (cmdstr == "live_res_prop_res") {
  420. scene_tree->_live_edit_res_set_res_func(p_command[1], p_command[2], p_command[3]);
  421. } else if (cmdstr == "live_res_prop") {
  422. scene_tree->_live_edit_res_set_func(p_command[1], p_command[2], p_command[3]);
  423. } else if (cmdstr == "live_node_call") {
  424. scene_tree->_live_edit_node_call_func(p_command[1], p_command[2], p_command[3], p_command[4], p_command[5], p_command[6], p_command[7]);
  425. } else if (cmdstr == "live_res_call") {
  426. scene_tree->_live_edit_res_call_func(p_command[1], p_command[2], p_command[3], p_command[4], p_command[5], p_command[6], p_command[7]);
  427. } else if (cmdstr == "live_create_node") {
  428. scene_tree->_live_edit_create_node_func(p_command[1], p_command[2], p_command[3]);
  429. } else if (cmdstr == "live_instance_node") {
  430. scene_tree->_live_edit_instance_node_func(p_command[1], p_command[2], p_command[3]);
  431. } else if (cmdstr == "live_remove_node") {
  432. scene_tree->_live_edit_remove_node_func(p_command[1]);
  433. } else if (cmdstr == "live_remove_and_keep_node") {
  434. scene_tree->_live_edit_remove_and_keep_node_func(p_command[1], p_command[2]);
  435. } else if (cmdstr == "live_restore_node") {
  436. scene_tree->_live_edit_restore_node_func(p_command[1], p_command[2], p_command[3]);
  437. } else if (cmdstr == "live_duplicate_node") {
  438. scene_tree->_live_edit_duplicate_node_func(p_command[1], p_command[2]);
  439. } else if (cmdstr == "live_reparent_node") {
  440. scene_tree->_live_edit_reparent_node_func(p_command[1], p_command[2], p_command[3], p_command[4]);
  441. } else {
  442. return false;
  443. }
  444. return true;
  445. #else
  446. return false;
  447. #endif
  448. }
  449. void ScriptDebuggerRemote::_send_object_id(ObjectID p_id) {
  450. Object *obj = ObjectDB::get_instance(p_id);
  451. if (!obj) {
  452. return;
  453. }
  454. typedef Pair<PropertyInfo, Variant> PropertyDesc;
  455. List<PropertyDesc> properties;
  456. if (ScriptInstance *si = obj->get_script_instance()) {
  457. if (!si->get_script().is_null()) {
  458. typedef Map<const Script *, Set<StringName>> ScriptMemberMap;
  459. typedef Map<const Script *, Map<StringName, Variant>> ScriptConstantsMap;
  460. ScriptMemberMap members;
  461. members[si->get_script().ptr()] = Set<StringName>();
  462. si->get_script()->get_members(&(members[si->get_script().ptr()]));
  463. ScriptConstantsMap constants;
  464. constants[si->get_script().ptr()] = Map<StringName, Variant>();
  465. si->get_script()->get_constants(&(constants[si->get_script().ptr()]));
  466. Ref<Script> base = si->get_script()->get_base_script();
  467. while (base.is_valid()) {
  468. members[base.ptr()] = Set<StringName>();
  469. base->get_members(&(members[base.ptr()]));
  470. constants[base.ptr()] = Map<StringName, Variant>();
  471. base->get_constants(&(constants[base.ptr()]));
  472. base = base->get_base_script();
  473. }
  474. for (ScriptMemberMap::Element *sm = members.front(); sm; sm = sm->next()) {
  475. for (Set<StringName>::Element *E = sm->get().front(); E; E = E->next()) {
  476. Variant m;
  477. if (si->get(E->get(), m)) {
  478. String script_path = sm->key() == si->get_script().ptr() ? "" : sm->key()->get_path().get_file() + "/";
  479. PropertyInfo pi(m.get_type(), "Members/" + script_path + E->get());
  480. properties.push_back(PropertyDesc(pi, m));
  481. }
  482. }
  483. }
  484. for (ScriptConstantsMap::Element *sc = constants.front(); sc; sc = sc->next()) {
  485. for (Map<StringName, Variant>::Element *E = sc->get().front(); E; E = E->next()) {
  486. String script_path = sc->key() == si->get_script().ptr() ? "" : sc->key()->get_path().get_file() + "/";
  487. if (E->value().get_type() == Variant::OBJECT) {
  488. Variant id = ((Object *)E->value())->get_instance_id();
  489. PropertyInfo pi(id.get_type(), "Constants/" + E->key(), PROPERTY_HINT_OBJECT_ID, "Object");
  490. properties.push_back(PropertyDesc(pi, id));
  491. } else {
  492. PropertyInfo pi(E->value().get_type(), "Constants/" + script_path + E->key());
  493. properties.push_back(PropertyDesc(pi, E->value()));
  494. }
  495. }
  496. }
  497. }
  498. }
  499. if (Node *node = Object::cast_to<Node>(obj)) {
  500. // in some cases node will not be in tree here
  501. // for instance where it created as variable and not yet added to tree
  502. // in such cases we can't ask for it's path
  503. if (node->is_inside_tree()) {
  504. PropertyInfo pi(Variant::NODE_PATH, String("Node/path"));
  505. properties.push_front(PropertyDesc(pi, node->get_path()));
  506. } else {
  507. PropertyInfo pi(Variant::STRING, String("Node/path"));
  508. properties.push_front(PropertyDesc(pi, "[Orphan]"));
  509. }
  510. } else if (Resource *res = Object::cast_to<Resource>(obj)) {
  511. if (Script *s = Object::cast_to<Script>(res)) {
  512. Map<StringName, Variant> constants;
  513. s->get_constants(&constants);
  514. for (Map<StringName, Variant>::Element *E = constants.front(); E; E = E->next()) {
  515. if (E->value().get_type() == Variant::OBJECT) {
  516. Variant id = ((Object *)E->value())->get_instance_id();
  517. PropertyInfo pi(id.get_type(), "Constants/" + E->key(), PROPERTY_HINT_OBJECT_ID, "Object");
  518. properties.push_front(PropertyDesc(pi, E->value()));
  519. } else {
  520. PropertyInfo pi(E->value().get_type(), String("Constants/") + E->key());
  521. properties.push_front(PropertyDesc(pi, E->value()));
  522. }
  523. }
  524. }
  525. }
  526. List<PropertyInfo> pinfo;
  527. obj->get_property_list(&pinfo, true);
  528. for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
  529. if (E->get().usage & (PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CATEGORY)) {
  530. properties.push_back(PropertyDesc(E->get(), obj->get(E->get().name)));
  531. }
  532. }
  533. Array send_props;
  534. for (int i = 0; i < properties.size(); i++) {
  535. const PropertyInfo &pi = properties[i].first;
  536. Variant &var = properties[i].second;
  537. RES res = var;
  538. Array prop;
  539. prop.push_back(pi.name);
  540. prop.push_back(pi.type);
  541. //only send information that can be sent..
  542. int len = 0; //test how big is this to encode
  543. encode_variant(var, nullptr, len);
  544. if (len > packet_peer_stream->get_output_buffer_max_size()) { //limit to max size
  545. prop.push_back(PROPERTY_HINT_OBJECT_TOO_BIG);
  546. prop.push_back("");
  547. prop.push_back(pi.usage);
  548. prop.push_back(Variant());
  549. } else {
  550. prop.push_back(pi.hint);
  551. prop.push_back(pi.hint_string);
  552. prop.push_back(pi.usage);
  553. if (!res.is_null() && !res->get_path().empty()) {
  554. var = res->get_path();
  555. }
  556. prop.push_back(var);
  557. }
  558. send_props.push_back(prop);
  559. }
  560. packet_peer_stream->put_var("message:inspect_object");
  561. packet_peer_stream->put_var(3);
  562. packet_peer_stream->put_var(p_id);
  563. packet_peer_stream->put_var(obj->get_class());
  564. packet_peer_stream->put_var(send_props);
  565. }
  566. void ScriptDebuggerRemote::_set_object_property(ObjectID p_id, const String &p_property, const Variant &p_value) {
  567. Object *obj = ObjectDB::get_instance(p_id);
  568. if (!obj) {
  569. return;
  570. }
  571. String prop_name = p_property;
  572. if (p_property.begins_with("Members/")) {
  573. Vector<String> ss = p_property.split("/");
  574. prop_name = ss[ss.size() - 1];
  575. }
  576. obj->set(prop_name, p_value);
  577. }
  578. void ScriptDebuggerRemote::_poll_events() {
  579. //this si called from ::idle_poll, happens only when running the game,
  580. //does not get called while on debug break
  581. while (packet_peer_stream->get_available_packet_count() > 0) {
  582. _get_output();
  583. //send over output_strings
  584. Variant var;
  585. Error err = packet_peer_stream->get_var(var);
  586. ERR_CONTINUE(err != OK);
  587. ERR_CONTINUE(var.get_type() != Variant::ARRAY);
  588. Array cmd = var;
  589. ERR_CONTINUE(cmd.size() == 0);
  590. ERR_CONTINUE(cmd[0].get_type() != Variant::STRING);
  591. String command = cmd[0];
  592. //cmd.remove(0);
  593. if (command == "break") {
  594. if (get_break_language()) {
  595. debug(get_break_language());
  596. }
  597. } else if (command == "request_scene_tree") {
  598. #ifdef DEBUG_ENABLED
  599. if (scene_tree) {
  600. scene_tree->_debugger_request_tree();
  601. }
  602. #endif
  603. } else if (command == "request_video_mem") {
  604. _send_video_memory();
  605. } else if (command == "inspect_object") {
  606. ObjectID id = cmd[1];
  607. _send_object_id(id);
  608. } else if (command == "set_object_property") {
  609. _set_object_property(cmd[1], cmd[2], cmd[3]);
  610. } else if (command == "start_profiling") {
  611. for (int i = 0; i < ScriptServer::get_language_count(); i++) {
  612. ScriptServer::get_language(i)->profiling_start();
  613. }
  614. max_frame_functions = cmd[1];
  615. profiler_function_signature_map.clear();
  616. profiling = true;
  617. frame_time = 0;
  618. idle_time = 0;
  619. physics_time = 0;
  620. physics_frame_time = 0;
  621. print_line("PROFILING ALRIGHT!");
  622. } else if (command == "stop_profiling") {
  623. for (int i = 0; i < ScriptServer::get_language_count(); i++) {
  624. ScriptServer::get_language(i)->profiling_stop();
  625. }
  626. profiling = false;
  627. _send_profiling_data(false);
  628. print_line("PROFILING END!");
  629. } else if (command == "start_network_profiling") {
  630. multiplayer->profiling_start();
  631. profiling_network = true;
  632. } else if (command == "stop_network_profiling") {
  633. multiplayer->profiling_end();
  634. profiling_network = false;
  635. } else if (command == "override_camera_2D:set") {
  636. bool enforce = cmd[1];
  637. if (scene_tree) {
  638. scene_tree->get_root()->enable_canvas_transform_override(enforce);
  639. }
  640. } else if (command == "override_camera_2D:transform") {
  641. Transform2D transform = cmd[1];
  642. if (scene_tree) {
  643. scene_tree->get_root()->set_canvas_transform_override(transform);
  644. }
  645. } else if (command == "override_camera_3D:set") {
  646. bool enable = cmd[1];
  647. if (scene_tree) {
  648. scene_tree->get_root()->enable_camera_override(enable);
  649. }
  650. } else if (command == "override_camera_3D:transform") {
  651. Transform transform = cmd[1];
  652. bool is_perspective = cmd[2];
  653. float size_or_fov = cmd[3];
  654. float near = cmd[4];
  655. float far = cmd[5];
  656. if (scene_tree) {
  657. if (is_perspective) {
  658. scene_tree->get_root()->set_camera_override_perspective(size_or_fov, near, far);
  659. } else {
  660. scene_tree->get_root()->set_camera_override_orthogonal(size_or_fov, near, far);
  661. }
  662. scene_tree->get_root()->set_camera_override_transform(transform);
  663. }
  664. } else if (command == "reload_scripts") {
  665. reload_all_scripts = true;
  666. } else if (command == "breakpoint") {
  667. bool set = cmd[3];
  668. if (set) {
  669. insert_breakpoint(cmd[2], cmd[1]);
  670. } else {
  671. remove_breakpoint(cmd[2], cmd[1]);
  672. }
  673. } else if (command == "set_skip_breakpoints") {
  674. skip_breakpoints = cmd[1];
  675. } else {
  676. _parse_live_edit(cmd);
  677. }
  678. }
  679. }
  680. void ScriptDebuggerRemote::_send_profiling_data(bool p_for_frame) {
  681. int ofs = 0;
  682. for (int i = 0; i < ScriptServer::get_language_count(); i++) {
  683. if (p_for_frame) {
  684. ofs += ScriptServer::get_language(i)->profiling_get_frame_data(&profile_info.write[ofs], profile_info.size() - ofs);
  685. } else {
  686. ofs += ScriptServer::get_language(i)->profiling_get_accumulated_data(&profile_info.write[ofs], profile_info.size() - ofs);
  687. }
  688. }
  689. for (int i = 0; i < ofs; i++) {
  690. profile_info_ptrs.write[i] = &profile_info.write[i];
  691. }
  692. SortArray<ScriptLanguage::ProfilingInfo *, ProfileInfoSort> sa;
  693. sa.sort(profile_info_ptrs.ptrw(), ofs);
  694. int to_send = MIN(ofs, max_frame_functions);
  695. //check signatures first
  696. uint64_t total_script_time = 0;
  697. for (int i = 0; i < to_send; i++) {
  698. if (!profiler_function_signature_map.has(profile_info_ptrs[i]->signature)) {
  699. int idx = profiler_function_signature_map.size();
  700. packet_peer_stream->put_var("profile_sig");
  701. packet_peer_stream->put_var(2);
  702. packet_peer_stream->put_var(profile_info_ptrs[i]->signature);
  703. packet_peer_stream->put_var(idx);
  704. profiler_function_signature_map[profile_info_ptrs[i]->signature] = idx;
  705. }
  706. total_script_time += profile_info_ptrs[i]->self_time;
  707. }
  708. //send frames then
  709. if (p_for_frame) {
  710. packet_peer_stream->put_var("profile_frame");
  711. packet_peer_stream->put_var(8 + profile_frame_data.size() * 2 + to_send * 4);
  712. } else {
  713. packet_peer_stream->put_var("profile_total");
  714. packet_peer_stream->put_var(8 + to_send * 4);
  715. }
  716. packet_peer_stream->put_var(Engine::get_singleton()->get_idle_frames()); //total frame time
  717. packet_peer_stream->put_var(frame_time); //total frame time
  718. packet_peer_stream->put_var(idle_time); //idle frame time
  719. packet_peer_stream->put_var(physics_time); //fixed frame time
  720. packet_peer_stream->put_var(physics_frame_time); //fixed frame time
  721. packet_peer_stream->put_var(USEC_TO_SEC(total_script_time)); //total script execution time
  722. if (p_for_frame) {
  723. packet_peer_stream->put_var(profile_frame_data.size()); //how many profile framedatas to send
  724. packet_peer_stream->put_var(to_send); //how many script functions to send
  725. for (int i = 0; i < profile_frame_data.size(); i++) {
  726. packet_peer_stream->put_var(profile_frame_data[i].name);
  727. packet_peer_stream->put_var(profile_frame_data[i].data);
  728. }
  729. } else {
  730. packet_peer_stream->put_var(0); //how many script functions to send
  731. packet_peer_stream->put_var(to_send); //how many script functions to send
  732. }
  733. for (int i = 0; i < to_send; i++) {
  734. int sig_id = -1;
  735. if (profiler_function_signature_map.has(profile_info_ptrs[i]->signature)) {
  736. sig_id = profiler_function_signature_map[profile_info_ptrs[i]->signature];
  737. }
  738. packet_peer_stream->put_var(sig_id);
  739. packet_peer_stream->put_var(profile_info_ptrs[i]->call_count);
  740. packet_peer_stream->put_var(profile_info_ptrs[i]->total_time / 1000000.0);
  741. packet_peer_stream->put_var(profile_info_ptrs[i]->self_time / 1000000.0);
  742. }
  743. if (p_for_frame) {
  744. profile_frame_data.clear();
  745. }
  746. }
  747. void ScriptDebuggerRemote::idle_poll() {
  748. // this function is called every frame, except when there is a debugger break (::debug() in this class)
  749. // execution stops and remains in the ::debug function
  750. _get_output();
  751. if (requested_quit) {
  752. packet_peer_stream->put_var("kill_me");
  753. packet_peer_stream->put_var(0);
  754. requested_quit = false;
  755. }
  756. if (performance) {
  757. uint64_t pt = OS::get_singleton()->get_ticks_msec();
  758. if (pt - last_perf_time > 1000) {
  759. last_perf_time = pt;
  760. int max = performance->get("MONITOR_MAX");
  761. Array arr;
  762. arr.resize(max);
  763. for (int i = 0; i < max; i++) {
  764. arr[i] = performance->call("get_monitor", i);
  765. }
  766. packet_peer_stream->put_var("performance");
  767. packet_peer_stream->put_var(1);
  768. packet_peer_stream->put_var(arr);
  769. }
  770. }
  771. if (profiling) {
  772. if (skip_profile_frame) {
  773. skip_profile_frame = false;
  774. } else {
  775. //send profiling info normally
  776. _send_profiling_data(true);
  777. }
  778. }
  779. if (profiling_network) {
  780. uint64_t pt = OS::get_singleton()->get_ticks_msec();
  781. if (pt - last_net_bandwidth_time > 200) {
  782. last_net_bandwidth_time = pt;
  783. _send_network_bandwidth_usage();
  784. }
  785. if (pt - last_net_prof_time > 100) {
  786. last_net_prof_time = pt;
  787. _send_network_profiling_data();
  788. }
  789. }
  790. if (reload_all_scripts) {
  791. for (int i = 0; i < ScriptServer::get_language_count(); i++) {
  792. ScriptServer::get_language(i)->reload_all_scripts();
  793. }
  794. reload_all_scripts = false;
  795. }
  796. _poll_events();
  797. }
  798. void ScriptDebuggerRemote::_send_network_profiling_data() {
  799. ERR_FAIL_COND(multiplayer.is_null());
  800. int n_nodes = multiplayer->get_profiling_frame(&network_profile_info.write[0]);
  801. packet_peer_stream->put_var("network_profile");
  802. packet_peer_stream->put_var(n_nodes * 6);
  803. for (int i = 0; i < n_nodes; ++i) {
  804. packet_peer_stream->put_var(network_profile_info[i].node);
  805. packet_peer_stream->put_var(network_profile_info[i].node_path);
  806. packet_peer_stream->put_var(network_profile_info[i].incoming_rpc);
  807. packet_peer_stream->put_var(network_profile_info[i].incoming_rset);
  808. packet_peer_stream->put_var(network_profile_info[i].outgoing_rpc);
  809. packet_peer_stream->put_var(network_profile_info[i].outgoing_rset);
  810. }
  811. }
  812. void ScriptDebuggerRemote::_send_network_bandwidth_usage() {
  813. ERR_FAIL_COND(multiplayer.is_null());
  814. int incoming_bandwidth = multiplayer->get_incoming_bandwidth_usage();
  815. int outgoing_bandwidth = multiplayer->get_outgoing_bandwidth_usage();
  816. packet_peer_stream->put_var("network_bandwidth");
  817. packet_peer_stream->put_var(2);
  818. packet_peer_stream->put_var(incoming_bandwidth);
  819. packet_peer_stream->put_var(outgoing_bandwidth);
  820. }
  821. void ScriptDebuggerRemote::send_message(const String &p_message, const Array &p_args) {
  822. mutex.lock();
  823. if (!locking && tcp_client->is_connected_to_host()) {
  824. if (messages.size() >= max_messages_per_frame) {
  825. n_messages_dropped++;
  826. } else {
  827. Message msg;
  828. msg.message = p_message;
  829. msg.data = p_args;
  830. messages.push_back(msg);
  831. }
  832. }
  833. mutex.unlock();
  834. }
  835. void ScriptDebuggerRemote::send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type, const Vector<ScriptLanguage::StackInfo> &p_stack_info) {
  836. OutputError oe;
  837. oe.error = p_err;
  838. oe.error_descr = p_descr;
  839. oe.source_file = p_file;
  840. oe.source_line = p_line;
  841. oe.source_func = p_func;
  842. oe.warning = p_type == ERR_HANDLER_WARNING;
  843. uint64_t time = OS::get_singleton()->get_ticks_msec();
  844. oe.hr = time / 3600000;
  845. oe.min = (time / 60000) % 60;
  846. oe.sec = (time / 1000) % 60;
  847. oe.msec = time % 1000;
  848. Array cstack;
  849. uint64_t ticks = OS::get_singleton()->get_ticks_usec() / 1000;
  850. msec_count += ticks - last_msec;
  851. last_msec = ticks;
  852. if (msec_count > 1000) {
  853. msec_count = 0;
  854. err_count = 0;
  855. n_errors_dropped = 0;
  856. warn_count = 0;
  857. n_warnings_dropped = 0;
  858. }
  859. cstack.resize(p_stack_info.size() * 3);
  860. for (int i = 0; i < p_stack_info.size(); i++) {
  861. cstack[i * 3 + 0] = p_stack_info[i].file;
  862. cstack[i * 3 + 1] = p_stack_info[i].func;
  863. cstack[i * 3 + 2] = p_stack_info[i].line;
  864. }
  865. oe.callstack = cstack;
  866. if (oe.warning) {
  867. warn_count++;
  868. } else {
  869. err_count++;
  870. }
  871. mutex.lock();
  872. if (!locking && tcp_client->is_connected_to_host()) {
  873. if (oe.warning) {
  874. if (warn_count > max_warnings_per_second) {
  875. n_warnings_dropped++;
  876. } else {
  877. errors.push_back(oe);
  878. }
  879. } else {
  880. if (err_count > max_errors_per_second) {
  881. n_errors_dropped++;
  882. } else {
  883. errors.push_back(oe);
  884. }
  885. }
  886. }
  887. mutex.unlock();
  888. }
  889. void ScriptDebuggerRemote::_print_handler(void *p_this, const String &p_string, bool p_error) {
  890. ScriptDebuggerRemote *sdr = (ScriptDebuggerRemote *)p_this;
  891. uint64_t ticks = OS::get_singleton()->get_ticks_usec() / 1000;
  892. sdr->msec_count += ticks - sdr->last_msec;
  893. sdr->last_msec = ticks;
  894. if (sdr->msec_count > 1000) {
  895. sdr->char_count = 0;
  896. sdr->msec_count = 0;
  897. }
  898. String s = p_string;
  899. int allowed_chars = MIN(MAX(sdr->max_cps - sdr->char_count, 0), s.length());
  900. if (allowed_chars == 0 && s.length() > 0) {
  901. return;
  902. }
  903. if (allowed_chars < s.length()) {
  904. s = s.substr(0, allowed_chars);
  905. }
  906. sdr->char_count += allowed_chars;
  907. bool overflowed = sdr->char_count >= sdr->max_cps;
  908. sdr->mutex.lock();
  909. if (!sdr->locking && sdr->tcp_client->is_connected_to_host()) {
  910. if (overflowed) {
  911. s += "[...]";
  912. }
  913. OutputString output_string;
  914. output_string.message = s;
  915. output_string.type = p_error ? MESSAGE_TYPE_ERROR : MESSAGE_TYPE_LOG;
  916. sdr->output_strings.push_back(output_string);
  917. if (overflowed) {
  918. output_string.message = "[output overflow, print less text!]";
  919. output_string.type = MESSAGE_TYPE_ERROR;
  920. sdr->output_strings.push_back(output_string);
  921. }
  922. }
  923. sdr->mutex.unlock();
  924. }
  925. void ScriptDebuggerRemote::request_quit() {
  926. requested_quit = true;
  927. }
  928. void ScriptDebuggerRemote::set_multiplayer(Ref<MultiplayerAPI> p_multiplayer) {
  929. multiplayer = p_multiplayer;
  930. }
  931. bool ScriptDebuggerRemote::is_profiling() const {
  932. return profiling;
  933. }
  934. void ScriptDebuggerRemote::add_profiling_frame_data(const StringName &p_name, const Array &p_data) {
  935. int idx = -1;
  936. for (int i = 0; i < profile_frame_data.size(); i++) {
  937. if (profile_frame_data[i].name == p_name) {
  938. idx = i;
  939. break;
  940. }
  941. }
  942. FrameData fd;
  943. fd.name = p_name;
  944. fd.data = p_data;
  945. if (idx == -1) {
  946. profile_frame_data.push_back(fd);
  947. } else {
  948. profile_frame_data.write[idx] = fd;
  949. }
  950. }
  951. void ScriptDebuggerRemote::profiling_start() {
  952. //ignores this, uses it via connection
  953. }
  954. void ScriptDebuggerRemote::profiling_end() {
  955. //ignores this, uses it via connection
  956. }
  957. void ScriptDebuggerRemote::profiling_set_frame_times(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time) {
  958. frame_time = p_frame_time;
  959. idle_time = p_idle_time;
  960. physics_time = p_physics_time;
  961. physics_frame_time = p_physics_frame_time;
  962. }
  963. void ScriptDebuggerRemote::set_skip_breakpoints(bool p_skip_breakpoints) {
  964. skip_breakpoints = p_skip_breakpoints;
  965. }
  966. void ScriptDebuggerRemote::set_allow_focus_steal_pid(OS::ProcessID p_pid) {
  967. allow_focus_steal_pid = p_pid;
  968. }
  969. ScriptDebuggerRemote::ResourceUsageFunc ScriptDebuggerRemote::resource_usage_func = nullptr;
  970. ScriptDebuggerRemote::ScriptDebuggerRemote() :
  971. profiling(false),
  972. profiling_network(false),
  973. max_frame_functions(16),
  974. skip_profile_frame(false),
  975. reload_all_scripts(false),
  976. tcp_client(Ref<StreamPeerTCP>(memnew(StreamPeerTCP))),
  977. packet_peer_stream(Ref<PacketPeerStream>(memnew(PacketPeerStream))),
  978. last_perf_time(0),
  979. last_net_prof_time(0),
  980. last_net_bandwidth_time(0),
  981. performance(Engine::get_singleton()->get_singleton_object("Performance")),
  982. requested_quit(false),
  983. max_messages_per_frame(GLOBAL_GET("network/limits/debugger_stdout/max_messages_per_frame")),
  984. n_messages_dropped(0),
  985. max_errors_per_second(GLOBAL_GET("network/limits/debugger_stdout/max_errors_per_second")),
  986. max_warnings_per_second(GLOBAL_GET("network/limits/debugger_stdout/max_warnings_per_second")),
  987. n_errors_dropped(0),
  988. n_warnings_dropped(0),
  989. max_cps(GLOBAL_GET("network/limits/debugger_stdout/max_chars_per_second")),
  990. char_count(0),
  991. err_count(0),
  992. warn_count(0),
  993. last_msec(0),
  994. msec_count(0),
  995. allow_focus_steal_pid(0),
  996. locking(false),
  997. poll_every(0),
  998. scene_tree(nullptr) {
  999. packet_peer_stream->set_stream_peer(tcp_client);
  1000. packet_peer_stream->set_output_buffer_max_size((1024 * 1024 * 8) - 4); // 8 MiB should be way more than enough, minus 4 bytes for separator.
  1001. phl.printfunc = _print_handler;
  1002. phl.userdata = this;
  1003. add_print_handler(&phl);
  1004. eh.errfunc = _err_handler;
  1005. eh.userdata = this;
  1006. add_error_handler(&eh);
  1007. profile_info.resize(GLOBAL_GET("debug/settings/profiler/max_functions"));
  1008. network_profile_info.resize(GLOBAL_GET("debug/settings/profiler/max_functions"));
  1009. profile_info_ptrs.resize(profile_info.size());
  1010. }
  1011. ScriptDebuggerRemote::~ScriptDebuggerRemote() {
  1012. remove_print_handler(&phl);
  1013. remove_error_handler(&eh);
  1014. }