Path: blob/master/editor/debugger/editor_debugger_node.h
20898 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 "editor/docks/editor_dock.h"3536class Button;37class DebugAdapterParser;38class EditorDebuggerPlugin;39class EditorDebuggerTree;40class EditorDebuggerRemoteObjects;41class MenuButton;42class ScriptEditorDebugger;43class TabContainer;44class UndoRedo;4546class EditorDebuggerNode : public EditorDock {47GDCLASS(EditorDebuggerNode, EditorDock);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;95MenuButton *script_menu = nullptr;9697Ref<Script> stack_script; // Why?!?9899bool initializing = true;100int last_error_count = 0;101int last_warning_count = 0;102103bool inspect_edited_object_wait = false;104float inspect_edited_object_timeout = 0;105EditorDebuggerTree *remote_scene_tree = nullptr;106bool remote_scene_tree_wait = false;107float remote_scene_tree_timeout = 0.0;108bool remote_scene_tree_clear_msg = true;109bool auto_switch_remote_scene_tree = false;110bool debug_with_external_editor = false;111bool keep_open = false;112String current_uri;113114bool debug_mute_audio = false;115116CameraOverride camera_override = OVERRIDE_NONE;117HashMap<Breakpoint, bool, Breakpoint> breakpoints;118119HashSet<Ref<EditorDebuggerPlugin>> debugger_plugins;120121ScriptEditorDebugger *_add_debugger();122void _update_errors();123void _update_margins();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);181182String get_var_value(const String &p_var) const;183Ref<Script> get_dump_stack_script() const { return stack_script; } // Why do we need this?184185bool get_debug_with_external_editor() { return debug_with_external_editor; }186187bool is_skip_breakpoints() const;188bool is_ignore_error_breaks() const;189void set_breakpoint(const String &p_path, int p_line, bool p_enabled);190void set_breakpoints(const String &p_path, const Array &p_lines);191void reload_all_scripts();192void reload_scripts(const Vector<String> &p_script_paths);193194// Remote inspector/edit.195void request_remote_tree();196void set_remote_selection(const TypedArray<int64_t> &p_ids);197void clear_remote_tree_selection();198void stop_waiting_inspection();199bool match_remote_selection(const TypedArray<uint64_t> &p_ids) const;200static void _methods_changed(void *p_ud, Object *p_base, const StringName &p_name, const Variant **p_args, int p_argcount);201static void _properties_changed(void *p_ud, Object *p_base, const StringName &p_property, const Variant &p_value);202203// LiveDebug204void set_live_debugging(bool p_enabled);205void update_live_edit_root();206void live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name);207void live_debug_instantiate_node(const NodePath &p_parent, const String &p_path, const String &p_name);208void live_debug_remove_node(const NodePath &p_at);209void live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id);210void live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos);211void live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name);212void live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos);213214void set_debug_mute_audio(bool p_mute);215bool get_debug_mute_audio() const;216217void set_camera_override(CameraOverride p_override);218CameraOverride get_camera_override();219220String get_server_uri() const;221222void set_keep_open(bool p_keep_open);223Error start(const String &p_uri = "tcp://");224void stop(bool p_force = false);225226bool plugins_capture(ScriptEditorDebugger *p_debugger, const String &p_message, const Array &p_data);227void add_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin);228void remove_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin);229};230231232