script_debugger.cpp 4.4 KB

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