Path: blob/master/editor/debugger/editor_debugger_node.h
9903 views
/**************************************************************************/1/* editor_debugger_node.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "core/object/script_language.h"33#include "editor/debugger/editor_debugger_server.h"34#include "scene/gui/margin_container.h"3536class Button;37class DebugAdapterParser;38class EditorDebuggerPlugin;39class EditorDebuggerTree;40class EditorDebuggerRemoteObjects;41class MenuButton;42class ScriptEditorDebugger;43class TabContainer;44class UndoRedo;4546class EditorDebuggerNode : public MarginContainer {47GDCLASS(EditorDebuggerNode, MarginContainer);4849public:50enum CameraOverride {51OVERRIDE_NONE,52OVERRIDE_INGAME,53OVERRIDE_EDITORS,54};5556private:57enum Options {58DEBUG_NEXT,59DEBUG_STEP,60DEBUG_BREAK,61DEBUG_CONTINUE,62DEBUG_WITH_EXTERNAL_EDITOR,63};6465class Breakpoint {66public:67String source;68int line = 0;6970static uint32_t hash(const Breakpoint &p_val) {71uint32_t h = HashMapHasherDefault::hash(p_val.source);72return hash_murmur3_one_32(p_val.line, h);73}74bool operator==(const Breakpoint &p_b) const {75return (line == p_b.line && source == p_b.source);76}7778bool operator<(const Breakpoint &p_b) const {79if (line == p_b.line) {80return source < p_b.source;81}82return line < p_b.line;83}8485Breakpoint() {}8687Breakpoint(const String &p_source, int p_line) {88line = p_line;89source = p_source;90}91};9293Ref<EditorDebuggerServer> server;94TabContainer *tabs = nullptr;95Button *debugger_button = nullptr;96MenuButton *script_menu = nullptr;9798Ref<Script> stack_script; // Why?!?99100bool initializing = true;101int last_error_count = 0;102int last_warning_count = 0;103104bool inspect_edited_object_wait = false;105float inspect_edited_object_timeout = 0;106EditorDebuggerTree *remote_scene_tree = nullptr;107bool remote_scene_tree_wait = false;108float remote_scene_tree_timeout = 0.0;109bool remote_scene_tree_clear_msg = true;110bool auto_switch_remote_scene_tree = false;111bool debug_with_external_editor = false;112bool keep_open = false;113String current_uri;114115bool debug_mute_audio = false;116117CameraOverride camera_override = OVERRIDE_NONE;118HashMap<Breakpoint, bool, Breakpoint> breakpoints;119120HashSet<Ref<EditorDebuggerPlugin>> debugger_plugins;121122ScriptEditorDebugger *_add_debugger();123void _update_errors();124125friend class DebuggerEditorPlugin;126friend class DebugAdapterParser;127static EditorDebuggerNode *singleton;128EditorDebuggerNode();129130protected:131void _debugger_stopped(int p_id);132void _debugger_wants_stop(int p_id);133void _debugger_changed(int p_tab);134void _debug_data(const String &p_msg, const Array &p_data, int p_debugger);135void _remote_tree_select_requested(const TypedArray<int64_t> &p_ids, int p_debugger);136void _remote_tree_clear_selection_requested(int p_debugger);137void _remote_tree_updated(int p_debugger);138void _remote_tree_button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button);139void _remote_objects_updated(EditorDebuggerRemoteObjects *p_objs, int p_debugger);140void _remote_object_property_updated(ObjectID p_id, const String &p_property, int p_debugger);141void _remote_objects_requested(const TypedArray<uint64_t> &p_ids, int p_debugger);142void _remote_selection_cleared(int p_debugger);143void _save_node_requested(ObjectID p_id, const String &p_file, int p_debugger);144145void _breakpoint_set_in_tree(Ref<RefCounted> p_script, int p_line, bool p_enabled, int p_debugger);146void _breakpoints_cleared_in_tree(int p_debugger);147148void _clear_execution(Ref<RefCounted> p_script) {149emit_signal(SNAME("clear_execution"), p_script);150}151152void _text_editor_stack_goto(const ScriptEditorDebugger *p_debugger);153void _text_editor_stack_clear(const ScriptEditorDebugger *p_debugger);154void _stack_frame_selected(int p_debugger);155void _error_selected(const String &p_file, int p_line, int p_debugger);156void _breaked(bool p_breaked, bool p_can_debug, const String &p_message, bool p_has_stackdump, int p_debugger);157void _paused();158void _break_state_changed();159void _menu_option(int p_id);160void _update_debug_options();161162protected:163void _notification(int p_what);164static void _bind_methods();165166public:167static EditorDebuggerNode *get_singleton() { return singleton; }168void register_undo_redo(UndoRedo *p_undo_redo);169170ScriptEditorDebugger *get_previous_debugger() const;171ScriptEditorDebugger *get_current_debugger() const;172ScriptEditorDebugger *get_default_debugger() const;173ScriptEditorDebugger *get_debugger(int p_debugger) const;174175void debug_next();176void debug_step();177void debug_break();178void debug_continue();179180void set_script_debug_button(MenuButton *p_button);181182void set_tool_button(Button *p_button) {183debugger_button = p_button;184}185186String get_var_value(const String &p_var) const;187Ref<Script> get_dump_stack_script() const { return stack_script; } // Why do we need this?188189bool get_debug_with_external_editor() { return debug_with_external_editor; }190191bool is_skip_breakpoints() const;192bool is_ignore_error_breaks() const;193void set_breakpoint(const String &p_path, int p_line, bool p_enabled);194void set_breakpoints(const String &p_path, const Array &p_lines);195void reload_all_scripts();196void reload_scripts(const Vector<String> &p_script_paths);197198// Remote inspector/edit.199void request_remote_tree();200void set_remote_selection(const TypedArray<int64_t> &p_ids);201void clear_remote_tree_selection();202void stop_waiting_inspection();203bool match_remote_selection(const TypedArray<uint64_t> &p_ids) const;204static void _methods_changed(void *p_ud, Object *p_base, const StringName &p_name, const Variant **p_args, int p_argcount);205static void _properties_changed(void *p_ud, Object *p_base, const StringName &p_property, const Variant &p_value);206207// LiveDebug208void set_live_debugging(bool p_enabled);209void update_live_edit_root();210void live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name);211void live_debug_instantiate_node(const NodePath &p_parent, const String &p_path, const String &p_name);212void live_debug_remove_node(const NodePath &p_at);213void live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id);214void live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos);215void live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name);216void live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos);217218void set_debug_mute_audio(bool p_mute);219bool get_debug_mute_audio() const;220221void set_camera_override(CameraOverride p_override);222CameraOverride get_camera_override();223224String get_server_uri() const;225226void set_keep_open(bool p_keep_open);227Error start(const String &p_uri = "tcp://");228void stop(bool p_force = false);229230bool plugins_capture(ScriptEditorDebugger *p_debugger, const String &p_message, const Array &p_data);231void add_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin);232void remove_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin);233};234235236