| 1 | /**************************************************************************/ |
| 2 | /* script_debugger.cpp */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 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 | |
| 31 | #include "script_debugger.h" |
| 32 | |
| 33 | #include "core/debugger/engine_debugger.h" |
| 34 | |
| 35 | thread_local int ScriptDebugger::lines_left = -1; |
| 36 | thread_local int ScriptDebugger::depth = -1; |
| 37 | thread_local ScriptLanguage *ScriptDebugger::break_lang = nullptr; |
| 38 | thread_local Vector<ScriptDebugger::StackInfo> ScriptDebugger::error_stack_info; |
| 39 | |
| 40 | void ScriptDebugger::set_lines_left(int p_left) { |
| 41 | lines_left = p_left; |
| 42 | } |
| 43 | |
| 44 | void ScriptDebugger::set_depth(int p_depth) { |
| 45 | depth = p_depth; |
| 46 | } |
| 47 | |
| 48 | void ScriptDebugger::insert_breakpoint(int p_line, const StringName &p_source) { |
| 49 | if (!breakpoints.has(p_line)) { |
| 50 | breakpoints[p_line] = HashSet<StringName>(); |
| 51 | } |
| 52 | breakpoints[p_line].insert(p_source); |
| 53 | } |
| 54 | |
| 55 | void ScriptDebugger::remove_breakpoint(int p_line, const StringName &p_source) { |
| 56 | if (!breakpoints.has(p_line)) { |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | breakpoints[p_line].erase(p_source); |
| 61 | if (breakpoints[p_line].size() == 0) { |
| 62 | breakpoints.erase(p_line); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | String ScriptDebugger::breakpoint_find_source(const String &p_source) const { |
| 67 | return p_source; |
| 68 | } |
| 69 | |
| 70 | void ScriptDebugger::clear_breakpoints() { |
| 71 | breakpoints.clear(); |
| 72 | } |
| 73 | |
| 74 | void ScriptDebugger::set_skip_breakpoints(bool p_skip_breakpoints) { |
| 75 | skip_breakpoints = p_skip_breakpoints; |
| 76 | } |
| 77 | |
| 78 | bool ScriptDebugger::is_skipping_breakpoints() { |
| 79 | return skip_breakpoints; |
| 80 | } |
| 81 | |
| 82 | void ScriptDebugger::debug(ScriptLanguage *p_lang, bool p_can_continue, bool p_is_error_breakpoint) { |
| 83 | ScriptLanguage *prev = break_lang; |
| 84 | break_lang = p_lang; |
| 85 | EngineDebugger::get_singleton()->debug(p_can_continue, p_is_error_breakpoint); |
| 86 | break_lang = prev; |
| 87 | } |
| 88 | |
| 89 | void ScriptDebugger::send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, bool p_editor_notify, ErrorHandlerType p_type, const Vector<StackInfo> &p_stack_info) { |
| 90 | // Store stack info, this is ugly, but allows us to separate EngineDebugger and ScriptDebugger. There might be a better way. |
| 91 | error_stack_info.append_array(p_stack_info); |
| 92 | EngineDebugger::get_singleton()->send_error(p_func, p_file, p_line, p_err, p_descr, p_editor_notify, p_type); |
| 93 | error_stack_info.clear(); // Clear because this is thread local |
| 94 | } |
| 95 | |
| 96 | Vector<ScriptLanguage::StackInfo> ScriptDebugger::get_error_stack_info() const { |
| 97 | return error_stack_info; |
| 98 | } |
| 99 | |
| 100 | ScriptLanguage *ScriptDebugger::get_break_language() const { |
| 101 | return break_lang; |
| 102 | } |
| 103 | |