script_debugger_remote.cpp 37 KB

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