2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* script_debugger_remote.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2020-01-01 11:16:22 +01:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "script_debugger_remote.h"
|
2017-01-16 08:04:19 +01:00
|
|
|
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/engine.h"
|
|
|
|
#include "core/io/ip.h"
|
|
|
|
#include "core/io/marshalls.h"
|
|
|
|
#include "core/os/input.h"
|
|
|
|
#include "core/os/os.h"
|
|
|
|
#include "core/project_settings.h"
|
2017-10-17 16:37:25 +02:00
|
|
|
#include "scene/main/node.h"
|
2019-04-06 22:55:01 +02:00
|
|
|
#include "scene/main/scene_tree.h"
|
|
|
|
#include "scene/main/viewport.h"
|
2018-02-21 16:07:49 +01:00
|
|
|
#include "scene/resources/packed_scene.h"
|
2019-04-06 22:55:01 +02:00
|
|
|
#include "servers/visual_server.h"
|
2017-10-17 16:37:25 +02:00
|
|
|
|
2015-10-21 14:50:44 +02:00
|
|
|
void ScriptDebuggerRemote::_send_video_memory() {
|
|
|
|
|
|
|
|
List<ResourceUsage> usage;
|
|
|
|
if (resource_usage_func)
|
|
|
|
resource_usage_func(&usage);
|
|
|
|
|
|
|
|
usage.sort();
|
|
|
|
|
|
|
|
packet_peer_stream->put_var("message:video_mem");
|
2017-03-05 16:44:50 +01:00
|
|
|
packet_peer_stream->put_var(usage.size() * 4);
|
2015-10-21 14:50:44 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<ResourceUsage>::Element *E = usage.front(); E; E = E->next()) {
|
2015-10-21 14:50:44 +02:00
|
|
|
|
|
|
|
packet_peer_stream->put_var(E->get().path);
|
|
|
|
packet_peer_stream->put_var(E->get().type);
|
|
|
|
packet_peer_stream->put_var(E->get().format);
|
|
|
|
packet_peer_stream->put_var(E->get().vram);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Error ScriptDebuggerRemote::connect_to_host(const String &p_host, uint16_t p_port) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
IP_Address ip;
|
|
|
|
if (p_host.is_valid_ip_address())
|
|
|
|
ip = p_host;
|
|
|
|
else
|
|
|
|
ip = IP::get_singleton()->resolve_hostname(p_host);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int port = p_port;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-12-21 21:27:48 +01:00
|
|
|
const int tries = 6;
|
|
|
|
int waits[tries] = { 1, 10, 100, 1000, 1000, 1000 };
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
tcp_client->connect_to_host(ip, port);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-12-21 21:27:48 +01:00
|
|
|
for (int i = 0; i < tries; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tcp_client->get_status() == StreamPeerTCP::STATUS_CONNECTED) {
|
2018-09-11 18:36:43 +02:00
|
|
|
print_verbose("Remote Debugger: Connected!");
|
2017-03-05 16:44:50 +01:00
|
|
|
break;
|
|
|
|
} else {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-12-21 21:27:48 +01:00
|
|
|
const int ms = waits[i];
|
|
|
|
OS::get_singleton()->delay_usec(ms * 1000);
|
2018-09-11 18:36:43 +02:00
|
|
|
print_verbose("Remote Debugger: Connection failed with status: '" + String::num(tcp_client->get_status()) + "', retrying in " + String::num(ms) + " msec.");
|
2017-03-05 16:44:50 +01:00
|
|
|
};
|
|
|
|
};
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tcp_client->get_status() != StreamPeerTCP::STATUS_CONNECTED) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-08-15 04:57:49 +02:00
|
|
|
ERR_PRINTS("Remote Debugger: Unable to connect. Status: " + String::num(tcp_client->get_status()) + ".");
|
2017-03-05 16:44:50 +01:00
|
|
|
return FAILED;
|
|
|
|
};
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
packet_peer_stream->set_stream_peer(tcp_client);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return OK;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
void ScriptDebuggerRemote::_put_variable(const String &p_name, const Variant &p_variable) {
|
|
|
|
|
|
|
|
packet_peer_stream->put_var(p_name);
|
2018-01-03 06:58:27 +01:00
|
|
|
|
|
|
|
Variant var = p_variable;
|
|
|
|
if (p_variable.get_type() == Variant::OBJECT && !ObjectDB::instance_validate(p_variable)) {
|
|
|
|
var = Variant();
|
|
|
|
}
|
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
int len = 0;
|
2018-11-22 02:10:27 +01:00
|
|
|
Error err = encode_variant(var, NULL, len, true);
|
2017-09-02 22:32:31 +02:00
|
|
|
if (err != OK)
|
2019-08-15 04:57:49 +02:00
|
|
|
ERR_PRINT("Failed to encode variant.");
|
2017-09-02 22:32:31 +02:00
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
if (len > packet_peer_stream->get_output_buffer_max_size()) { //limit to max size
|
|
|
|
packet_peer_stream->put_var(Variant());
|
|
|
|
} else {
|
2018-01-03 06:58:27 +01:00
|
|
|
packet_peer_stream->put_var(var);
|
2017-08-18 15:59:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-21 16:07:49 +01:00
|
|
|
void ScriptDebuggerRemote::_save_node(ObjectID id, const String &p_path) {
|
|
|
|
|
|
|
|
Node *node = Object::cast_to<Node>(ObjectDB::get_instance(id));
|
|
|
|
ERR_FAIL_COND(!node);
|
|
|
|
|
|
|
|
Ref<PackedScene> ps = memnew(PackedScene);
|
|
|
|
ps->pack(node);
|
|
|
|
ResourceSaver::save(p_path, ps);
|
|
|
|
}
|
|
|
|
|
2019-07-29 20:09:22 +02:00
|
|
|
void ScriptDebuggerRemote::debug(ScriptLanguage *p_script, bool p_can_continue, bool p_is_error_breakpoint) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-05-22 02:18:16 +02:00
|
|
|
//this function is called when there is a debugger break (bug on script)
|
|
|
|
//or when execution is paused from editor
|
|
|
|
|
2019-07-29 20:09:22 +02:00
|
|
|
if (skip_breakpoints && !p_is_error_breakpoint)
|
|
|
|
return;
|
|
|
|
|
2019-08-15 04:57:49 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tcp_client->is_connected_to_host(), "Script Debugger failed to connect, but being used anyway.");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
packet_peer_stream->put_var("debug_enter");
|
|
|
|
packet_peer_stream->put_var(2);
|
|
|
|
packet_peer_stream->put_var(p_can_continue);
|
|
|
|
packet_peer_stream->put_var(p_script->debug_get_error());
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
skip_profile_frame = true; // to avoid super long frame time for the frame
|
2016-05-22 02:18:16 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Input::MouseMode mouse_mode = Input::get_singleton()->get_mouse_mode();
|
|
|
|
if (mouse_mode != Input::MOUSE_MODE_VISIBLE)
|
2016-01-02 16:58:59 +01:00
|
|
|
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
|
|
|
|
|
2019-04-06 22:55:01 +02:00
|
|
|
uint64_t loop_begin_usec = 0;
|
|
|
|
uint64_t loop_time_sec = 0;
|
2017-03-05 16:44:50 +01:00
|
|
|
while (true) {
|
2019-04-06 22:55:01 +02:00
|
|
|
loop_begin_usec = OS::get_singleton()->get_ticks_usec();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
_get_output();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (packet_peer_stream->get_available_packet_count() > 0) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Variant var;
|
|
|
|
Error err = packet_peer_stream->get_var(var);
|
2019-07-29 20:09:22 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_CONTINUE(err != OK);
|
|
|
|
ERR_CONTINUE(var.get_type() != Variant::ARRAY);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Array cmd = var;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_CONTINUE(cmd.size() == 0);
|
|
|
|
ERR_CONTINUE(cmd[0].get_type() != Variant::STRING);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
String command = cmd[0];
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (command == "get_stack_dump") {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
packet_peer_stream->put_var("stack_dump");
|
|
|
|
int slc = p_script->debug_get_stack_level_count();
|
2017-03-05 16:44:50 +01:00
|
|
|
packet_peer_stream->put_var(slc);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < slc; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Dictionary d;
|
2017-03-05 16:44:50 +01:00
|
|
|
d["file"] = p_script->debug_get_stack_level_source(i);
|
|
|
|
d["line"] = p_script->debug_get_stack_level_line(i);
|
|
|
|
d["function"] = p_script->debug_get_stack_level_function(i);
|
2014-02-10 02:10:30 +01:00
|
|
|
//d["id"]=p_script->debug_get_stack_level_
|
2017-03-05 16:44:50 +01:00
|
|
|
d["id"] = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
packet_peer_stream->put_var(d);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (command == "get_stack_frame_vars") {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-08-02 17:29:37 +02:00
|
|
|
cmd.remove(0);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_CONTINUE(cmd.size() != 1);
|
2014-02-10 02:10:30 +01:00
|
|
|
int lv = cmd[0];
|
|
|
|
|
|
|
|
List<String> members;
|
|
|
|
List<Variant> member_vals;
|
2017-10-17 16:37:25 +02:00
|
|
|
if (ScriptInstance *inst = p_script->debug_get_stack_level_instance(lv)) {
|
|
|
|
members.push_back("self");
|
|
|
|
member_vals.push_back(inst->get_owner());
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
p_script->debug_get_stack_level_members(lv, &members, &member_vals);
|
|
|
|
ERR_CONTINUE(members.size() != member_vals.size());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
List<String> locals;
|
|
|
|
List<Variant> local_vals;
|
2017-03-05 16:44:50 +01:00
|
|
|
p_script->debug_get_stack_level_locals(lv, &locals, &local_vals);
|
|
|
|
ERR_CONTINUE(locals.size() != local_vals.size());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-10-17 16:37:25 +02:00
|
|
|
List<String> globals;
|
|
|
|
List<Variant> globals_vals;
|
|
|
|
p_script->debug_get_globals(&globals, &globals_vals);
|
|
|
|
ERR_CONTINUE(globals.size() != globals_vals.size());
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
packet_peer_stream->put_var("stack_frame_vars");
|
2017-10-17 16:37:25 +02:00
|
|
|
packet_peer_stream->put_var(3 + (locals.size() + members.size() + globals.size()) * 2);
|
|
|
|
|
|
|
|
{ //locals
|
|
|
|
packet_peer_stream->put_var(locals.size());
|
|
|
|
|
|
|
|
List<String>::Element *E = locals.front();
|
|
|
|
List<Variant>::Element *F = local_vals.front();
|
|
|
|
|
|
|
|
while (E) {
|
|
|
|
_put_variable(E->get(), F->get());
|
|
|
|
|
|
|
|
E = E->next();
|
|
|
|
F = F->next();
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
{ //members
|
|
|
|
packet_peer_stream->put_var(members.size());
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
List<String>::Element *E = members.front();
|
|
|
|
List<Variant>::Element *F = member_vals.front();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (E) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
_put_variable(E->get(), F->get());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
E = E->next();
|
|
|
|
F = F->next();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-17 16:37:25 +02:00
|
|
|
{ //globals
|
|
|
|
packet_peer_stream->put_var(globals.size());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-10-17 16:37:25 +02:00
|
|
|
List<String>::Element *E = globals.front();
|
|
|
|
List<Variant>::Element *F = globals_vals.front();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (E) {
|
2017-08-18 15:59:31 +02:00
|
|
|
_put_variable(E->get(), F->get());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
E = E->next();
|
|
|
|
F = F->next();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (command == "step") {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
set_depth(-1);
|
|
|
|
set_lines_left(1);
|
|
|
|
break;
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (command == "next") {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
set_depth(0);
|
|
|
|
set_lines_left(1);
|
|
|
|
break;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (command == "continue") {
|
2014-02-10 02:10:30 +01:00
|
|
|
set_depth(-1);
|
|
|
|
set_lines_left(-1);
|
2016-09-14 04:02:18 +02:00
|
|
|
OS::get_singleton()->move_window_to_foreground();
|
2014-02-10 02:10:30 +01:00
|
|
|
break;
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (command == "break") {
|
2014-02-10 02:10:30 +01:00
|
|
|
ERR_PRINT("Got break when already broke!");
|
|
|
|
break;
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (command == "request_scene_tree") {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-04-06 22:55:01 +02:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
if (scene_tree)
|
|
|
|
scene_tree->_debugger_request_tree();
|
|
|
|
#endif
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (command == "request_video_mem") {
|
2015-10-21 14:50:44 +02:00
|
|
|
|
|
|
|
_send_video_memory();
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (command == "inspect_object") {
|
2016-05-23 00:28:37 +02:00
|
|
|
|
|
|
|
ObjectID id = cmd[1];
|
|
|
|
_send_object_id(id);
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (command == "set_object_property") {
|
2016-05-23 00:28:37 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_set_object_property(cmd[1], cmd[2], cmd[3]);
|
2016-05-23 00:28:37 +02:00
|
|
|
|
2019-04-06 22:55:01 +02:00
|
|
|
} else if (command == "override_camera_2D:set") {
|
|
|
|
bool enforce = cmd[1];
|
|
|
|
|
|
|
|
if (scene_tree) {
|
|
|
|
scene_tree->get_root()->enable_canvas_transform_override(enforce);
|
|
|
|
}
|
|
|
|
} else if (command == "override_camera_2D:transform") {
|
|
|
|
Transform2D transform = cmd[1];
|
|
|
|
|
|
|
|
if (scene_tree) {
|
|
|
|
scene_tree->get_root()->set_canvas_transform_override(transform);
|
|
|
|
}
|
|
|
|
} else if (command == "override_camera_3D:set") {
|
|
|
|
bool enable = cmd[1];
|
|
|
|
|
|
|
|
if (scene_tree) {
|
|
|
|
scene_tree->get_root()->enable_camera_override(enable);
|
|
|
|
}
|
|
|
|
} else if (command == "override_camera_3D:transform") {
|
|
|
|
Transform transform = cmd[1];
|
|
|
|
bool is_perspective = cmd[2];
|
|
|
|
float size_or_fov = cmd[3];
|
|
|
|
float near = cmd[4];
|
|
|
|
float far = cmd[5];
|
|
|
|
|
|
|
|
if (scene_tree) {
|
|
|
|
if (is_perspective) {
|
|
|
|
scene_tree->get_root()->set_camera_override_perspective(size_or_fov, near, far);
|
|
|
|
} else {
|
|
|
|
scene_tree->get_root()->set_camera_override_orthogonal(size_or_fov, near, far);
|
|
|
|
}
|
|
|
|
scene_tree->get_root()->set_camera_override_transform(transform);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (command == "reload_scripts") {
|
|
|
|
reload_all_scripts = true;
|
|
|
|
} else if (command == "breakpoint") {
|
2015-08-05 01:17:13 +02:00
|
|
|
|
|
|
|
bool set = cmd[3];
|
|
|
|
if (set)
|
2017-03-05 16:44:50 +01:00
|
|
|
insert_breakpoint(cmd[2], cmd[1]);
|
2015-08-05 01:17:13 +02:00
|
|
|
else
|
2017-03-05 16:44:50 +01:00
|
|
|
remove_breakpoint(cmd[2], cmd[1]);
|
2015-08-05 01:17:13 +02:00
|
|
|
|
2018-02-21 16:07:49 +01:00
|
|
|
} else if (command == "save_node") {
|
|
|
|
_save_node(cmd[1], cmd[2]);
|
2019-07-29 20:09:22 +02:00
|
|
|
} else if (command == "set_skip_breakpoints") {
|
|
|
|
skip_breakpoints = cmd[1];
|
2015-08-02 17:29:37 +02:00
|
|
|
} else {
|
|
|
|
_parse_live_edit(cmd);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
OS::get_singleton()->delay_usec(10000);
|
2019-03-03 21:12:19 +01:00
|
|
|
OS::get_singleton()->process_and_drop_events();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2019-04-06 22:55:01 +02:00
|
|
|
|
|
|
|
// This is for the camera override to stay live even when the game is paused from the editor
|
|
|
|
loop_time_sec = (OS::get_singleton()->get_ticks_usec() - loop_begin_usec) / 1000000.0f;
|
|
|
|
VisualServer::get_singleton()->sync();
|
|
|
|
if (VisualServer::get_singleton()->has_changed()) {
|
|
|
|
VisualServer::get_singleton()->draw(true, loop_time_sec * Engine::get_singleton()->get_time_scale());
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
packet_peer_stream->put_var("debug_exit");
|
|
|
|
packet_peer_stream->put_var(0);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (mouse_mode != Input::MOUSE_MODE_VISIBLE)
|
2016-01-02 16:58:59 +01:00
|
|
|
Input::get_singleton()->set_mouse_mode(mouse_mode);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScriptDebuggerRemote::_get_output() {
|
|
|
|
|
|
|
|
mutex->lock();
|
|
|
|
if (output_strings.size()) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
locking = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
packet_peer_stream->put_var("output");
|
2017-03-05 16:44:50 +01:00
|
|
|
packet_peer_stream->put_var(output_strings.size());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (output_strings.size()) {
|
2019-11-29 15:06:42 +01:00
|
|
|
const OutputString &output_string = output_strings.front()->get();
|
|
|
|
|
|
|
|
Array msg_data;
|
|
|
|
msg_data.push_back(output_string.message);
|
|
|
|
msg_data.push_back(output_string.type);
|
|
|
|
|
|
|
|
packet_peer_stream->put_var(msg_data);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
output_strings.pop_front();
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
locking = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2018-01-03 17:04:10 +01:00
|
|
|
if (n_messages_dropped > 0) {
|
|
|
|
Message msg;
|
|
|
|
msg.message = "Too many messages! " + String::num_int64(n_messages_dropped) + " messages were dropped.";
|
|
|
|
messages.push_back(msg);
|
|
|
|
n_messages_dropped = 0;
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
while (messages.size()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
locking = true;
|
|
|
|
packet_peer_stream->put_var("message:" + messages.front()->get().message);
|
2014-02-10 02:10:30 +01:00
|
|
|
packet_peer_stream->put_var(messages.front()->get().data.size());
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < messages.front()->get().data.size(); i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
packet_peer_stream->put_var(messages.front()->get().data[i]);
|
|
|
|
}
|
|
|
|
messages.pop_front();
|
2017-03-05 16:44:50 +01:00
|
|
|
locking = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2015-08-04 14:47:32 +02:00
|
|
|
|
2019-07-31 17:24:53 +02:00
|
|
|
if (n_errors_dropped == 1) {
|
|
|
|
// Only print one message about dropping per second
|
2018-01-03 17:04:10 +01:00
|
|
|
OutputError oe;
|
|
|
|
oe.error = "TOO_MANY_ERRORS";
|
2019-07-31 17:24:53 +02:00
|
|
|
oe.error_descr = "Too many errors! Ignoring errors for up to 1 second.";
|
2018-01-03 17:04:10 +01:00
|
|
|
oe.warning = false;
|
|
|
|
uint64_t time = OS::get_singleton()->get_ticks_msec();
|
|
|
|
oe.hr = time / 3600000;
|
|
|
|
oe.min = (time / 60000) % 60;
|
|
|
|
oe.sec = (time / 1000) % 60;
|
|
|
|
oe.msec = time % 1000;
|
|
|
|
errors.push_back(oe);
|
2019-07-31 17:24:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (n_warnings_dropped == 1) {
|
|
|
|
// Only print one message about dropping per second
|
|
|
|
OutputError oe;
|
|
|
|
oe.error = "TOO_MANY_WARNINGS";
|
|
|
|
oe.error_descr = "Too many warnings! Ignoring warnings for up to 1 second.";
|
|
|
|
oe.warning = true;
|
|
|
|
uint64_t time = OS::get_singleton()->get_ticks_msec();
|
|
|
|
oe.hr = time / 3600000;
|
|
|
|
oe.min = (time / 60000) % 60;
|
|
|
|
oe.sec = (time / 1000) % 60;
|
|
|
|
oe.msec = time % 1000;
|
|
|
|
errors.push_back(oe);
|
2018-01-03 17:04:10 +01:00
|
|
|
}
|
|
|
|
|
2015-08-04 14:47:32 +02:00
|
|
|
while (errors.size()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
locking = true;
|
2015-08-04 14:47:32 +02:00
|
|
|
packet_peer_stream->put_var("error");
|
|
|
|
OutputError oe = errors.front()->get();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
packet_peer_stream->put_var(oe.callstack.size() + 2);
|
2015-08-04 14:47:32 +02:00
|
|
|
|
|
|
|
Array error_data;
|
|
|
|
|
|
|
|
error_data.push_back(oe.hr);
|
|
|
|
error_data.push_back(oe.min);
|
|
|
|
error_data.push_back(oe.sec);
|
|
|
|
error_data.push_back(oe.msec);
|
|
|
|
error_data.push_back(oe.source_func);
|
|
|
|
error_data.push_back(oe.source_file);
|
|
|
|
error_data.push_back(oe.source_line);
|
|
|
|
error_data.push_back(oe.error);
|
|
|
|
error_data.push_back(oe.error_descr);
|
|
|
|
error_data.push_back(oe.warning);
|
|
|
|
packet_peer_stream->put_var(error_data);
|
|
|
|
packet_peer_stream->put_var(oe.callstack.size());
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < oe.callstack.size(); i++) {
|
2015-08-04 14:47:32 +02:00
|
|
|
packet_peer_stream->put_var(oe.callstack[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
errors.pop_front();
|
2017-03-05 16:44:50 +01:00
|
|
|
locking = false;
|
2015-08-04 14:47:32 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
mutex->unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScriptDebuggerRemote::line_poll() {
|
|
|
|
|
|
|
|
//the purpose of this is just processing events every now and then when the script might get too busy
|
2017-03-24 21:45:31 +01:00
|
|
|
//otherwise bugs like infinite loops can't be caught
|
2017-03-05 16:44:50 +01:00
|
|
|
if (poll_every % 2048 == 0)
|
2014-02-10 02:10:30 +01:00
|
|
|
_poll_events();
|
|
|
|
poll_every++;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
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) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_type == ERR_HANDLER_SCRIPT)
|
2015-08-04 14:47:32 +02:00
|
|
|
return; //ignore script errors, those go through debugger
|
|
|
|
|
|
|
|
Vector<ScriptLanguage::StackInfo> si;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
|
|
|
|
si = ScriptServer::get_language(i)->debug_get_current_stack_info();
|
2015-08-04 14:47:32 +02:00
|
|
|
if (si.size())
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-01-09 17:19:03 +01:00
|
|
|
ScriptDebuggerRemote *sdr = (ScriptDebuggerRemote *)ud;
|
|
|
|
sdr->send_error(p_func, p_file, p_line, p_err, p_descr, p_type, si);
|
2015-08-04 14:47:32 +02:00
|
|
|
}
|
|
|
|
|
2017-08-11 21:10:05 +02:00
|
|
|
bool ScriptDebuggerRemote::_parse_live_edit(const Array &p_command) {
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2019-04-06 22:55:01 +02:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
|
2017-08-11 21:10:05 +02:00
|
|
|
String cmdstr = p_command[0];
|
2019-04-06 22:55:01 +02:00
|
|
|
if (!scene_tree || !cmdstr.begins_with("live_"))
|
2015-08-02 17:29:37 +02:00
|
|
|
return false;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cmdstr == "live_set_root") {
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2019-04-06 22:55:01 +02:00
|
|
|
scene_tree->_live_edit_root_func(p_command[1], p_command[2]);
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (cmdstr == "live_node_path") {
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2019-04-06 22:55:01 +02:00
|
|
|
scene_tree->_live_edit_node_path_func(p_command[1], p_command[2]);
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (cmdstr == "live_res_path") {
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2019-04-06 22:55:01 +02:00
|
|
|
scene_tree->_live_edit_res_path_func(p_command[1], p_command[2]);
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (cmdstr == "live_node_prop_res") {
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2019-04-06 22:55:01 +02:00
|
|
|
scene_tree->_live_edit_node_set_res_func(p_command[1], p_command[2], p_command[3]);
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (cmdstr == "live_node_prop") {
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2019-04-06 22:55:01 +02:00
|
|
|
scene_tree->_live_edit_node_set_func(p_command[1], p_command[2], p_command[3]);
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (cmdstr == "live_res_prop_res") {
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2019-04-06 22:55:01 +02:00
|
|
|
scene_tree->_live_edit_res_set_res_func(p_command[1], p_command[2], p_command[3]);
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (cmdstr == "live_res_prop") {
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2019-04-06 22:55:01 +02:00
|
|
|
scene_tree->_live_edit_res_set_func(p_command[1], p_command[2], p_command[3]);
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (cmdstr == "live_node_call") {
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2019-04-06 22:55:01 +02:00
|
|
|
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]);
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (cmdstr == "live_res_call") {
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2019-04-06 22:55:01 +02:00
|
|
|
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]);
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (cmdstr == "live_create_node") {
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2019-04-06 22:55:01 +02:00
|
|
|
scene_tree->_live_edit_create_node_func(p_command[1], p_command[2], p_command[3]);
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (cmdstr == "live_instance_node") {
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2019-04-06 22:55:01 +02:00
|
|
|
scene_tree->_live_edit_instance_node_func(p_command[1], p_command[2], p_command[3]);
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (cmdstr == "live_remove_node") {
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2019-04-06 22:55:01 +02:00
|
|
|
scene_tree->_live_edit_remove_node_func(p_command[1]);
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (cmdstr == "live_remove_and_keep_node") {
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2019-04-06 22:55:01 +02:00
|
|
|
scene_tree->_live_edit_remove_and_keep_node_func(p_command[1], p_command[2]);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (cmdstr == "live_restore_node") {
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2019-04-06 22:55:01 +02:00
|
|
|
scene_tree->_live_edit_restore_node_func(p_command[1], p_command[2], p_command[3]);
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (cmdstr == "live_duplicate_node") {
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2019-04-06 22:55:01 +02:00
|
|
|
scene_tree->_live_edit_duplicate_node_func(p_command[1], p_command[2]);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (cmdstr == "live_reparent_node") {
|
2015-08-02 17:29:37 +02:00
|
|
|
|
2019-04-06 22:55:01 +02:00
|
|
|
scene_tree->_live_edit_reparent_node_func(p_command[1], p_command[2], p_command[3], p_command[4]);
|
2015-08-02 17:29:37 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2019-04-06 22:55:01 +02:00
|
|
|
#else
|
|
|
|
|
|
|
|
return false;
|
|
|
|
#endif
|
2015-08-02 17:29:37 +02:00
|
|
|
}
|
|
|
|
|
2016-05-23 00:28:37 +02:00
|
|
|
void ScriptDebuggerRemote::_send_object_id(ObjectID p_id) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Object *obj = ObjectDB::get_instance(p_id);
|
2016-05-23 00:28:37 +02:00
|
|
|
if (!obj)
|
|
|
|
return;
|
|
|
|
|
2017-10-17 16:37:25 +02:00
|
|
|
typedef Pair<PropertyInfo, Variant> PropertyDesc;
|
|
|
|
List<PropertyDesc> properties;
|
2016-05-23 00:28:37 +02:00
|
|
|
|
2017-10-17 16:37:25 +02:00
|
|
|
if (ScriptInstance *si = obj->get_script_instance()) {
|
|
|
|
if (!si->get_script().is_null()) {
|
2016-05-23 00:28:37 +02:00
|
|
|
|
2018-04-25 07:23:05 +02:00
|
|
|
typedef Map<const Script *, Set<StringName> > ScriptMemberMap;
|
|
|
|
typedef Map<const Script *, Map<StringName, Variant> > ScriptConstantsMap;
|
|
|
|
|
|
|
|
ScriptMemberMap members;
|
|
|
|
members[si->get_script().ptr()] = Set<StringName>();
|
|
|
|
si->get_script()->get_members(&(members[si->get_script().ptr()]));
|
|
|
|
|
|
|
|
ScriptConstantsMap constants;
|
|
|
|
constants[si->get_script().ptr()] = Map<StringName, Variant>();
|
|
|
|
si->get_script()->get_constants(&(constants[si->get_script().ptr()]));
|
|
|
|
|
|
|
|
Ref<Script> base = si->get_script()->get_base_script();
|
|
|
|
while (base.is_valid()) {
|
|
|
|
|
|
|
|
members[base.ptr()] = Set<StringName>();
|
|
|
|
base->get_members(&(members[base.ptr()]));
|
|
|
|
|
|
|
|
constants[base.ptr()] = Map<StringName, Variant>();
|
|
|
|
base->get_constants(&(constants[base.ptr()]));
|
|
|
|
|
|
|
|
base = base->get_base_script();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (ScriptMemberMap::Element *sm = members.front(); sm; sm = sm->next()) {
|
|
|
|
for (Set<StringName>::Element *E = sm->get().front(); E; E = E->next()) {
|
|
|
|
Variant m;
|
|
|
|
if (si->get(E->get(), m)) {
|
|
|
|
String script_path = sm->key() == si->get_script().ptr() ? "" : sm->key()->get_path().get_file() + "/";
|
|
|
|
PropertyInfo pi(m.get_type(), "Members/" + script_path + E->get());
|
|
|
|
properties.push_back(PropertyDesc(pi, m));
|
|
|
|
}
|
2017-10-17 16:37:25 +02:00
|
|
|
}
|
|
|
|
}
|
2016-05-23 00:28:37 +02:00
|
|
|
|
2018-04-25 07:23:05 +02:00
|
|
|
for (ScriptConstantsMap::Element *sc = constants.front(); sc; sc = sc->next()) {
|
|
|
|
for (Map<StringName, Variant>::Element *E = sc->get().front(); E; E = E->next()) {
|
|
|
|
String script_path = sc->key() == si->get_script().ptr() ? "" : sc->key()->get_path().get_file() + "/";
|
2018-10-04 01:59:24 +02:00
|
|
|
if (E->value().get_type() == Variant::OBJECT) {
|
|
|
|
Variant id = ((Object *)E->value())->get_instance_id();
|
|
|
|
PropertyInfo pi(id.get_type(), "Constants/" + E->key(), PROPERTY_HINT_OBJECT_ID, "Object");
|
|
|
|
properties.push_back(PropertyDesc(pi, id));
|
|
|
|
} else {
|
|
|
|
PropertyInfo pi(E->value().get_type(), "Constants/" + script_path + E->key());
|
|
|
|
properties.push_back(PropertyDesc(pi, E->value()));
|
|
|
|
}
|
2018-04-25 07:23:05 +02:00
|
|
|
}
|
2017-10-17 16:37:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-11 14:13:33 +02:00
|
|
|
|
2017-10-17 16:37:25 +02:00
|
|
|
if (Node *node = Object::cast_to<Node>(obj)) {
|
2019-08-11 14:13:33 +02:00
|
|
|
// in some cases node will not be in tree here
|
|
|
|
// for instance where it created as variable and not yet added to tree
|
|
|
|
// in such cases we can't ask for it's path
|
|
|
|
if (node->is_inside_tree()) {
|
|
|
|
PropertyInfo pi(Variant::NODE_PATH, String("Node/path"));
|
|
|
|
properties.push_front(PropertyDesc(pi, node->get_path()));
|
|
|
|
} else {
|
|
|
|
PropertyInfo pi(Variant::STRING, String("Node/path"));
|
|
|
|
properties.push_front(PropertyDesc(pi, "[Orphan]"));
|
|
|
|
}
|
|
|
|
|
2017-10-17 16:37:25 +02:00
|
|
|
} else if (Resource *res = Object::cast_to<Resource>(obj)) {
|
|
|
|
if (Script *s = Object::cast_to<Script>(res)) {
|
|
|
|
Map<StringName, Variant> constants;
|
|
|
|
s->get_constants(&constants);
|
|
|
|
for (Map<StringName, Variant>::Element *E = constants.front(); E; E = E->next()) {
|
2018-10-04 01:59:24 +02:00
|
|
|
if (E->value().get_type() == Variant::OBJECT) {
|
|
|
|
Variant id = ((Object *)E->value())->get_instance_id();
|
|
|
|
PropertyInfo pi(id.get_type(), "Constants/" + E->key(), PROPERTY_HINT_OBJECT_ID, "Object");
|
|
|
|
properties.push_front(PropertyDesc(pi, E->value()));
|
|
|
|
} else {
|
|
|
|
PropertyInfo pi(E->value().get_type(), String("Constants/") + E->key());
|
|
|
|
properties.push_front(PropertyDesc(pi, E->value()));
|
|
|
|
}
|
2017-10-17 16:37:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-23 00:28:37 +02:00
|
|
|
|
|
|
|
List<PropertyInfo> pinfo;
|
2017-03-05 16:44:50 +01:00
|
|
|
obj->get_property_list(&pinfo, true);
|
|
|
|
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
|
|
|
|
if (E->get().usage & (PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CATEGORY)) {
|
2017-10-17 16:37:25 +02:00
|
|
|
properties.push_back(PropertyDesc(E->get(), obj->get(E->get().name)));
|
2016-05-23 00:28:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-17 16:37:25 +02:00
|
|
|
Array send_props;
|
|
|
|
for (int i = 0; i < properties.size(); i++) {
|
|
|
|
const PropertyInfo &pi = properties[i].first;
|
2018-01-23 06:01:12 +01:00
|
|
|
Variant &var = properties[i].second;
|
|
|
|
|
2017-10-17 16:37:25 +02:00
|
|
|
RES res = var;
|
|
|
|
|
|
|
|
Array prop;
|
|
|
|
prop.push_back(pi.name);
|
|
|
|
prop.push_back(pi.type);
|
2017-11-16 10:18:36 +01:00
|
|
|
|
|
|
|
//only send information that can be sent..
|
|
|
|
int len = 0; //test how big is this to encode
|
|
|
|
encode_variant(var, NULL, len);
|
|
|
|
if (len > packet_peer_stream->get_output_buffer_max_size()) { //limit to max size
|
|
|
|
prop.push_back(PROPERTY_HINT_OBJECT_TOO_BIG);
|
|
|
|
prop.push_back("");
|
|
|
|
prop.push_back(pi.usage);
|
|
|
|
prop.push_back(Variant());
|
|
|
|
} else {
|
|
|
|
prop.push_back(pi.hint);
|
2018-09-18 02:05:50 +02:00
|
|
|
prop.push_back(pi.hint_string);
|
2017-11-16 10:18:36 +01:00
|
|
|
prop.push_back(pi.usage);
|
2018-10-04 01:59:24 +02:00
|
|
|
|
2018-09-18 02:05:50 +02:00
|
|
|
if (!res.is_null()) {
|
2018-10-04 01:59:24 +02:00
|
|
|
var = res->get_path();
|
2018-09-18 02:05:50 +02:00
|
|
|
}
|
|
|
|
|
2017-11-16 10:18:36 +01:00
|
|
|
prop.push_back(var);
|
2016-05-23 00:28:37 +02:00
|
|
|
}
|
2017-10-17 16:37:25 +02:00
|
|
|
send_props.push_back(prop);
|
2016-05-23 00:28:37 +02:00
|
|
|
}
|
2017-10-17 16:37:25 +02:00
|
|
|
|
2016-05-23 00:28:37 +02:00
|
|
|
packet_peer_stream->put_var("message:inspect_object");
|
2017-10-17 16:37:25 +02:00
|
|
|
packet_peer_stream->put_var(3);
|
2016-05-23 00:28:37 +02:00
|
|
|
packet_peer_stream->put_var(p_id);
|
2017-01-03 03:03:46 +01:00
|
|
|
packet_peer_stream->put_var(obj->get_class());
|
2017-10-17 16:37:25 +02:00
|
|
|
packet_peer_stream->put_var(send_props);
|
2016-05-23 00:28:37 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void ScriptDebuggerRemote::_set_object_property(ObjectID p_id, const String &p_property, const Variant &p_value) {
|
2016-05-23 00:28:37 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Object *obj = ObjectDB::get_instance(p_id);
|
2016-05-23 00:28:37 +02:00
|
|
|
if (!obj)
|
|
|
|
return;
|
|
|
|
|
2017-10-17 16:37:25 +02:00
|
|
|
String prop_name = p_property;
|
2018-04-25 07:23:05 +02:00
|
|
|
if (p_property.begins_with("Members/")) {
|
|
|
|
Vector<String> ss = p_property.split("/");
|
|
|
|
prop_name = ss[ss.size() - 1];
|
|
|
|
}
|
2017-10-17 16:37:25 +02:00
|
|
|
|
|
|
|
obj->set(prop_name, p_value);
|
2016-05-23 00:28:37 +02:00
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void ScriptDebuggerRemote::_poll_events() {
|
|
|
|
|
2016-05-22 02:18:16 +02:00
|
|
|
//this si called from ::idle_poll, happens only when running the game,
|
|
|
|
//does not get called while on debug break
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (packet_peer_stream->get_available_packet_count() > 0) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
_get_output();
|
|
|
|
|
|
|
|
//send over output_strings
|
|
|
|
|
|
|
|
Variant var;
|
|
|
|
Error err = packet_peer_stream->get_var(var);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_CONTINUE(err != OK);
|
|
|
|
ERR_CONTINUE(var.get_type() != Variant::ARRAY);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Array cmd = var;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_CONTINUE(cmd.size() == 0);
|
|
|
|
ERR_CONTINUE(cmd[0].get_type() != Variant::STRING);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
String command = cmd[0];
|
2015-08-02 17:29:37 +02:00
|
|
|
//cmd.remove(0);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (command == "break") {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (get_break_language())
|
|
|
|
debug(get_break_language());
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (command == "request_scene_tree") {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-04-06 22:55:01 +02:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
if (scene_tree)
|
|
|
|
scene_tree->_debugger_request_tree();
|
|
|
|
#endif
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (command == "request_video_mem") {
|
2015-10-21 14:50:44 +02:00
|
|
|
|
|
|
|
_send_video_memory();
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (command == "inspect_object") {
|
2016-05-23 00:28:37 +02:00
|
|
|
|
|
|
|
ObjectID id = cmd[1];
|
|
|
|
_send_object_id(id);
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (command == "set_object_property") {
|
2016-05-23 00:28:37 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_set_object_property(cmd[1], cmd[2], cmd[3]);
|
2016-05-23 00:28:37 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (command == "start_profiling") {
|
2016-05-22 02:18:16 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
|
2016-05-22 02:18:16 +02:00
|
|
|
ScriptServer::get_language(i)->profiling_start();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
max_frame_functions = cmd[1];
|
2016-05-22 02:18:16 +02:00
|
|
|
profiler_function_signature_map.clear();
|
2017-03-05 16:44:50 +01:00
|
|
|
profiling = true;
|
|
|
|
frame_time = 0;
|
|
|
|
idle_time = 0;
|
2017-09-30 16:19:07 +02:00
|
|
|
physics_time = 0;
|
|
|
|
physics_frame_time = 0;
|
2016-05-22 02:18:16 +02:00
|
|
|
|
|
|
|
print_line("PROFILING ALRIGHT!");
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (command == "stop_profiling") {
|
2016-05-22 02:18:16 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
|
2016-05-22 02:18:16 +02:00
|
|
|
ScriptServer::get_language(i)->profiling_stop();
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
profiling = false;
|
2016-05-22 02:18:16 +02:00
|
|
|
_send_profiling_data(false);
|
|
|
|
print_line("PROFILING END!");
|
2019-09-01 18:38:58 +02:00
|
|
|
} else if (command == "start_network_profiling") {
|
|
|
|
|
|
|
|
multiplayer->profiling_start();
|
|
|
|
profiling_network = true;
|
|
|
|
} else if (command == "stop_network_profiling") {
|
|
|
|
|
|
|
|
multiplayer->profiling_end();
|
|
|
|
profiling_network = false;
|
2019-04-06 22:55:01 +02:00
|
|
|
} else if (command == "override_camera_2D:set") {
|
|
|
|
bool enforce = cmd[1];
|
|
|
|
|
|
|
|
if (scene_tree) {
|
|
|
|
scene_tree->get_root()->enable_canvas_transform_override(enforce);
|
|
|
|
}
|
|
|
|
} else if (command == "override_camera_2D:transform") {
|
|
|
|
Transform2D transform = cmd[1];
|
|
|
|
|
|
|
|
if (scene_tree) {
|
|
|
|
scene_tree->get_root()->set_canvas_transform_override(transform);
|
|
|
|
}
|
|
|
|
} else if (command == "override_camera_3D:set") {
|
|
|
|
bool enable = cmd[1];
|
|
|
|
|
|
|
|
if (scene_tree) {
|
|
|
|
scene_tree->get_root()->enable_camera_override(enable);
|
|
|
|
}
|
|
|
|
} else if (command == "override_camera_3D:transform") {
|
|
|
|
Transform transform = cmd[1];
|
|
|
|
bool is_perspective = cmd[2];
|
|
|
|
float size_or_fov = cmd[3];
|
|
|
|
float near = cmd[4];
|
|
|
|
float far = cmd[5];
|
|
|
|
|
|
|
|
if (scene_tree) {
|
|
|
|
if (is_perspective) {
|
|
|
|
scene_tree->get_root()->set_camera_override_perspective(size_or_fov, near, far);
|
|
|
|
} else {
|
|
|
|
scene_tree->get_root()->set_camera_override_orthogonal(size_or_fov, near, far);
|
|
|
|
}
|
|
|
|
scene_tree->get_root()->set_camera_override_transform(transform);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (command == "reload_scripts") {
|
|
|
|
reload_all_scripts = true;
|
|
|
|
} else if (command == "breakpoint") {
|
2015-08-05 01:17:13 +02:00
|
|
|
|
|
|
|
bool set = cmd[3];
|
|
|
|
if (set)
|
2017-03-05 16:44:50 +01:00
|
|
|
insert_breakpoint(cmd[2], cmd[1]);
|
2015-08-05 01:17:13 +02:00
|
|
|
else
|
2017-03-05 16:44:50 +01:00
|
|
|
remove_breakpoint(cmd[2], cmd[1]);
|
2019-07-29 20:09:22 +02:00
|
|
|
} else if (command == "set_skip_breakpoints") {
|
|
|
|
skip_breakpoints = cmd[1];
|
2015-08-02 17:29:37 +02:00
|
|
|
} else {
|
|
|
|
_parse_live_edit(cmd);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-22 02:18:16 +02:00
|
|
|
void ScriptDebuggerRemote::_send_profiling_data(bool p_for_frame) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int ofs = 0;
|
2016-05-22 02:18:16 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
|
2016-05-22 02:18:16 +02:00
|
|
|
if (p_for_frame)
|
2018-07-25 03:11:03 +02:00
|
|
|
ofs += ScriptServer::get_language(i)->profiling_get_frame_data(&profile_info.write[ofs], profile_info.size() - ofs);
|
2016-05-22 02:18:16 +02:00
|
|
|
else
|
2018-07-25 03:11:03 +02:00
|
|
|
ofs += ScriptServer::get_language(i)->profiling_get_accumulated_data(&profile_info.write[ofs], profile_info.size() - ofs);
|
2016-05-22 02:18:16 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < ofs; i++) {
|
2018-07-25 03:11:03 +02:00
|
|
|
profile_info_ptrs.write[i] = &profile_info.write[i];
|
2016-05-22 02:18:16 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
SortArray<ScriptLanguage::ProfilingInfo *, ProfileInfoSort> sa;
|
2017-11-25 04:07:54 +01:00
|
|
|
sa.sort(profile_info_ptrs.ptrw(), ofs);
|
2016-05-22 02:18:16 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int to_send = MIN(ofs, max_frame_functions);
|
2016-05-22 02:18:16 +02:00
|
|
|
|
|
|
|
//check signatures first
|
2017-03-05 16:44:50 +01:00
|
|
|
uint64_t total_script_time = 0;
|
2016-05-22 02:18:16 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < to_send; i++) {
|
2016-05-22 02:18:16 +02:00
|
|
|
|
|
|
|
if (!profiler_function_signature_map.has(profile_info_ptrs[i]->signature)) {
|
|
|
|
|
|
|
|
int idx = profiler_function_signature_map.size();
|
|
|
|
packet_peer_stream->put_var("profile_sig");
|
|
|
|
packet_peer_stream->put_var(2);
|
|
|
|
packet_peer_stream->put_var(profile_info_ptrs[i]->signature);
|
|
|
|
packet_peer_stream->put_var(idx);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
profiler_function_signature_map[profile_info_ptrs[i]->signature] = idx;
|
2016-05-22 02:18:16 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
total_script_time += profile_info_ptrs[i]->self_time;
|
2016-05-22 02:18:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//send frames then
|
|
|
|
|
|
|
|
if (p_for_frame) {
|
|
|
|
packet_peer_stream->put_var("profile_frame");
|
2017-03-05 16:44:50 +01:00
|
|
|
packet_peer_stream->put_var(8 + profile_frame_data.size() * 2 + to_send * 4);
|
2016-05-22 02:18:16 +02:00
|
|
|
} else {
|
|
|
|
packet_peer_stream->put_var("profile_total");
|
2017-03-05 16:44:50 +01:00
|
|
|
packet_peer_stream->put_var(8 + to_send * 4);
|
2016-05-22 02:18:16 +02:00
|
|
|
}
|
|
|
|
|
2020-03-31 03:49:29 +02:00
|
|
|
packet_peer_stream->put_var(Engine::get_singleton()->get_idle_frames()); //total frame time
|
2016-05-22 02:18:16 +02:00
|
|
|
packet_peer_stream->put_var(frame_time); //total frame time
|
|
|
|
packet_peer_stream->put_var(idle_time); //idle frame time
|
2017-09-30 16:19:07 +02:00
|
|
|
packet_peer_stream->put_var(physics_time); //fixed frame time
|
|
|
|
packet_peer_stream->put_var(physics_frame_time); //fixed frame time
|
2016-05-22 02:18:16 +02:00
|
|
|
|
|
|
|
packet_peer_stream->put_var(USEC_TO_SEC(total_script_time)); //total script execution time
|
|
|
|
|
|
|
|
if (p_for_frame) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
packet_peer_stream->put_var(profile_frame_data.size()); //how many profile framedatas to send
|
2016-05-22 02:18:16 +02:00
|
|
|
packet_peer_stream->put_var(to_send); //how many script functions to send
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < profile_frame_data.size(); i++) {
|
2016-05-22 02:18:16 +02:00
|
|
|
|
|
|
|
packet_peer_stream->put_var(profile_frame_data[i].name);
|
|
|
|
packet_peer_stream->put_var(profile_frame_data[i].data);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
packet_peer_stream->put_var(0); //how many script functions to send
|
|
|
|
packet_peer_stream->put_var(to_send); //how many script functions to send
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < to_send; i++) {
|
2016-05-22 02:18:16 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int sig_id = -1;
|
2016-05-22 02:18:16 +02:00
|
|
|
|
|
|
|
if (profiler_function_signature_map.has(profile_info_ptrs[i]->signature)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
sig_id = profiler_function_signature_map[profile_info_ptrs[i]->signature];
|
2016-05-22 02:18:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
packet_peer_stream->put_var(sig_id);
|
|
|
|
packet_peer_stream->put_var(profile_info_ptrs[i]->call_count);
|
2017-03-05 16:44:50 +01:00
|
|
|
packet_peer_stream->put_var(profile_info_ptrs[i]->total_time / 1000000.0);
|
|
|
|
packet_peer_stream->put_var(profile_info_ptrs[i]->self_time / 1000000.0);
|
2016-05-22 02:18:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (p_for_frame) {
|
|
|
|
profile_frame_data.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void ScriptDebuggerRemote::idle_poll() {
|
|
|
|
|
2016-05-22 02:18:16 +02:00
|
|
|
// this function is called every frame, except when there is a debugger break (::debug() in this class)
|
|
|
|
// execution stops and remains in the ::debug function
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_get_output();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (requested_quit) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
packet_peer_stream->put_var("kill_me");
|
|
|
|
packet_peer_stream->put_var(0);
|
|
|
|
requested_quit = false;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (performance) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
uint64_t pt = OS::get_singleton()->get_ticks_msec();
|
2018-05-28 13:47:09 +02:00
|
|
|
if (pt - last_perf_time > 1000) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
last_perf_time = pt;
|
2014-02-10 02:10:30 +01:00
|
|
|
int max = performance->get("MONITOR_MAX");
|
|
|
|
Array arr;
|
|
|
|
arr.resize(max);
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < max; i++) {
|
|
|
|
arr[i] = performance->call("get_monitor", i);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
packet_peer_stream->put_var("performance");
|
|
|
|
packet_peer_stream->put_var(1);
|
|
|
|
packet_peer_stream->put_var(arr);
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (profiling) {
|
2016-05-22 02:18:16 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (skip_profile_frame) {
|
|
|
|
skip_profile_frame = false;
|
|
|
|
} else {
|
2016-05-22 02:18:16 +02:00
|
|
|
//send profiling info normally
|
|
|
|
_send_profiling_data(true);
|
2017-03-05 16:44:50 +01:00
|
|
|
}
|
|
|
|
}
|
2016-06-02 01:22:02 +02:00
|
|
|
|
2019-09-01 18:38:58 +02:00
|
|
|
if (profiling_network) {
|
|
|
|
uint64_t pt = OS::get_singleton()->get_ticks_msec();
|
|
|
|
if (pt - last_net_bandwidth_time > 200) {
|
|
|
|
last_net_bandwidth_time = pt;
|
|
|
|
_send_network_bandwidth_usage();
|
|
|
|
}
|
|
|
|
if (pt - last_net_prof_time > 100) {
|
|
|
|
last_net_prof_time = pt;
|
|
|
|
_send_network_profiling_data();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (reload_all_scripts) {
|
2016-06-02 01:22:02 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
|
|
|
|
ScriptServer::get_language(i)->reload_all_scripts();
|
|
|
|
}
|
|
|
|
reload_all_scripts = false;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_poll_events();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2019-09-01 18:38:58 +02:00
|
|
|
void ScriptDebuggerRemote::_send_network_profiling_data() {
|
|
|
|
ERR_FAIL_COND(multiplayer.is_null());
|
|
|
|
|
|
|
|
int n_nodes = multiplayer->get_profiling_frame(&network_profile_info.write[0]);
|
|
|
|
|
|
|
|
packet_peer_stream->put_var("network_profile");
|
|
|
|
packet_peer_stream->put_var(n_nodes * 6);
|
|
|
|
for (int i = 0; i < n_nodes; ++i) {
|
|
|
|
packet_peer_stream->put_var(network_profile_info[i].node);
|
|
|
|
packet_peer_stream->put_var(network_profile_info[i].node_path);
|
|
|
|
packet_peer_stream->put_var(network_profile_info[i].incoming_rpc);
|
|
|
|
packet_peer_stream->put_var(network_profile_info[i].incoming_rset);
|
|
|
|
packet_peer_stream->put_var(network_profile_info[i].outgoing_rpc);
|
|
|
|
packet_peer_stream->put_var(network_profile_info[i].outgoing_rset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScriptDebuggerRemote::_send_network_bandwidth_usage() {
|
|
|
|
ERR_FAIL_COND(multiplayer.is_null());
|
|
|
|
|
|
|
|
int incoming_bandwidth = multiplayer->get_incoming_bandwidth_usage();
|
|
|
|
int outgoing_bandwidth = multiplayer->get_outgoing_bandwidth_usage();
|
|
|
|
|
|
|
|
packet_peer_stream->put_var("network_bandwidth");
|
|
|
|
packet_peer_stream->put_var(2);
|
|
|
|
packet_peer_stream->put_var(incoming_bandwidth);
|
|
|
|
packet_peer_stream->put_var(outgoing_bandwidth);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void ScriptDebuggerRemote::send_message(const String &p_message, const Array &p_args) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
mutex->lock();
|
2017-01-14 15:07:57 +01:00
|
|
|
if (!locking && tcp_client->is_connected_to_host()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-01-03 17:04:10 +01:00
|
|
|
if (messages.size() >= max_messages_per_frame) {
|
|
|
|
n_messages_dropped++;
|
|
|
|
} else {
|
|
|
|
Message msg;
|
|
|
|
msg.message = p_message;
|
|
|
|
msg.data = p_args;
|
|
|
|
messages.push_back(msg);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
mutex->unlock();
|
|
|
|
}
|
|
|
|
|
2018-01-09 17:19:03 +01:00
|
|
|
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) {
|
|
|
|
|
|
|
|
OutputError oe;
|
|
|
|
oe.error = p_err;
|
|
|
|
oe.error_descr = p_descr;
|
|
|
|
oe.source_file = p_file;
|
|
|
|
oe.source_line = p_line;
|
|
|
|
oe.source_func = p_func;
|
|
|
|
oe.warning = p_type == ERR_HANDLER_WARNING;
|
|
|
|
uint64_t time = OS::get_singleton()->get_ticks_msec();
|
|
|
|
oe.hr = time / 3600000;
|
|
|
|
oe.min = (time / 60000) % 60;
|
|
|
|
oe.sec = (time / 1000) % 60;
|
|
|
|
oe.msec = time % 1000;
|
|
|
|
Array cstack;
|
|
|
|
|
2019-07-31 17:24:53 +02:00
|
|
|
uint64_t ticks = OS::get_singleton()->get_ticks_usec() / 1000;
|
|
|
|
msec_count += ticks - last_msec;
|
|
|
|
last_msec = ticks;
|
|
|
|
|
|
|
|
if (msec_count > 1000) {
|
|
|
|
msec_count = 0;
|
|
|
|
|
|
|
|
err_count = 0;
|
|
|
|
n_errors_dropped = 0;
|
|
|
|
warn_count = 0;
|
|
|
|
n_warnings_dropped = 0;
|
|
|
|
}
|
|
|
|
|
2018-01-09 17:19:03 +01:00
|
|
|
cstack.resize(p_stack_info.size() * 3);
|
|
|
|
for (int i = 0; i < p_stack_info.size(); i++) {
|
|
|
|
cstack[i * 3 + 0] = p_stack_info[i].file;
|
|
|
|
cstack[i * 3 + 1] = p_stack_info[i].func;
|
|
|
|
cstack[i * 3 + 2] = p_stack_info[i].line;
|
|
|
|
}
|
|
|
|
|
|
|
|
oe.callstack = cstack;
|
2019-07-31 17:24:53 +02:00
|
|
|
if (oe.warning) {
|
|
|
|
warn_count++;
|
|
|
|
} else {
|
|
|
|
err_count++;
|
|
|
|
}
|
2018-01-09 17:19:03 +01:00
|
|
|
|
|
|
|
mutex->lock();
|
|
|
|
|
|
|
|
if (!locking && tcp_client->is_connected_to_host()) {
|
|
|
|
|
2019-07-31 17:24:53 +02:00
|
|
|
if (oe.warning) {
|
|
|
|
if (warn_count > max_warnings_per_second) {
|
|
|
|
n_warnings_dropped++;
|
|
|
|
} else {
|
|
|
|
errors.push_back(oe);
|
|
|
|
}
|
2018-01-09 17:19:03 +01:00
|
|
|
} else {
|
2019-07-31 17:24:53 +02:00
|
|
|
if (err_count > max_errors_per_second) {
|
|
|
|
n_errors_dropped++;
|
|
|
|
} else {
|
|
|
|
errors.push_back(oe);
|
|
|
|
}
|
2018-01-09 17:19:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex->unlock();
|
|
|
|
}
|
|
|
|
|
2017-11-14 23:01:45 +01:00
|
|
|
void ScriptDebuggerRemote::_print_handler(void *p_this, const String &p_string, bool p_error) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ScriptDebuggerRemote *sdr = (ScriptDebuggerRemote *)p_this;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uint64_t ticks = OS::get_singleton()->get_ticks_usec() / 1000;
|
|
|
|
sdr->msec_count += ticks - sdr->last_msec;
|
|
|
|
sdr->last_msec = ticks;
|
2015-08-04 14:47:32 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (sdr->msec_count > 1000) {
|
|
|
|
sdr->char_count = 0;
|
|
|
|
sdr->msec_count = 0;
|
2015-08-04 14:47:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String s = p_string;
|
2017-03-05 16:44:50 +01:00
|
|
|
int allowed_chars = MIN(MAX(sdr->max_cps - sdr->char_count, 0), s.length());
|
2015-08-04 14:47:32 +02:00
|
|
|
|
2020-05-07 02:26:29 +02:00
|
|
|
if (allowed_chars == 0 && s.length() > 0)
|
2015-08-04 14:47:32 +02:00
|
|
|
return;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (allowed_chars < s.length()) {
|
|
|
|
s = s.substr(0, allowed_chars);
|
2015-08-04 14:47:32 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
sdr->char_count += allowed_chars;
|
2017-10-16 22:10:11 +02:00
|
|
|
bool overflowed = sdr->char_count >= sdr->max_cps;
|
2015-08-04 14:47:32 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
sdr->mutex->lock();
|
2017-01-14 15:07:57 +01:00
|
|
|
if (!sdr->locking && sdr->tcp_client->is_connected_to_host()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-10-16 22:10:11 +02:00
|
|
|
if (overflowed)
|
|
|
|
s += "[...]";
|
|
|
|
|
2019-11-29 15:06:42 +01:00
|
|
|
OutputString output_string;
|
|
|
|
output_string.message = s;
|
|
|
|
output_string.type = p_error ? MESSAGE_TYPE_ERROR : MESSAGE_TYPE_LOG;
|
|
|
|
sdr->output_strings.push_back(output_string);
|
2017-10-16 22:10:11 +02:00
|
|
|
|
|
|
|
if (overflowed) {
|
2019-11-29 15:06:42 +01:00
|
|
|
output_string.message = "[output overflow, print less text!]";
|
|
|
|
output_string.type = MESSAGE_TYPE_ERROR;
|
|
|
|
sdr->output_strings.push_back(output_string);
|
2017-10-16 22:10:11 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
sdr->mutex->unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScriptDebuggerRemote::request_quit() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
requested_quit = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2019-09-01 18:38:58 +02:00
|
|
|
void ScriptDebuggerRemote::set_multiplayer(Ref<MultiplayerAPI> p_multiplayer) {
|
|
|
|
multiplayer = p_multiplayer;
|
|
|
|
}
|
|
|
|
|
2016-05-22 02:18:16 +02:00
|
|
|
bool ScriptDebuggerRemote::is_profiling() const {
|
|
|
|
|
|
|
|
return profiling;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
void ScriptDebuggerRemote::add_profiling_frame_data(const StringName &p_name, const Array &p_data) {
|
2016-05-22 02:18:16 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int idx = -1;
|
|
|
|
for (int i = 0; i < profile_frame_data.size(); i++) {
|
|
|
|
if (profile_frame_data[i].name == p_name) {
|
|
|
|
idx = i;
|
2016-05-22 02:18:16 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FrameData fd;
|
2017-03-05 16:44:50 +01:00
|
|
|
fd.name = p_name;
|
|
|
|
fd.data = p_data;
|
2016-05-22 02:18:16 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (idx == -1) {
|
2016-05-22 02:18:16 +02:00
|
|
|
profile_frame_data.push_back(fd);
|
|
|
|
} else {
|
2018-07-25 03:11:03 +02:00
|
|
|
profile_frame_data.write[idx] = fd;
|
2016-05-22 02:18:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScriptDebuggerRemote::profiling_start() {
|
2018-02-21 17:30:55 +01:00
|
|
|
//ignores this, uses it via connection
|
2016-05-22 02:18:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScriptDebuggerRemote::profiling_end() {
|
2018-02-21 17:30:55 +01:00
|
|
|
//ignores this, uses it via connection
|
2016-05-22 02:18:16 +02:00
|
|
|
}
|
|
|
|
|
2017-09-30 16:19:07 +02:00
|
|
|
void ScriptDebuggerRemote::profiling_set_frame_times(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time) {
|
2016-05-22 02:18:16 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
frame_time = p_frame_time;
|
|
|
|
idle_time = p_idle_time;
|
2017-09-30 16:19:07 +02:00
|
|
|
physics_time = p_physics_time;
|
|
|
|
physics_frame_time = p_physics_frame_time;
|
2016-05-22 02:18:16 +02:00
|
|
|
}
|
|
|
|
|
2019-07-29 20:09:22 +02:00
|
|
|
void ScriptDebuggerRemote::set_skip_breakpoints(bool p_skip_breakpoints) {
|
|
|
|
skip_breakpoints = p_skip_breakpoints;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ScriptDebuggerRemote::ResourceUsageFunc ScriptDebuggerRemote::resource_usage_func = NULL;
|
2015-10-21 14:50:44 +02:00
|
|
|
|
2017-12-06 21:36:34 +01:00
|
|
|
ScriptDebuggerRemote::ScriptDebuggerRemote() :
|
|
|
|
profiling(false),
|
2019-09-01 18:38:58 +02:00
|
|
|
profiling_network(false),
|
2017-12-06 21:36:34 +01:00
|
|
|
max_frame_functions(16),
|
|
|
|
skip_profile_frame(false),
|
|
|
|
reload_all_scripts(false),
|
2018-09-02 06:36:45 +02:00
|
|
|
tcp_client(Ref<StreamPeerTCP>(memnew(StreamPeerTCP))),
|
2017-12-06 21:36:34 +01:00
|
|
|
packet_peer_stream(Ref<PacketPeerStream>(memnew(PacketPeerStream))),
|
|
|
|
last_perf_time(0),
|
2019-09-01 18:38:58 +02:00
|
|
|
last_net_prof_time(0),
|
|
|
|
last_net_bandwidth_time(0),
|
2017-12-06 21:36:34 +01:00
|
|
|
performance(Engine::get_singleton()->get_singleton_object("Performance")),
|
|
|
|
requested_quit(false),
|
|
|
|
mutex(Mutex::create()),
|
2018-01-03 17:04:10 +01:00
|
|
|
max_messages_per_frame(GLOBAL_GET("network/limits/debugger_stdout/max_messages_per_frame")),
|
|
|
|
n_messages_dropped(0),
|
2019-07-31 17:24:53 +02:00
|
|
|
max_errors_per_second(GLOBAL_GET("network/limits/debugger_stdout/max_errors_per_second")),
|
|
|
|
max_warnings_per_second(GLOBAL_GET("network/limits/debugger_stdout/max_warnings_per_second")),
|
2018-01-03 17:04:10 +01:00
|
|
|
n_errors_dropped(0),
|
2018-09-28 17:17:38 +02:00
|
|
|
max_cps(GLOBAL_GET("network/limits/debugger_stdout/max_chars_per_second")),
|
|
|
|
char_count(0),
|
2019-07-31 17:24:53 +02:00
|
|
|
err_count(0),
|
|
|
|
warn_count(0),
|
2017-12-06 21:36:34 +01:00
|
|
|
last_msec(0),
|
|
|
|
msec_count(0),
|
|
|
|
locking(false),
|
|
|
|
poll_every(0),
|
2019-04-06 22:55:01 +02:00
|
|
|
scene_tree(NULL) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
packet_peer_stream->set_stream_peer(tcp_client);
|
2019-12-21 16:45:55 +01:00
|
|
|
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.
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
phl.printfunc = _print_handler;
|
|
|
|
phl.userdata = this;
|
2014-02-10 02:10:30 +01:00
|
|
|
add_print_handler(&phl);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
|
|
|
eh.errfunc = _err_handler;
|
|
|
|
eh.userdata = this;
|
2015-08-04 14:47:32 +02:00
|
|
|
add_error_handler(&eh);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-10-05 18:43:53 +02:00
|
|
|
profile_info.resize(GLOBAL_GET("debug/settings/profiler/max_functions"));
|
2019-09-01 18:38:58 +02:00
|
|
|
network_profile_info.resize(GLOBAL_GET("debug/settings/profiler/max_functions"));
|
2016-05-22 02:18:16 +02:00
|
|
|
profile_info_ptrs.resize(profile_info.size());
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ScriptDebuggerRemote::~ScriptDebuggerRemote() {
|
|
|
|
|
|
|
|
remove_print_handler(&phl);
|
2015-08-04 14:47:32 +02:00
|
|
|
remove_error_handler(&eh);
|
2014-02-10 02:10:30 +01:00
|
|
|
memdelete(mutex);
|
|
|
|
}
|