2020-02-27 02:30:20 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* engine_debugger.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2021-01-01 19:13:46 +00:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2020-02-27 02:30:20 +00:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
#ifndef ENGINE_DEBUGGER_H
|
|
|
|
#define ENGINE_DEBUGGER_H
|
|
|
|
|
2020-11-07 22:33:38 +00:00
|
|
|
#include "core/string/string_name.h"
|
|
|
|
#include "core/string/ustring.h"
|
|
|
|
#include "core/templates/map.h"
|
|
|
|
#include "core/templates/vector.h"
|
|
|
|
#include "core/variant/array.h"
|
|
|
|
#include "core/variant/variant.h"
|
2020-02-27 02:30:20 +00:00
|
|
|
|
2020-03-11 10:23:21 +00:00
|
|
|
class RemoteDebuggerPeer;
|
2020-02-27 02:30:20 +00:00
|
|
|
class ScriptDebugger;
|
|
|
|
|
|
|
|
class EngineDebugger {
|
|
|
|
public:
|
|
|
|
typedef void (*ProfilingToggle)(void *p_user, bool p_enable, const Array &p_opts);
|
2021-02-02 02:16:37 +00:00
|
|
|
typedef void (*ProfilingTick)(void *p_user, double p_frame_time, double p_process_time, double p_physics_time, double p_physics_frame_time);
|
2020-02-27 02:30:20 +00:00
|
|
|
typedef void (*ProfilingAdd)(void *p_user, const Array &p_arr);
|
2020-03-11 10:23:21 +00:00
|
|
|
|
2020-02-27 02:30:20 +00:00
|
|
|
typedef Error (*CaptureFunc)(void *p_user, const String &p_msg, const Array &p_args, bool &r_captured);
|
|
|
|
|
2020-03-11 10:23:21 +00:00
|
|
|
typedef RemoteDebuggerPeer *(*CreatePeerFunc)(const String &p_uri);
|
|
|
|
|
2020-02-27 02:30:20 +00:00
|
|
|
class Profiler {
|
|
|
|
friend class EngineDebugger;
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
ProfilingToggle toggle = nullptr;
|
|
|
|
ProfilingAdd add = nullptr;
|
|
|
|
ProfilingTick tick = nullptr;
|
|
|
|
void *data = nullptr;
|
2020-02-27 02:30:20 +00:00
|
|
|
bool active = false;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Profiler() {}
|
|
|
|
Profiler(void *p_data, ProfilingToggle p_toggle, ProfilingAdd p_add, ProfilingTick p_tick) {
|
|
|
|
data = p_data;
|
|
|
|
toggle = p_toggle;
|
|
|
|
add = p_add;
|
|
|
|
tick = p_tick;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Capture {
|
|
|
|
friend class EngineDebugger;
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
CaptureFunc capture = nullptr;
|
|
|
|
void *data = nullptr;
|
2020-02-27 02:30:20 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
Capture() {}
|
|
|
|
Capture(void *p_data, CaptureFunc p_capture) {
|
|
|
|
data = p_data;
|
|
|
|
capture = p_capture;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2021-02-02 02:16:37 +00:00
|
|
|
double frame_time = 0.0;
|
|
|
|
double process_time = 0.0;
|
|
|
|
double physics_time = 0.0;
|
|
|
|
double physics_frame_time = 0.0;
|
2020-02-27 02:30:20 +00:00
|
|
|
|
|
|
|
uint32_t poll_every = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static EngineDebugger *singleton;
|
|
|
|
static ScriptDebugger *script_debugger;
|
|
|
|
|
|
|
|
static Map<StringName, Profiler> profilers;
|
|
|
|
static Map<StringName, Capture> captures;
|
2020-03-11 10:23:21 +00:00
|
|
|
static Map<String, CreatePeerFunc> protocols;
|
2020-02-27 02:30:20 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
_FORCE_INLINE_ static EngineDebugger *get_singleton() { return singleton; }
|
2020-04-01 23:20:12 +00:00
|
|
|
_FORCE_INLINE_ static bool is_active() { return singleton != nullptr && script_debugger != nullptr; }
|
2020-02-27 02:30:20 +00:00
|
|
|
|
|
|
|
_FORCE_INLINE_ static ScriptDebugger *get_script_debugger() { return script_debugger; };
|
|
|
|
|
|
|
|
static void initialize(const String &p_uri, bool p_skip_breakpoints, Vector<String> p_breakpoints);
|
|
|
|
static void deinitialize();
|
|
|
|
static void register_profiler(const StringName &p_name, const Profiler &p_profiler);
|
|
|
|
static void unregister_profiler(const StringName &p_name);
|
|
|
|
static bool is_profiling(const StringName &p_name);
|
|
|
|
static bool has_profiler(const StringName &p_name);
|
|
|
|
static void profiler_add_frame_data(const StringName &p_name, const Array &p_data);
|
|
|
|
|
|
|
|
static void register_message_capture(const StringName &p_name, Capture p_func);
|
|
|
|
static void unregister_message_capture(const StringName &p_name);
|
|
|
|
static bool has_capture(const StringName &p_name);
|
|
|
|
|
2020-03-11 10:23:21 +00:00
|
|
|
static void register_uri_handler(const String &p_protocol, CreatePeerFunc p_func);
|
|
|
|
|
2021-02-02 02:16:37 +00:00
|
|
|
void iteration(uint64_t p_frame_ticks, uint64_t p_process_ticks, uint64_t p_physics_ticks, double p_physics_frame_time);
|
2020-02-27 02:30:20 +00:00
|
|
|
void profiler_enable(const StringName &p_name, bool p_enabled, const Array &p_opts = Array());
|
|
|
|
Error capture_parse(const StringName &p_name, const String &p_msg, const Array &p_args, bool &r_captured);
|
|
|
|
|
|
|
|
void line_poll();
|
|
|
|
|
|
|
|
virtual void poll_events(bool p_is_idle) {}
|
|
|
|
virtual void send_message(const String &p_msg, const Array &p_data) = 0;
|
2021-09-22 15:36:40 +00:00
|
|
|
virtual 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) = 0;
|
2020-02-27 02:30:20 +00:00
|
|
|
virtual void debug(bool p_can_continue = true, bool p_is_error_breakpoint = false) = 0;
|
|
|
|
|
|
|
|
virtual ~EngineDebugger();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ENGINE_DEBUGGER_H
|