123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- /*************************************************************************/
- /* script_debugger_local.cpp */
- /*************************************************************************/
- /* This file is part of: */
- /* GODOT ENGINE */
- /* http://www.godotengine.org */
- /*************************************************************************/
- /* Copyright (c) 2007-2014 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 */
- /* "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. */
- /*************************************************************************/
- #include "script_debugger_local.h"
- #include "os/os.h"
- void ScriptDebuggerLocal::debug(ScriptLanguage *p_script,bool p_can_continue) {
- print_line("Debugger Break, Reason: '"+p_script->debug_get_error()+"'");
- print_line("*Frame "+itos(0)+" - "+p_script->debug_get_stack_level_source(0)+":"+itos(p_script->debug_get_stack_level_line(0))+" in function '"+p_script->debug_get_stack_level_function(0)+"'");
- print_line("Enter \"help\" for assistance.");
- int current_frame=0;
- int total_frames=p_script->debug_get_stack_level_count();
- while(true) {
- OS::get_singleton()->print("debug> ");
- String line = OS::get_singleton()->get_stdin_string().strip_edges();
- if (line=="") {
- print_line("Debugger Break, Reason: '"+p_script->debug_get_error()+"'");
- print_line("*Frame "+itos(current_frame)+" - "+p_script->debug_get_stack_level_source(current_frame)+":"+itos(p_script->debug_get_stack_level_line(current_frame))+" in function '"+p_script->debug_get_stack_level_function(current_frame)+"'");
- print_line("Enter \"help\" for assistance.");
- } else if (line=="c" || line=="continue")
- break;
- else if (line=="bt" || line=="breakpoint") {
- for(int i=0;i<total_frames;i++) {
- String cfi=(current_frame==i)?"*":" "; //current frame indicator
- print_line(cfi+"Frame "+itos(i)+" - "+p_script->debug_get_stack_level_source(i)+":"+itos(p_script->debug_get_stack_level_line(i))+" in function '"+p_script->debug_get_stack_level_function(i)+"'");
- }
- } else if (line.begins_with("fr") || line.begins_with("frame")) {
- if (line.get_slice_count(" ")==1) {
- print_line("*Frame "+itos(current_frame)+" - "+p_script->debug_get_stack_level_source(current_frame)+":"+itos(p_script->debug_get_stack_level_line(current_frame))+" in function '"+p_script->debug_get_stack_level_function(current_frame)+"'");
- } else {
- int frame = line.get_slice(" ",1).to_int();
- if (frame<0 || frame >=total_frames) {
- print_line("Error: Invalid frame.");
- } else {
- current_frame=frame;
- print_line("*Frame "+itos(frame)+" - "+p_script->debug_get_stack_level_source(frame)+":"+itos(p_script->debug_get_stack_level_line(frame))+" in function '"+p_script->debug_get_stack_level_function(frame)+"'");
- }
- }
- } else if (line=="lv" || line=="locals") {
- List<String> locals;
- List<Variant> values;
- p_script->debug_get_stack_level_locals(current_frame,&locals, &values);
- List<Variant>::Element* V = values.front();
- for (List<String>::Element *E=locals.front();E;E=E->next()) {
- print_line(E->get() + ": " + String(V->get()));
- V = V->next();
- }
- } else if (line=="gv" || line=="globals") {
- List<String> locals;
- List<Variant> values;
- p_script->debug_get_globals(&locals, &values);
- List<Variant>::Element* V = values.front();
- for (List<String>::Element *E=locals.front();E;E=E->next()) {
- print_line(E->get() + ": " + String(V->get()));
- V = V->next();
- }
- } else if (line=="mv" || line=="members") {
- List<String> locals;
- List<Variant> values;
- p_script->debug_get_stack_level_members(current_frame,&locals, &values);
- List<Variant>::Element* V = values.front();
- for (List<String>::Element *E=locals.front();E;E=E->next()) {
- print_line(E->get() + ": " + String(V->get()));
- V = V->next();
- }
- } else if (line.begins_with("p") || line.begins_with("print")) {
- if (line.get_slice_count(" ")<=1) {
- print_line("Usage: print <expre>");
- } else {
- String expr = line.get_slice(" ",2);
- String res = p_script->debug_parse_stack_level_expression(current_frame,expr);
- print_line(res);
- }
- } else if (line=="s" || line=="step") {
- set_depth(-1);
- set_lines_left(1);
- break;
- } else if (line.begins_with("n") || line.begins_with("next")) {
- set_depth(0);
- set_lines_left(1);
- break;
- } else if (line.begins_with("br") || line.begins_with("break")) {
- if (line.get_slice_count(" ")<=1) {
- //show breakpoints
- } else {
- String bppos=line.get_slice(" ",1);
- String source=bppos.get_slice(":",0).strip_edges();
- int line=bppos.get_slice(":",1).strip_edges().to_int();
- source = breakpoint_find_source(source);
- insert_breakpoint(line,source);
- print_line("BreakPoint at "+source+":"+itos(line));
- }
- } else if (line.begins_with("delete")) {
- if (line.get_slice_count(" ")<=1) {
- clear_breakpoints();
- } else {
- String bppos=line.get_slice(" ",1);
- String source=bppos.get_slice(":",0).strip_edges();
- int line=bppos.get_slice(":",1).strip_edges().to_int();
- source = breakpoint_find_source(source);
- remove_breakpoint(line,source);
- print_line("Removed BreakPoint at "+source+":"+itos(line));
- }
- } else if (line=="h" || line=="help") {
- print_line("Built-In Debugger command list:\n");
- print_line("\tc,continue :\t\t Continue execution.");
- print_line("\tbt,backtrace :\t\t Show stack trace (frames).");
- print_line("\tfr,frame <frame>:\t Change current frame.");
- print_line("\tlv,locals :\t\t Show local variables for current frame.");
- print_line("\tmv,members :\t\t Show member variables for \"this\" in frame.");
- print_line("\tgv,globals :\t\t Show global variables.");
- print_line("\tp,print <expr> :\t Execute and print variable in expression.");
- print_line("\ts,step :\t\t Step to next line.");
- print_line("\tn,next :\t\t Next line.");
- print_line("\tbr,break source:line :\t Place a breakpoint.");
- print_line("\tdelete [source:line]:\t\t Delete one/all breakpoints.");
- } else {
- print_line("Error: Invalid command, enter \"help\" for assistance.");
- }
- }
- }
- void ScriptDebuggerLocal::send_message(const String& p_message, const Array &p_args) {
- print_line("MESSAGE: '"+p_message+"' - "+String(Variant(p_args)));
- }
- ScriptDebuggerLocal::ScriptDebuggerLocal() {
- }
|