script_debugger_remote.cpp 37 KB

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