script_debugger_remote.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284
  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. if (var.get_type() == Variant::OBJECT && var.is_ref()) {
  520. REF r = var;
  521. if (r.is_valid()) {
  522. res = *r;
  523. } else {
  524. res = RES();
  525. }
  526. }
  527. Array prop;
  528. prop.push_back(pi.name);
  529. prop.push_back(pi.type);
  530. //only send information that can be sent..
  531. int len = 0; //test how big is this to encode
  532. encode_variant(var, NULL, len);
  533. if (len > packet_peer_stream->get_output_buffer_max_size()) { //limit to max size
  534. prop.push_back(PROPERTY_HINT_OBJECT_TOO_BIG);
  535. prop.push_back("");
  536. prop.push_back(pi.usage);
  537. prop.push_back(Variant());
  538. } else {
  539. prop.push_back(pi.hint);
  540. prop.push_back(pi.hint_string);
  541. prop.push_back(pi.usage);
  542. if (!res.is_null()) {
  543. var = res->get_path();
  544. }
  545. prop.push_back(var);
  546. }
  547. send_props.push_back(prop);
  548. }
  549. packet_peer_stream->put_var("message:inspect_object");
  550. packet_peer_stream->put_var(3);
  551. packet_peer_stream->put_var(p_id);
  552. packet_peer_stream->put_var(obj->get_class());
  553. packet_peer_stream->put_var(send_props);
  554. }
  555. void ScriptDebuggerRemote::_set_object_property(ObjectID p_id, const String &p_property, const Variant &p_value) {
  556. Object *obj = ObjectDB::get_instance(p_id);
  557. if (!obj)
  558. return;
  559. String prop_name = p_property;
  560. if (p_property.begins_with("Members/")) {
  561. Vector<String> ss = p_property.split("/");
  562. prop_name = ss[ss.size() - 1];
  563. }
  564. obj->set(prop_name, p_value);
  565. }
  566. void ScriptDebuggerRemote::_poll_events() {
  567. //this si called from ::idle_poll, happens only when running the game,
  568. //does not get called while on debug break
  569. while (packet_peer_stream->get_available_packet_count() > 0) {
  570. _get_output();
  571. //send over output_strings
  572. Variant var;
  573. Error err = packet_peer_stream->get_var(var);
  574. ERR_CONTINUE(err != OK);
  575. ERR_CONTINUE(var.get_type() != Variant::ARRAY);
  576. Array cmd = var;
  577. ERR_CONTINUE(cmd.size() == 0);
  578. ERR_CONTINUE(cmd[0].get_type() != Variant::STRING);
  579. String command = cmd[0];
  580. //cmd.remove(0);
  581. if (command == "break") {
  582. if (get_break_language())
  583. debug(get_break_language());
  584. } else if (command == "request_scene_tree") {
  585. #ifdef DEBUG_ENABLED
  586. if (scene_tree)
  587. scene_tree->_debugger_request_tree();
  588. #endif
  589. } else if (command == "request_video_mem") {
  590. _send_video_memory();
  591. } else if (command == "inspect_object") {
  592. ObjectID id = cmd[1];
  593. _send_object_id(id);
  594. } else if (command == "set_object_property") {
  595. _set_object_property(cmd[1], cmd[2], cmd[3]);
  596. } else if (command == "start_profiling") {
  597. for (int i = 0; i < ScriptServer::get_language_count(); i++) {
  598. ScriptServer::get_language(i)->profiling_start();
  599. }
  600. max_frame_functions = cmd[1];
  601. profiler_function_signature_map.clear();
  602. profiling = true;
  603. frame_time = 0;
  604. idle_time = 0;
  605. physics_time = 0;
  606. physics_frame_time = 0;
  607. print_line("PROFILING ALRIGHT!");
  608. } else if (command == "stop_profiling") {
  609. for (int i = 0; i < ScriptServer::get_language_count(); i++) {
  610. ScriptServer::get_language(i)->profiling_stop();
  611. }
  612. profiling = false;
  613. _send_profiling_data(false);
  614. print_line("PROFILING END!");
  615. } else if (command == "start_network_profiling") {
  616. multiplayer->profiling_start();
  617. profiling_network = true;
  618. } else if (command == "stop_network_profiling") {
  619. multiplayer->profiling_end();
  620. profiling_network = false;
  621. } else if (command == "override_camera_2D:set") {
  622. bool enforce = cmd[1];
  623. if (scene_tree) {
  624. scene_tree->get_root()->enable_canvas_transform_override(enforce);
  625. }
  626. } else if (command == "override_camera_2D:transform") {
  627. Transform2D transform = cmd[1];
  628. if (scene_tree) {
  629. scene_tree->get_root()->set_canvas_transform_override(transform);
  630. }
  631. } else if (command == "override_camera_3D:set") {
  632. bool enable = cmd[1];
  633. if (scene_tree) {
  634. scene_tree->get_root()->enable_camera_override(enable);
  635. }
  636. } else if (command == "override_camera_3D:transform") {
  637. Transform transform = cmd[1];
  638. bool is_perspective = cmd[2];
  639. float size_or_fov = cmd[3];
  640. float near = cmd[4];
  641. float far = cmd[5];
  642. if (scene_tree) {
  643. if (is_perspective) {
  644. scene_tree->get_root()->set_camera_override_perspective(size_or_fov, near, far);
  645. } else {
  646. scene_tree->get_root()->set_camera_override_orthogonal(size_or_fov, near, far);
  647. }
  648. scene_tree->get_root()->set_camera_override_transform(transform);
  649. }
  650. } else if (command == "reload_scripts") {
  651. reload_all_scripts = true;
  652. } else if (command == "breakpoint") {
  653. bool set = cmd[3];
  654. if (set)
  655. insert_breakpoint(cmd[2], cmd[1]);
  656. else
  657. remove_breakpoint(cmd[2], cmd[1]);
  658. } else if (command == "set_skip_breakpoints") {
  659. skip_breakpoints = cmd[1];
  660. } else {
  661. _parse_live_edit(cmd);
  662. }
  663. }
  664. }
  665. void ScriptDebuggerRemote::_send_profiling_data(bool p_for_frame) {
  666. int ofs = 0;
  667. for (int i = 0; i < ScriptServer::get_language_count(); i++) {
  668. if (p_for_frame)
  669. ofs += ScriptServer::get_language(i)->profiling_get_frame_data(&profile_info.write[ofs], profile_info.size() - ofs);
  670. else
  671. ofs += ScriptServer::get_language(i)->profiling_get_accumulated_data(&profile_info.write[ofs], profile_info.size() - ofs);
  672. }
  673. for (int i = 0; i < ofs; i++) {
  674. profile_info_ptrs.write[i] = &profile_info.write[i];
  675. }
  676. SortArray<ScriptLanguage::ProfilingInfo *, ProfileInfoSort> sa;
  677. sa.sort(profile_info_ptrs.ptrw(), ofs);
  678. int to_send = MIN(ofs, max_frame_functions);
  679. //check signatures first
  680. uint64_t total_script_time = 0;
  681. for (int i = 0; i < to_send; i++) {
  682. if (!profiler_function_signature_map.has(profile_info_ptrs[i]->signature)) {
  683. int idx = profiler_function_signature_map.size();
  684. packet_peer_stream->put_var("profile_sig");
  685. packet_peer_stream->put_var(2);
  686. packet_peer_stream->put_var(profile_info_ptrs[i]->signature);
  687. packet_peer_stream->put_var(idx);
  688. profiler_function_signature_map[profile_info_ptrs[i]->signature] = idx;
  689. }
  690. total_script_time += profile_info_ptrs[i]->self_time;
  691. }
  692. //send frames then
  693. if (p_for_frame) {
  694. packet_peer_stream->put_var("profile_frame");
  695. packet_peer_stream->put_var(8 + profile_frame_data.size() * 2 + to_send * 4);
  696. } else {
  697. packet_peer_stream->put_var("profile_total");
  698. packet_peer_stream->put_var(8 + to_send * 4);
  699. }
  700. packet_peer_stream->put_var(Engine::get_singleton()->get_idle_frames()); //total frame time
  701. packet_peer_stream->put_var(frame_time); //total frame time
  702. packet_peer_stream->put_var(idle_time); //idle frame time
  703. packet_peer_stream->put_var(physics_time); //fixed frame time
  704. packet_peer_stream->put_var(physics_frame_time); //fixed frame time
  705. packet_peer_stream->put_var(USEC_TO_SEC(total_script_time)); //total script execution time
  706. if (p_for_frame) {
  707. packet_peer_stream->put_var(profile_frame_data.size()); //how many profile framedatas to send
  708. packet_peer_stream->put_var(to_send); //how many script functions to send
  709. for (int i = 0; i < profile_frame_data.size(); i++) {
  710. packet_peer_stream->put_var(profile_frame_data[i].name);
  711. packet_peer_stream->put_var(profile_frame_data[i].data);
  712. }
  713. } else {
  714. packet_peer_stream->put_var(0); //how many script functions to send
  715. packet_peer_stream->put_var(to_send); //how many script functions to send
  716. }
  717. for (int i = 0; i < to_send; i++) {
  718. int sig_id = -1;
  719. if (profiler_function_signature_map.has(profile_info_ptrs[i]->signature)) {
  720. sig_id = profiler_function_signature_map[profile_info_ptrs[i]->signature];
  721. }
  722. packet_peer_stream->put_var(sig_id);
  723. packet_peer_stream->put_var(profile_info_ptrs[i]->call_count);
  724. packet_peer_stream->put_var(profile_info_ptrs[i]->total_time / 1000000.0);
  725. packet_peer_stream->put_var(profile_info_ptrs[i]->self_time / 1000000.0);
  726. }
  727. if (p_for_frame) {
  728. profile_frame_data.clear();
  729. }
  730. }
  731. void ScriptDebuggerRemote::idle_poll() {
  732. // this function is called every frame, except when there is a debugger break (::debug() in this class)
  733. // execution stops and remains in the ::debug function
  734. _get_output();
  735. if (requested_quit) {
  736. packet_peer_stream->put_var("kill_me");
  737. packet_peer_stream->put_var(0);
  738. requested_quit = false;
  739. }
  740. if (performance) {
  741. uint64_t pt = OS::get_singleton()->get_ticks_msec();
  742. if (pt - last_perf_time > 1000) {
  743. last_perf_time = pt;
  744. int max = performance->get("MONITOR_MAX");
  745. Array arr;
  746. arr.resize(max);
  747. for (int i = 0; i < max; i++) {
  748. arr[i] = performance->call("get_monitor", i);
  749. }
  750. packet_peer_stream->put_var("performance");
  751. packet_peer_stream->put_var(1);
  752. packet_peer_stream->put_var(arr);
  753. }
  754. }
  755. if (profiling) {
  756. if (skip_profile_frame) {
  757. skip_profile_frame = false;
  758. } else {
  759. //send profiling info normally
  760. _send_profiling_data(true);
  761. }
  762. }
  763. if (profiling_network) {
  764. uint64_t pt = OS::get_singleton()->get_ticks_msec();
  765. if (pt - last_net_bandwidth_time > 200) {
  766. last_net_bandwidth_time = pt;
  767. _send_network_bandwidth_usage();
  768. }
  769. if (pt - last_net_prof_time > 100) {
  770. last_net_prof_time = pt;
  771. _send_network_profiling_data();
  772. }
  773. }
  774. if (reload_all_scripts) {
  775. for (int i = 0; i < ScriptServer::get_language_count(); i++) {
  776. ScriptServer::get_language(i)->reload_all_scripts();
  777. }
  778. reload_all_scripts = false;
  779. }
  780. _poll_events();
  781. }
  782. void ScriptDebuggerRemote::_send_network_profiling_data() {
  783. ERR_FAIL_COND(multiplayer.is_null());
  784. int n_nodes = multiplayer->get_profiling_frame(&network_profile_info.write[0]);
  785. packet_peer_stream->put_var("network_profile");
  786. packet_peer_stream->put_var(n_nodes * 6);
  787. for (int i = 0; i < n_nodes; ++i) {
  788. packet_peer_stream->put_var(network_profile_info[i].node);
  789. packet_peer_stream->put_var(network_profile_info[i].node_path);
  790. packet_peer_stream->put_var(network_profile_info[i].incoming_rpc);
  791. packet_peer_stream->put_var(network_profile_info[i].incoming_rset);
  792. packet_peer_stream->put_var(network_profile_info[i].outgoing_rpc);
  793. packet_peer_stream->put_var(network_profile_info[i].outgoing_rset);
  794. }
  795. }
  796. void ScriptDebuggerRemote::_send_network_bandwidth_usage() {
  797. ERR_FAIL_COND(multiplayer.is_null());
  798. int incoming_bandwidth = multiplayer->get_incoming_bandwidth_usage();
  799. int outgoing_bandwidth = multiplayer->get_outgoing_bandwidth_usage();
  800. packet_peer_stream->put_var("network_bandwidth");
  801. packet_peer_stream->put_var(2);
  802. packet_peer_stream->put_var(incoming_bandwidth);
  803. packet_peer_stream->put_var(outgoing_bandwidth);
  804. }
  805. void ScriptDebuggerRemote::send_message(const String &p_message, const Array &p_args) {
  806. mutex->lock();
  807. if (!locking && tcp_client->is_connected_to_host()) {
  808. if (messages.size() >= max_messages_per_frame) {
  809. n_messages_dropped++;
  810. } else {
  811. Message msg;
  812. msg.message = p_message;
  813. msg.data = p_args;
  814. messages.push_back(msg);
  815. }
  816. }
  817. mutex->unlock();
  818. }
  819. 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) {
  820. OutputError oe;
  821. oe.error = p_err;
  822. oe.error_descr = p_descr;
  823. oe.source_file = p_file;
  824. oe.source_line = p_line;
  825. oe.source_func = p_func;
  826. oe.warning = p_type == ERR_HANDLER_WARNING;
  827. uint64_t time = OS::get_singleton()->get_ticks_msec();
  828. oe.hr = time / 3600000;
  829. oe.min = (time / 60000) % 60;
  830. oe.sec = (time / 1000) % 60;
  831. oe.msec = time % 1000;
  832. Array cstack;
  833. uint64_t ticks = OS::get_singleton()->get_ticks_usec() / 1000;
  834. msec_count += ticks - last_msec;
  835. last_msec = ticks;
  836. if (msec_count > 1000) {
  837. msec_count = 0;
  838. err_count = 0;
  839. n_errors_dropped = 0;
  840. warn_count = 0;
  841. n_warnings_dropped = 0;
  842. }
  843. cstack.resize(p_stack_info.size() * 3);
  844. for (int i = 0; i < p_stack_info.size(); i++) {
  845. cstack[i * 3 + 0] = p_stack_info[i].file;
  846. cstack[i * 3 + 1] = p_stack_info[i].func;
  847. cstack[i * 3 + 2] = p_stack_info[i].line;
  848. }
  849. oe.callstack = cstack;
  850. if (oe.warning) {
  851. warn_count++;
  852. } else {
  853. err_count++;
  854. }
  855. mutex->lock();
  856. if (!locking && tcp_client->is_connected_to_host()) {
  857. if (oe.warning) {
  858. if (warn_count > max_warnings_per_second) {
  859. n_warnings_dropped++;
  860. } else {
  861. errors.push_back(oe);
  862. }
  863. } else {
  864. if (err_count > max_errors_per_second) {
  865. n_errors_dropped++;
  866. } else {
  867. errors.push_back(oe);
  868. }
  869. }
  870. }
  871. mutex->unlock();
  872. }
  873. void ScriptDebuggerRemote::_print_handler(void *p_this, const String &p_string, bool p_error) {
  874. ScriptDebuggerRemote *sdr = (ScriptDebuggerRemote *)p_this;
  875. uint64_t ticks = OS::get_singleton()->get_ticks_usec() / 1000;
  876. sdr->msec_count += ticks - sdr->last_msec;
  877. sdr->last_msec = ticks;
  878. if (sdr->msec_count > 1000) {
  879. sdr->char_count = 0;
  880. sdr->msec_count = 0;
  881. }
  882. String s = p_string;
  883. int allowed_chars = MIN(MAX(sdr->max_cps - sdr->char_count, 0), s.length());
  884. if (allowed_chars == 0)
  885. return;
  886. if (allowed_chars < s.length()) {
  887. s = s.substr(0, allowed_chars);
  888. }
  889. sdr->char_count += allowed_chars;
  890. bool overflowed = sdr->char_count >= sdr->max_cps;
  891. sdr->mutex->lock();
  892. if (!sdr->locking && sdr->tcp_client->is_connected_to_host()) {
  893. if (overflowed)
  894. s += "[...]";
  895. sdr->output_strings.push_back(s);
  896. if (overflowed) {
  897. sdr->output_strings.push_back("[output overflow, print less text!]");
  898. }
  899. }
  900. sdr->mutex->unlock();
  901. }
  902. void ScriptDebuggerRemote::request_quit() {
  903. requested_quit = true;
  904. }
  905. void ScriptDebuggerRemote::set_multiplayer(Ref<MultiplayerAPI> p_multiplayer) {
  906. multiplayer = p_multiplayer;
  907. }
  908. bool ScriptDebuggerRemote::is_profiling() const {
  909. return profiling;
  910. }
  911. void ScriptDebuggerRemote::add_profiling_frame_data(const StringName &p_name, const Array &p_data) {
  912. int idx = -1;
  913. for (int i = 0; i < profile_frame_data.size(); i++) {
  914. if (profile_frame_data[i].name == p_name) {
  915. idx = i;
  916. break;
  917. }
  918. }
  919. FrameData fd;
  920. fd.name = p_name;
  921. fd.data = p_data;
  922. if (idx == -1) {
  923. profile_frame_data.push_back(fd);
  924. } else {
  925. profile_frame_data.write[idx] = fd;
  926. }
  927. }
  928. void ScriptDebuggerRemote::profiling_start() {
  929. //ignores this, uses it via connection
  930. }
  931. void ScriptDebuggerRemote::profiling_end() {
  932. //ignores this, uses it via connection
  933. }
  934. void ScriptDebuggerRemote::profiling_set_frame_times(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time) {
  935. frame_time = p_frame_time;
  936. idle_time = p_idle_time;
  937. physics_time = p_physics_time;
  938. physics_frame_time = p_physics_frame_time;
  939. }
  940. void ScriptDebuggerRemote::set_skip_breakpoints(bool p_skip_breakpoints) {
  941. skip_breakpoints = p_skip_breakpoints;
  942. }
  943. ScriptDebuggerRemote::ResourceUsageFunc ScriptDebuggerRemote::resource_usage_func = NULL;
  944. ScriptDebuggerRemote::ScriptDebuggerRemote() :
  945. profiling(false),
  946. profiling_network(false),
  947. max_frame_functions(16),
  948. skip_profile_frame(false),
  949. reload_all_scripts(false),
  950. tcp_client(Ref<StreamPeerTCP>(memnew(StreamPeerTCP))),
  951. packet_peer_stream(Ref<PacketPeerStream>(memnew(PacketPeerStream))),
  952. last_perf_time(0),
  953. last_net_prof_time(0),
  954. last_net_bandwidth_time(0),
  955. performance(Engine::get_singleton()->get_singleton_object("Performance")),
  956. requested_quit(false),
  957. mutex(Mutex::create()),
  958. max_messages_per_frame(GLOBAL_GET("network/limits/debugger_stdout/max_messages_per_frame")),
  959. n_messages_dropped(0),
  960. max_errors_per_second(GLOBAL_GET("network/limits/debugger_stdout/max_errors_per_second")),
  961. max_warnings_per_second(GLOBAL_GET("network/limits/debugger_stdout/max_warnings_per_second")),
  962. n_errors_dropped(0),
  963. max_cps(GLOBAL_GET("network/limits/debugger_stdout/max_chars_per_second")),
  964. char_count(0),
  965. err_count(0),
  966. warn_count(0),
  967. last_msec(0),
  968. msec_count(0),
  969. locking(false),
  970. poll_every(0),
  971. scene_tree(NULL) {
  972. packet_peer_stream->set_stream_peer(tcp_client);
  973. 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.
  974. phl.printfunc = _print_handler;
  975. phl.userdata = this;
  976. add_print_handler(&phl);
  977. eh.errfunc = _err_handler;
  978. eh.userdata = this;
  979. add_error_handler(&eh);
  980. profile_info.resize(GLOBAL_GET("debug/settings/profiler/max_functions"));
  981. network_profile_info.resize(GLOBAL_GET("debug/settings/profiler/max_functions"));
  982. profile_info_ptrs.resize(profile_info.size());
  983. }
  984. ScriptDebuggerRemote::~ScriptDebuggerRemote() {
  985. remove_print_handler(&phl);
  986. remove_error_handler(&eh);
  987. memdelete(mutex);
  988. }