1/**************************************************************************/
2/* script_debugger.h */
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#ifndef SCRIPT_DEBUGGER_H
32#define SCRIPT_DEBUGGER_H
33
34#include "core/object/script_language.h"
35#include "core/string/string_name.h"
36#include "core/templates/hash_set.h"
37#include "core/templates/rb_map.h"
38#include "core/templates/vector.h"
39
40class ScriptDebugger {
41 typedef ScriptLanguage::StackInfo StackInfo;
42
43 bool skip_breakpoints = false;
44
45 HashMap<int, HashSet<StringName>> breakpoints;
46
47 static thread_local int lines_left;
48 static thread_local int depth;
49 static thread_local ScriptLanguage *break_lang;
50 static thread_local Vector<StackInfo> error_stack_info;
51
52public:
53 void set_lines_left(int p_left);
54 _ALWAYS_INLINE_ int get_lines_left() const {
55 return lines_left;
56 }
57
58 void set_depth(int p_depth);
59 _ALWAYS_INLINE_ int get_depth() const {
60 return depth;
61 }
62
63 String breakpoint_find_source(const String &p_source) const;
64 void set_break_language(ScriptLanguage *p_lang) { break_lang = p_lang; }
65 ScriptLanguage *get_break_language() { return break_lang; }
66 void set_skip_breakpoints(bool p_skip_breakpoints);
67 bool is_skipping_breakpoints();
68 void insert_breakpoint(int p_line, const StringName &p_source);
69 void remove_breakpoint(int p_line, const StringName &p_source);
70 _ALWAYS_INLINE_ bool is_breakpoint(int p_line, const StringName &p_source) const {
71 if (likely(!breakpoints.has(p_line))) {
72 return false;
73 }
74 return breakpoints[p_line].has(p_source);
75 }
76 void clear_breakpoints();
77 const HashMap<int, HashSet<StringName>> &get_breakpoints() const { return breakpoints; }
78
79 void debug(ScriptLanguage *p_lang, bool p_can_continue = true, bool p_is_error_breakpoint = false);
80 ScriptLanguage *get_break_language() const;
81
82 void 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);
83 Vector<StackInfo> get_error_stack_info() const;
84 ScriptDebugger() {}
85};
86
87#endif // SCRIPT_DEBUGGER_H
88