Path: blob/master/editor/debugger/debug_adapter/debug_adapter_protocol.h
9906 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/io/stream_peer_tcp.h"34#include "core/io/tcp_server.h"3536#include "debug_adapter_parser.h"37#include "debug_adapter_types.h"38#include "scene/debugger/scene_debugger.h"3940#define DAP_MAX_BUFFER_SIZE 4194304 // 4MB41#define DAP_MAX_CLIENTS 84243class DebugAdapterParser;4445struct DAPeer : RefCounted {46Ref<StreamPeerTCP> connection;4748uint8_t req_buf[DAP_MAX_BUFFER_SIZE];49int req_pos = 0;50bool has_header = false;51int content_length = 0;52List<Dictionary> res_queue;53int seq = 0;54uint64_t timestamp = 0;5556// Client specific info57bool linesStartAt1 = false;58bool columnsStartAt1 = false;59bool supportsVariableType = false;60bool supportsInvalidatedEvent = false;61bool supportsCustomData = false;6263// Internal client info64bool attached = false;65Dictionary pending_launch;6667Error handle_data();68Error send_data();69Vector<uint8_t> format_output(const Dictionary &p_params) const;70};7172class DebugAdapterProtocol : public Object {73GDCLASS(DebugAdapterProtocol, Object)7475friend class DebugAdapterParser;7677using DAPVarID = int;78using DAPStackFrameID = int;7980private:81static DebugAdapterProtocol *singleton;82DebugAdapterParser *parser = nullptr;8384List<Ref<DAPeer>> clients;85Ref<TCPServer> server;8687Error on_client_connected();88void on_client_disconnected(const Ref<DAPeer> &p_peer);89void on_debug_paused();90void on_debug_stopped();91void on_debug_output(const String &p_message, int p_type);92void on_debug_breaked(const bool &p_reallydid, const bool &p_can_debug, const String &p_reason, const bool &p_has_stackdump);93void on_debug_breakpoint_toggled(const String &p_path, const int &p_line, const bool &p_enabled);94void on_debug_stack_dump(const Array &p_stack_dump);95void on_debug_stack_frame_vars(const int &p_size);96void on_debug_stack_frame_var(const Array &p_data);97void on_debug_data(const String &p_msg, const Array &p_data);9899void reset_current_info();100void reset_ids();101void reset_stack_info();102103int parse_variant(const Variant &p_var);104void parse_object(SceneDebuggerObject &p_obj);105const Variant parse_object_variable(const SceneDebuggerObject::SceneDebuggerProperty &p_property);106void parse_evaluation(DebuggerMarshalls::ScriptStackVariable &p_var);107108ObjectID search_object_id(DAPVarID p_var_id);109bool request_remote_object(const ObjectID &p_object_id);110bool request_remote_evaluate(const String &p_eval, int p_stack_frame);111112const DAP::Source &fetch_source(const String &p_path);113void update_source(const String &p_path);114115bool _initialized = false;116bool _processing_breakpoint = false;117bool _stepping = false;118bool _processing_stackdump = false;119int _remaining_vars = 0;120int _current_frame = 0;121uint64_t _request_timeout = 5000;122bool _sync_breakpoints = false;123124String _current_request;125Ref<DAPeer> _current_peer;126127int breakpoint_id = 0;128int stackframe_id = 0;129DAPVarID variable_id = 0;130List<DAP::Breakpoint> breakpoint_list;131HashMap<String, DAP::Source> breakpoint_source_list;132List<DAP::StackFrame> stackframe_list;133HashMap<DAPStackFrameID, Vector<int>> scope_list;134HashMap<DAPVarID, Array> variable_list;135136HashMap<ObjectID, DAPVarID> object_list;137HashSet<ObjectID> object_pending_set;138139HashMap<String, DAP::Variable> eval_list;140HashSet<String> eval_pending_list;141142public:143friend class DebugAdapterServer;144145_FORCE_INLINE_ static DebugAdapterProtocol *get_singleton() { return singleton; }146_FORCE_INLINE_ bool is_active() const { return _initialized && clients.size() > 0; }147148bool process_message(const String &p_text);149150String get_current_request() const { return _current_request; }151Ref<DAPeer> get_current_peer() const { return _current_peer; }152153void notify_initialized();154void notify_process();155void notify_terminated();156void notify_exited(const int &p_exitcode = 0);157void notify_stopped_paused();158void notify_stopped_exception(const String &p_error);159void notify_stopped_breakpoint(const int &p_id);160void notify_stopped_step();161void notify_continued();162void notify_output(const String &p_message, RemoteDebugger::MessageType p_type);163void notify_custom_data(const String &p_msg, const Array &p_data);164void notify_breakpoint(const DAP::Breakpoint &p_breakpoint, const bool &p_enabled);165166Array update_breakpoints(const String &p_path, const Array &p_lines);167168void poll();169Error start(int p_port, const IPAddress &p_bind_ip);170void stop();171172DebugAdapterProtocol();173~DebugAdapterProtocol();174};175176177