script_debugger_remote.cpp 37 KB

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