2021-06-04 20:39:38 +02:00
|
|
|
/**************************************************************************/
|
|
|
|
/* debug_adapter_protocol.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* 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 DEBUG_ADAPTER_PROTOCOL_H
|
|
|
|
#define DEBUG_ADAPTER_PROTOCOL_H
|
|
|
|
|
2024-09-30 15:15:09 +02:00
|
|
|
#include "core/debugger/debugger_marshalls.h"
|
2021-06-04 20:39:38 +02:00
|
|
|
#include "core/io/stream_peer_tcp.h"
|
|
|
|
#include "core/io/tcp_server.h"
|
|
|
|
|
|
|
|
#include "debug_adapter_parser.h"
|
|
|
|
#include "debug_adapter_types.h"
|
2024-09-24 22:33:29 +02:00
|
|
|
#include "scene/debugger/scene_debugger.h"
|
2021-06-04 20:39:38 +02:00
|
|
|
|
|
|
|
#define DAP_MAX_BUFFER_SIZE 4194304 // 4MB
|
|
|
|
#define DAP_MAX_CLIENTS 8
|
|
|
|
|
|
|
|
class DebugAdapterParser;
|
|
|
|
|
|
|
|
struct DAPeer : RefCounted {
|
|
|
|
Ref<StreamPeerTCP> connection;
|
|
|
|
|
|
|
|
uint8_t req_buf[DAP_MAX_BUFFER_SIZE];
|
|
|
|
int req_pos = 0;
|
|
|
|
bool has_header = false;
|
|
|
|
int content_length = 0;
|
|
|
|
List<Dictionary> res_queue;
|
|
|
|
int seq = 0;
|
2021-07-20 13:24:56 +02:00
|
|
|
uint64_t timestamp = 0;
|
2021-06-04 20:39:38 +02:00
|
|
|
|
|
|
|
// Client specific info
|
|
|
|
bool linesStartAt1 = false;
|
|
|
|
bool columnsStartAt1 = false;
|
|
|
|
bool supportsVariableType = false;
|
|
|
|
bool supportsInvalidatedEvent = false;
|
2021-07-20 13:24:56 +02:00
|
|
|
bool supportsCustomData = false;
|
|
|
|
|
|
|
|
// Internal client info
|
|
|
|
bool attached = false;
|
2023-11-14 16:08:36 +01:00
|
|
|
Dictionary pending_launch;
|
2021-06-04 20:39:38 +02:00
|
|
|
|
|
|
|
Error handle_data();
|
|
|
|
Error send_data();
|
|
|
|
String format_output(const Dictionary &p_params) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DebugAdapterProtocol : public Object {
|
|
|
|
GDCLASS(DebugAdapterProtocol, Object)
|
|
|
|
|
|
|
|
friend class DebugAdapterParser;
|
|
|
|
|
2024-09-24 22:33:29 +02:00
|
|
|
using DAPVarID = int;
|
|
|
|
|
2021-06-04 20:39:38 +02:00
|
|
|
private:
|
|
|
|
static DebugAdapterProtocol *singleton;
|
2022-04-04 15:06:57 +02:00
|
|
|
DebugAdapterParser *parser = nullptr;
|
2021-06-04 20:39:38 +02:00
|
|
|
|
|
|
|
List<Ref<DAPeer>> clients;
|
|
|
|
Ref<TCPServer> server;
|
|
|
|
|
|
|
|
Error on_client_connected();
|
|
|
|
void on_client_disconnected(const Ref<DAPeer> &p_peer);
|
|
|
|
void on_debug_paused();
|
|
|
|
void on_debug_stopped();
|
2024-03-14 11:53:30 +01:00
|
|
|
void on_debug_output(const String &p_message, int p_type);
|
2021-06-04 20:39:38 +02:00
|
|
|
void on_debug_breaked(const bool &p_reallydid, const bool &p_can_debug, const String &p_reason, const bool &p_has_stackdump);
|
2021-07-20 13:24:56 +02:00
|
|
|
void on_debug_breakpoint_toggled(const String &p_path, const int &p_line, const bool &p_enabled);
|
2021-06-04 20:39:38 +02:00
|
|
|
void on_debug_stack_dump(const Array &p_stack_dump);
|
|
|
|
void on_debug_stack_frame_vars(const int &p_size);
|
|
|
|
void on_debug_stack_frame_var(const Array &p_data);
|
2021-07-20 13:24:56 +02:00
|
|
|
void on_debug_data(const String &p_msg, const Array &p_data);
|
2021-06-04 20:39:38 +02:00
|
|
|
|
|
|
|
void reset_current_info();
|
|
|
|
void reset_ids();
|
|
|
|
void reset_stack_info();
|
|
|
|
|
2021-07-20 13:24:56 +02:00
|
|
|
int parse_variant(const Variant &p_var);
|
2024-09-24 22:33:29 +02:00
|
|
|
void parse_object(SceneDebuggerObject &p_obj);
|
|
|
|
const Variant parse_object_variable(const SceneDebuggerObject::SceneDebuggerProperty &p_property);
|
2024-09-30 15:15:09 +02:00
|
|
|
void parse_evaluation(DebuggerMarshalls::ScriptStackVariable &p_var);
|
2024-09-24 22:33:29 +02:00
|
|
|
|
|
|
|
ObjectID search_object_id(DAPVarID p_var_id);
|
|
|
|
bool request_remote_object(const ObjectID &p_object_id);
|
2024-09-30 15:15:09 +02:00
|
|
|
bool request_remote_evaluate(const String &p_eval, int p_stack_frame);
|
2021-07-20 13:24:56 +02:00
|
|
|
|
2021-06-04 20:39:38 +02:00
|
|
|
bool _initialized = false;
|
|
|
|
bool _processing_breakpoint = false;
|
|
|
|
bool _stepping = false;
|
|
|
|
bool _processing_stackdump = false;
|
|
|
|
int _remaining_vars = 0;
|
|
|
|
int _current_frame = 0;
|
2024-10-03 22:28:25 +02:00
|
|
|
uint64_t _request_timeout = 5000;
|
2021-07-20 13:24:56 +02:00
|
|
|
bool _sync_breakpoints = false;
|
2021-06-04 20:39:38 +02:00
|
|
|
|
|
|
|
String _current_request;
|
|
|
|
Ref<DAPeer> _current_peer;
|
|
|
|
|
2022-05-02 16:28:25 +02:00
|
|
|
int breakpoint_id = 0;
|
|
|
|
int stackframe_id = 0;
|
2024-09-24 22:33:29 +02:00
|
|
|
DAPVarID variable_id = 0;
|
2021-06-04 20:39:38 +02:00
|
|
|
List<DAP::Breakpoint> breakpoint_list;
|
2022-05-13 15:04:37 +02:00
|
|
|
HashMap<DAP::StackFrame, List<int>, DAP::StackFrame> stackframe_list;
|
2024-09-24 22:33:29 +02:00
|
|
|
HashMap<DAPVarID, Array> variable_list;
|
|
|
|
|
|
|
|
HashMap<ObjectID, DAPVarID> object_list;
|
|
|
|
HashSet<ObjectID> object_pending_set;
|
2021-06-04 20:39:38 +02:00
|
|
|
|
2024-09-30 15:15:09 +02:00
|
|
|
HashMap<String, DAP::Variable> eval_list;
|
|
|
|
HashSet<String> eval_pending_list;
|
|
|
|
|
2021-06-04 20:39:38 +02:00
|
|
|
public:
|
2021-07-20 13:24:56 +02:00
|
|
|
friend class DebugAdapterServer;
|
|
|
|
|
2021-06-04 20:39:38 +02:00
|
|
|
_FORCE_INLINE_ static DebugAdapterProtocol *get_singleton() { return singleton; }
|
|
|
|
_FORCE_INLINE_ bool is_active() const { return _initialized && clients.size() > 0; }
|
|
|
|
|
|
|
|
bool process_message(const String &p_text);
|
|
|
|
|
|
|
|
String get_current_request() const { return _current_request; }
|
|
|
|
Ref<DAPeer> get_current_peer() const { return _current_peer; }
|
|
|
|
|
|
|
|
void notify_initialized();
|
|
|
|
void notify_process();
|
|
|
|
void notify_terminated();
|
|
|
|
void notify_exited(const int &p_exitcode = 0);
|
|
|
|
void notify_stopped_paused();
|
|
|
|
void notify_stopped_exception(const String &p_error);
|
|
|
|
void notify_stopped_breakpoint(const int &p_id);
|
|
|
|
void notify_stopped_step();
|
|
|
|
void notify_continued();
|
2024-03-14 11:53:30 +01:00
|
|
|
void notify_output(const String &p_message, RemoteDebugger::MessageType p_type);
|
2021-07-20 13:24:56 +02:00
|
|
|
void notify_custom_data(const String &p_msg, const Array &p_data);
|
|
|
|
void notify_breakpoint(const DAP::Breakpoint &p_breakpoint, const bool &p_enabled);
|
2021-06-04 20:39:38 +02:00
|
|
|
|
2021-07-20 13:24:56 +02:00
|
|
|
Array update_breakpoints(const String &p_path, const Array &p_lines);
|
2021-06-04 20:39:38 +02:00
|
|
|
|
|
|
|
void poll();
|
|
|
|
Error start(int p_port, const IPAddress &p_bind_ip);
|
|
|
|
void stop();
|
|
|
|
|
|
|
|
DebugAdapterProtocol();
|
|
|
|
~DebugAdapterProtocol();
|
|
|
|
};
|
|
|
|
|
2022-07-23 23:41:51 +02:00
|
|
|
#endif // DEBUG_ADAPTER_PROTOCOL_H
|