Path: blob/master/editor/debugger/debug_adapter/debug_adapter_protocol.h
20896 views
/**************************************************************************/1/* debug_adapter_protocol.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/debugger/debugger_marshalls.h"33#include "core/debugger/remote_debugger.h"34#include "core/io/stream_peer_tcp.h"35#include "core/io/tcp_server.h"36#include "editor/debugger/debug_adapter/debug_adapter_types.h"37#include "scene/debugger/scene_debugger_object.h"3839#define DAP_MAX_BUFFER_SIZE 4194304 // 4MB40#define DAP_MAX_CLIENTS 84142class DebugAdapterParser;4344struct DAPeer : RefCounted {45Ref<StreamPeerTCP> connection;4647uint8_t req_buf[DAP_MAX_BUFFER_SIZE];48int req_pos = 0;49bool has_header = false;50int content_length = 0;51List<Dictionary> res_queue;52int seq = 0;53uint64_t timestamp = 0;5455// Client specific info56bool linesStartAt1 = false;57bool columnsStartAt1 = false;58bool supportsVariableType = false;59bool supportsInvalidatedEvent = false;60bool supportsCustomData = false;6162// Internal client info63bool attached = false;64Dictionary pending_launch;6566Error handle_data();67Error send_data();68Vector<uint8_t> format_output(const Dictionary &p_params) const;69};7071class DebugAdapterProtocol : public Object {72GDCLASS(DebugAdapterProtocol, Object)7374friend class DebugAdapterParser;7576using DAPVarID = int;77using DAPStackFrameID = int;7879private:80static DebugAdapterProtocol *singleton;81DebugAdapterParser *parser = nullptr;8283List<Ref<DAPeer>> clients;84Ref<TCPServer> server;8586Error on_client_connected();87void on_client_disconnected(const Ref<DAPeer> &p_peer);88void on_debug_paused();89void on_debug_stopped();90void on_debug_output(const String &p_message, int p_type);91void on_debug_breaked(const bool &p_reallydid, const bool &p_can_debug, const String &p_reason, const bool &p_has_stackdump);92void on_debug_breakpoint_toggled(const String &p_path, const int &p_line, const bool &p_enabled);93void on_debug_stack_dump(const Array &p_stack_dump);94void on_debug_stack_frame_vars(const int &p_size);95void on_debug_stack_frame_var(const Array &p_data);96void on_debug_data(const String &p_msg, const Array &p_data);9798void reset_current_info();99void reset_ids();100void reset_stack_info();101102int parse_variant(const Variant &p_var);103void parse_object(SceneDebuggerObject &p_obj);104const Variant parse_object_variable(const SceneDebuggerObject::SceneDebuggerProperty &p_property);105void parse_evaluation(DebuggerMarshalls::ScriptStackVariable &p_var);106107ObjectID search_object_id(DAPVarID p_var_id);108bool request_remote_object(const ObjectID &p_object_id);109bool request_remote_evaluate(const String &p_eval, int p_stack_frame);110111const DAP::Source &fetch_source(const String &p_path);112void update_source(const String &p_path);113114bool _initialized = false;115bool _processing_breakpoint = false;116bool _stepping = false;117bool _processing_stackdump = false;118int _remaining_vars = 0;119int _current_frame = 0;120uint64_t _request_timeout = 5000;121bool _sync_breakpoints = false;122123String _current_request;124Ref<DAPeer> _current_peer;125126int breakpoint_id = 0;127int stackframe_id = 0;128DAPVarID variable_id = 0;129List<DAP::Breakpoint> breakpoint_list;130HashMap<String, DAP::Source> breakpoint_source_list;131List<DAP::StackFrame> stackframe_list;132HashMap<DAPStackFrameID, Vector<int>> scope_list;133HashMap<DAPVarID, Array> variable_list;134135HashMap<ObjectID, DAPVarID> object_list;136HashSet<ObjectID> object_pending_set;137138HashMap<String, DAP::Variable> eval_list;139HashSet<String> eval_pending_list;140141public:142friend class DebugAdapterServer;143144_FORCE_INLINE_ static DebugAdapterProtocol *get_singleton() { return singleton; }145_FORCE_INLINE_ bool is_active() const { return _initialized && clients.size() > 0; }146147bool process_message(const String &p_text);148149String get_current_request() const { return _current_request; }150Ref<DAPeer> get_current_peer() const { return _current_peer; }151152void notify_initialized();153void notify_process();154void notify_terminated();155void notify_exited(const int &p_exitcode = 0);156void notify_stopped_paused();157void notify_stopped_exception(const String &p_error);158void notify_stopped_breakpoint(const int &p_id);159void notify_stopped_step();160void notify_continued();161void notify_output(const String &p_message, RemoteDebugger::MessageType p_type);162void notify_custom_data(const String &p_msg, const Array &p_data);163void notify_breakpoint(const DAP::Breakpoint &p_breakpoint, const bool &p_enabled);164165Array update_breakpoints(const String &p_path, const Array &p_lines);166167void poll();168Error start(int p_port, const IPAddress &p_bind_ip);169void stop();170171DebugAdapterProtocol();172~DebugAdapterProtocol();173};174175176