Debian Codegraph @

core/debugger/remote_debugger.h

raw symbols SCIP
1 /**************************************************************************/
2 /* remote_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 #pragma once
32
33 #include "core/debugger/debugger_marshalls.h"
34 #include "core/debugger/engine_debugger.h"
35 #include "core/debugger/remote_debugger_peer.h"
36 #include "core/object/class_db.h"
37 #include "core/string/string_name.h"
38 #include "core/string/ustring.h"
39 #include "core/variant/array.h"
40
41 class RemoteDebugger : public EngineDebugger {
42 public:
43 enum MessageType {
44 MESSAGE_TYPE_LOG,
45 MESSAGE_TYPE_ERROR,
46 MESSAGE_TYPE_LOG_RICH,
47 };
48
49 private:
50 typedef DebuggerMarshalls::OutputError ErrorMessage;
51
52 class PerformanceProfiler;
53
54 Ref<PerformanceProfiler> performance_profiler;
55
56 Ref<RemoteDebuggerPeer> peer;
57
58 struct OutputString {
59 String message;
60 MessageType type;
61 };
62 List<OutputString> output_strings;
63 List<ErrorMessage> errors;
64
65 int n_messages_dropped = 0;
66 int max_errors_per_second = 0;
67 int max_chars_per_second = 0;
68 int max_warnings_per_second = 0;
69 int n_errors_dropped = 0;
70 int n_warnings_dropped = 0;
71 int char_count = 0;
72 int err_count = 0;
73 int warn_count = 0;
74 int last_reset = 0;
75 bool reload_all_scripts = false;
76 Array script_paths_to_reload;
77
78 // Make handlers and send_message thread safe.
79 Mutex mutex;
80 bool flushing = false;
81 Thread::ID flush_thread = 0;
82
83 struct Message {
84 String message;
85 Array data;
86 };
87
88 HashMap<Thread::ID, List<Message>> messages;
89 HashSet<Thread::ID> threads_in_break;
90
91 void _poll_messages();
92 bool _has_messages();
93 Array _get_message();
94
95 PrintHandlerList phl;
96 static void _print_handler(void *p_this, const String &p_string, bool p_error, bool p_rich);
97 ErrorHandlerList eh;
98 static void _err_handler(void *p_this, const char *p_func, const char *p_file, int p_line, const char *p_err, const char *p_descr, bool p_editor_notify, ErrorHandlerType p_type);
99
100 ErrorMessage _create_overflow_error(const String &p_what, const String &p_descr);
101 Error _put_msg(const String &p_message, const Array &p_data);
102
103 bool is_peer_connected() { return peer->is_peer_connected(); }
104 void flush_output();
105
106 void _send_stack_vars(List<String> &p_names, List<Variant> &p_vals, int p_type);
107
108 Error _profiler_capture(const String &p_cmd, const Array &p_data, bool &r_captured);
109 Error _core_capture(const String &p_cmd, const Array &p_data, bool &r_captured);
110 Error _try_capture(const String &p_name, const Array &p_data, bool &r_captured);
111
112 public:
113 // Overrides
114 void poll_events(bool p_is_idle);
115 void send_message(const String &p_message, const Array &p_args);
116 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);
117 void debug(bool p_can_continue = true, bool p_is_error_breakpoint = false);
118
119 explicit RemoteDebugger(Ref<RemoteDebuggerPeer> p_peer);
120 ~RemoteDebugger();
121 };