diff options
Diffstat (limited to 'core/script_debugger_remote.cpp')
| -rw-r--r-- | core/script_debugger_remote.cpp | 292 |
1 files changed, 285 insertions, 7 deletions
diff --git a/core/script_debugger_remote.cpp b/core/script_debugger_remote.cpp index cd8303b54..d72c9f753 100644 --- a/core/script_debugger_remote.cpp +++ b/core/script_debugger_remote.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -31,10 +31,36 @@ #include "io/ip.h" #include "globals.h" +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"); + packet_peer_stream->put_var(usage.size()*4); + + + for(List<ResourceUsage>::Element *E=usage.front();E;E=E->next()) { + + 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); + } + +} + Error ScriptDebuggerRemote::connect_to_host(const String& p_host,uint16_t p_port) { - IP_Address ip = IP::get_singleton()->resolve_hostname(p_host); + IP_Address ip; + if (p_host.is_valid_ip_address()) + ip=p_host; + else + ip = IP::get_singleton()->resolve_hostname(p_host); int port = p_port; @@ -127,7 +153,7 @@ void ScriptDebuggerRemote::debug(ScriptLanguage *p_script,bool p_can_continue) { ERR_CONTINUE( cmd[0].get_type()!=Variant::STRING ); String command = cmd[0]; - cmd.remove(0); + if (command=="get_stack_dump") { @@ -150,7 +176,7 @@ void ScriptDebuggerRemote::debug(ScriptLanguage *p_script,bool p_can_continue) { } else if (command=="get_stack_frame_vars") { - + cmd.remove(0); ERR_CONTINUE( cmd.size()!=1 ); int lv = cmd[0]; @@ -243,6 +269,20 @@ void ScriptDebuggerRemote::debug(ScriptLanguage *p_script,bool p_can_continue) { if (request_scene_tree) request_scene_tree(request_scene_tree_ud); + + } else if (command=="request_video_mem") { + + _send_video_memory(); + } else if (command=="breakpoint") { + + bool set = cmd[3]; + if (set) + insert_breakpoint(cmd[2],cmd[1]); + else + remove_breakpoint(cmd[2],cmd[1]); + + } else { + _parse_live_edit(cmd); } @@ -287,6 +327,37 @@ void ScriptDebuggerRemote::_get_output() { messages.pop_front(); locking=false; } + + while (errors.size()) { + locking=true; + packet_peer_stream->put_var("error"); + OutputError oe = errors.front()->get(); + + packet_peer_stream->put_var(oe.callstack.size()+2); + + 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()); + for(int i=0;i<oe.callstack.size();i++) { + packet_peer_stream->put_var(oe.callstack[i]); + + } + + errors.pop_front(); + locking=false; + + } mutex->unlock(); } @@ -301,6 +372,160 @@ void ScriptDebuggerRemote::line_poll() { } +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) { + + if (p_type==ERR_HANDLER_SCRIPT) + return; //ignore script errors, those go through debugger + + ScriptDebuggerRemote *sdr = (ScriptDebuggerRemote*)ud; + + 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; + + Vector<ScriptLanguage::StackInfo> si; + + for(int i=0;i<ScriptServer::get_language_count();i++) { + si=ScriptServer::get_language(i)->debug_get_current_stack_info(); + if (si.size()) + break; + } + + cstack.resize(si.size()*2); + for(int i=0;i<si.size();i++) { + String path; + int line=0; + if (si[i].script.is_valid()) { + path=si[i].script->get_path(); + line=si[i].line; + } + cstack[i*2+0]=path; + cstack[i*2+1]=line; + } + + oe.callstack=cstack; + + + sdr->mutex->lock(); + + if (!sdr->locking && sdr->tcp_client->is_connected()) { + + sdr->errors.push_back(oe); + } + + sdr->mutex->unlock(); +} + + +bool ScriptDebuggerRemote::_parse_live_edit(const Array& cmd) { + + String cmdstr = cmd[0]; + if (!live_edit_funcs || !cmdstr.begins_with("live_")) + return false; + + + //print_line(Variant(cmd).get_construct_string()); + if (cmdstr=="live_set_root") { + + if (!live_edit_funcs->root_func) + return true; + //print_line("root: "+Variant(cmd).get_construct_string()); + live_edit_funcs->root_func(live_edit_funcs->udata,cmd[1],cmd[2]); + + } else if (cmdstr=="live_node_path") { + + if (!live_edit_funcs->node_path_func) + return true; + //print_line("path: "+Variant(cmd).get_construct_string()); + + live_edit_funcs->node_path_func(live_edit_funcs->udata,cmd[1],cmd[2]); + + } else if (cmdstr=="live_res_path") { + + if (!live_edit_funcs->res_path_func) + return true; + live_edit_funcs->res_path_func(live_edit_funcs->udata,cmd[1],cmd[2]); + + } else if (cmdstr=="live_node_prop_res") { + if (!live_edit_funcs->node_set_res_func) + return true; + + live_edit_funcs->node_set_res_func(live_edit_funcs->udata,cmd[1],cmd[2],cmd[3]); + + } else if (cmdstr=="live_node_prop") { + + if (!live_edit_funcs->node_set_func) + return true; + live_edit_funcs->node_set_func(live_edit_funcs->udata,cmd[1],cmd[2],cmd[3]); + + } else if (cmdstr=="live_res_prop_res") { + + if (!live_edit_funcs->res_set_res_func) + return true; + live_edit_funcs->res_set_res_func(live_edit_funcs->udata,cmd[1],cmd[2],cmd[3]); + + } else if (cmdstr=="live_res_prop") { + + if (!live_edit_funcs->res_set_func) + return true; + live_edit_funcs->res_set_func(live_edit_funcs->udata,cmd[1],cmd[2],cmd[3]); + + } else if (cmdstr=="live_node_call") { + + if (!live_edit_funcs->node_call_func) + return true; + live_edit_funcs->node_call_func(live_edit_funcs->udata,cmd[1],cmd[2], cmd[3],cmd[4],cmd[5],cmd[6],cmd[7]); + + } else if (cmdstr=="live_res_call") { + + if (!live_edit_funcs->res_call_func) + return true; + live_edit_funcs->res_call_func(live_edit_funcs->udata,cmd[1],cmd[2], cmd[3],cmd[4],cmd[5],cmd[6],cmd[7]); + + } else if (cmdstr=="live_create_node") { + + live_edit_funcs->tree_create_node_func(live_edit_funcs->udata,cmd[1],cmd[2],cmd[3]); + + } else if (cmdstr=="live_instance_node") { + + live_edit_funcs->tree_instance_node_func(live_edit_funcs->udata,cmd[1],cmd[2],cmd[3]); + + } else if (cmdstr=="live_remove_node") { + + live_edit_funcs->tree_remove_node_func(live_edit_funcs->udata,cmd[1]); + + } else if (cmdstr=="live_remove_and_keep_node") { + + live_edit_funcs->tree_remove_and_keep_node_func(live_edit_funcs->udata,cmd[1],cmd[2]); + } else if (cmdstr=="live_restore_node") { + + live_edit_funcs->tree_restore_node_func(live_edit_funcs->udata,cmd[1],cmd[2],cmd[3]); + + } else if (cmdstr=="live_duplicate_node") { + + live_edit_funcs->tree_duplicate_node_func(live_edit_funcs->udata,cmd[1],cmd[2]); + } else if (cmdstr=="live_reparent_node") { + + live_edit_funcs->tree_reparent_node_func(live_edit_funcs->udata,cmd[1],cmd[2],cmd[3],cmd[4]); + + } else { + + return false; + } + + return true; +} + void ScriptDebuggerRemote::_poll_events() { while(packet_peer_stream->get_available_packet_count()>0) { @@ -321,7 +546,7 @@ void ScriptDebuggerRemote::_poll_events() { ERR_CONTINUE( cmd[0].get_type()!=Variant::STRING ); String command = cmd[0]; - cmd.remove(0); + //cmd.remove(0); if (command=="break") { @@ -331,6 +556,18 @@ void ScriptDebuggerRemote::_poll_events() { if (request_scene_tree) request_scene_tree(request_scene_tree_ud); + } else if (command=="request_video_mem") { + + _send_video_memory(); + } else if (command=="breakpoint") { + + bool set = cmd[3]; + if (set) + insert_breakpoint(cmd[2],cmd[1]); + else + remove_breakpoint(cmd[2],cmd[1]); + } else { + _parse_live_edit(cmd); } } @@ -394,10 +631,35 @@ void ScriptDebuggerRemote::_print_handler(void *p_this,const String& p_string) { ScriptDebuggerRemote *sdr = (ScriptDebuggerRemote*)p_this; + uint64_t ticks = OS::get_singleton()->get_ticks_usec()/1000; + sdr->msec_count+=ticks-sdr->last_msec; + sdr->last_msec=ticks; + + if (sdr->msec_count>1000) { + sdr->char_count=0; + sdr->msec_count=0; + } + + String s = p_string; + int allowed_chars = MIN(MAX(sdr->max_cps - sdr->char_count,0), s.length()); + + if (allowed_chars==0) + return; + + if (allowed_chars<s.length()) { + s=s.substr(0,allowed_chars); + } + + sdr->char_count+=allowed_chars; + + if (sdr->char_count>=sdr->max_cps) { + s+="\n[output overflow, print less text!]\n"; + } + sdr->mutex->lock(); if (!sdr->locking && sdr->tcp_client->is_connected()) { - sdr->output_strings .push_back(p_string); + sdr->output_strings.push_back(s); } sdr->mutex->unlock(); } @@ -413,6 +675,13 @@ void ScriptDebuggerRemote::set_request_scene_tree_message_func(RequestSceneTreeM request_scene_tree_ud=p_udata; } +void ScriptDebuggerRemote::set_live_edit_funcs(LiveEditFuncs *p_funcs) { + + live_edit_funcs=p_funcs; +} + +ScriptDebuggerRemote::ResourceUsageFunc ScriptDebuggerRemote::resource_usage_func=NULL; + ScriptDebuggerRemote::ScriptDebuggerRemote() { tcp_client = StreamPeerTCP::create_ref(); @@ -429,13 +698,22 @@ ScriptDebuggerRemote::ScriptDebuggerRemote() { last_perf_time=0; poll_every=0; request_scene_tree=NULL; + live_edit_funcs=NULL; + max_cps = GLOBAL_DEF("debug/max_remote_stdout_chars_per_second",2048); + char_count=0; + msec_count=0; + last_msec=0; + + eh.errfunc=_err_handler; + eh.userdata=this; + add_error_handler(&eh); } ScriptDebuggerRemote::~ScriptDebuggerRemote() { remove_print_handler(&phl); + remove_error_handler(&eh); memdelete(mutex); - } |
