cppdap 2024-08-02 (c69444ed)

Code extracted from:

    https://github.com/google/cppdap.git

at commit c69444ed76f7468b232ac4f989cb8f2bdc100185 (c69444ed76f7468b232ac4f989cb8f2bdc100185).
This commit is contained in:
cppdap Upstream 2024-08-02 11:38:40 -04:00 committed by Brad King
parent 5d568df6b1
commit bcfd096ed9
9 changed files with 170 additions and 46 deletions

View File

@ -17,6 +17,7 @@
#include <functional>
#include <memory>
#include <stdint.h>
namespace dap {
class ReaderWriter;
@ -44,13 +45,21 @@ class Server {
// create() constructs and returns a new Server.
static std::unique_ptr<Server> create();
// start() begins listening for connections on the given port.
// start() begins listening for connections on localhost and the given port.
// callback will be called for each connection.
// onError will be called for any connection errors.
virtual bool start(int port,
const OnConnect& callback,
const OnError& onError = ignoreErrors) = 0;
// start() begins listening for connections on the given specific address and port.
// callback will be called for each connection.
// onError will be called for any connection errors.
virtual bool start(const char* address,
int port,
const OnConnect& callback,
const OnError& onError = ignoreErrors) = 0;
// stop() stops listening for connections.
// stop() is implicitly called on destruction.
virtual void stop() = 0;

View File

@ -15,7 +15,7 @@
// Generated with protocol_gen.go -- do not edit this file.
// go run scripts/protocol_gen/protocol_gen.go
//
// DAP version 1.59.0
// DAP version 1.65.0
#ifndef dap_protocol_h
#define dap_protocol_h
@ -141,6 +141,18 @@ struct Breakpoint {
// The offset from the instruction reference.
// This can be negative.
optional<integer> offset;
// A machine-readable explanation of why a breakpoint may not be verified. If
// a breakpoint is verified or a specific reason is not known, the adapter
// should omit this property. Possible values include:
//
// - `pending`: Indicates a breakpoint might be verified in the future, but
// the adapter cannot verify it in the current state.
// - `failed`: Indicates a breakpoint was not able to be verified, and the
// adapter does not believe it can be verified without intervention.
//
// Must be one of the following enumeration values:
// 'pending', 'failed'
optional<string> reason;
// The source where the breakpoint is located.
optional<Source> source;
// If true, the breakpoint could be set (but not necessarily at the desired
@ -214,7 +226,7 @@ struct BreakpointLocationsRequest : public Request {
// line is specified, the request returns all possible locations in that line.
integer line;
// The source location of the breakpoints; either `source.path` or
// `source.reference` must be specified.
// `source.sourceReference` must be specified.
Source source;
};
@ -229,18 +241,19 @@ DAP_DECLARE_STRUCT_TYPEINFO(CancelResponse);
// The `cancel` request is used by the client in two situations:
// - to indicate that it is no longer interested in the result produced by a
// specific request issued earlier
// - to cancel a progress sequence. Clients should only call this request if the
// corresponding capability `supportsCancelRequest` is true. This request has a
// hint characteristic: a debug adapter can only be expected to make a 'best
// effort' in honoring this request but there are no guarantees. The `cancel`
// request may return an error if it could not cancel an operation but a client
// should refrain from presenting this error to end users. The request that got
// cancelled still needs to send a response back. This can either be a normal
// result (`success` attribute true) or an error response (`success` attribute
// false and the `message` set to `cancelled`). Returning partial results from a
// cancelled request is possible but please note that a client has no generic
// way for detecting that a response is partial or not. The progress that got
// cancelled still needs to send a `progressEnd` event back.
// - to cancel a progress sequence.
// Clients should only call this request if the corresponding capability
// `supportsCancelRequest` is true. This request has a hint characteristic: a
// debug adapter can only be expected to make a 'best effort' in honoring this
// request but there are no guarantees. The `cancel` request may return an error
// if it could not cancel an operation but a client should refrain from
// presenting this error to end users. The request that got cancelled still
// needs to send a response back. This can either be a normal result (`success`
// attribute true) or an error response (`success` attribute false and the
// `message` set to `cancelled`). Returning partial results from a cancelled
// request is possible but please note that a client has no generic way for
// detecting that a response is partial or not. The progress that got cancelled
// still needs to send a `progressEnd` event back.
// A client should not assume that progress just got cancelled after sending
// the `cancel` request.
struct CancelRequest : public Request {
@ -280,6 +293,28 @@ struct ColumnDescriptor {
DAP_DECLARE_STRUCT_TYPEINFO(ColumnDescriptor);
// Describes one or more type of breakpoint a `BreakpointMode` applies to. This
// is a non-exhaustive enumeration and may expand as future breakpoint types are
// added.
using BreakpointModeApplicability = string;
// A `BreakpointMode` is provided as a option when setting breakpoints on
// sources or instructions.
struct BreakpointMode {
// Describes one or more type of breakpoint this mode applies to.
array<BreakpointModeApplicability> appliesTo;
// A help text providing additional information about the breakpoint mode.
// This string is typically shown as a hover and can be translated.
optional<string> description;
// The name of the breakpoint mode. This is shown in the UI.
string label;
// The internal ID of the mode. This value is passed to the `setBreakpoints`
// request.
string mode;
};
DAP_DECLARE_STRUCT_TYPEINFO(BreakpointMode);
// An `ExceptionBreakpointsFilter` is shown in the UI as an filter option for
// configuring how exceptions are dealt with.
struct ExceptionBreakpointsFilter {
@ -308,6 +343,13 @@ DAP_DECLARE_STRUCT_TYPEINFO(ExceptionBreakpointsFilter);
struct Capabilities {
// The set of additional module information exposed by the debug adapter.
optional<array<ColumnDescriptor>> additionalModuleColumns;
// Modes of breakpoints supported by the debug adapter, such as 'hardware' or
// 'software'. If present, the client may allow the user to select a mode and
// include it in its `setBreakpoints` request.
//
// Clients may present the first applicable mode in this array as the
// 'default' mode in gestures that set breakpoints.
optional<array<BreakpointMode>> breakpointModes;
// The set of characters that should trigger completion in a REPL. If not
// specified, the UI should assume the `.` character.
optional<array<string>> completionTriggerCharacters;
@ -579,7 +621,11 @@ struct DataBreakpointInfoResponse : public Response {
optional<boolean> canPersist;
// An identifier for the data on which a data breakpoint can be registered
// with the `setDataBreakpoints` request or null if no data breakpoint is
// available.
// available. If a `variablesReference` or `frameId` is passed, the `dataId`
// is valid in the current suspended state, otherwise it's valid indefinitely.
// See 'Lifetime of Object References' in the Overview section for details.
// Breakpoints set using the `dataId` in the `setDataBreakpoints` request may
// outlive the lifetime of the associated `dataId`.
variant<string, null> dataId;
// UI string that describes on what data the breakpoint is set on or why a
// data breakpoint is not available.
@ -597,6 +643,9 @@ struct DataBreakpointInfoRequest : public Request {
// If not specified, the expression is evaluated in the global scope. When
// `variablesReference` is specified, this property has no effect.
optional<integer> frameId;
// The mode of the desired breakpoint. If defined, this must be one of the
// `breakpointModes` the debug adapter advertised in its `Capabilities`.
optional<string> mode;
// The name of the variable's child to obtain data breakpoint information for.
// If `variablesReference` isn't specified, this can be an expression.
string name;
@ -634,6 +683,15 @@ struct DisassembledInstruction {
// but can be omitted afterwards if this instruction maps to the same source
// file as the previous instruction.
optional<Source> location;
// A hint for how to present the instruction in the UI.
//
// A value of `invalid` may be used to indicate this instruction is 'filler'
// and cannot be reached by the program. For example, unreadable memory
// addresses may be presented is 'invalid.'
//
// Must be one of the following enumeration values:
// 'normal', 'invalid'
optional<string> presentationHint;
// Name of the symbol that corresponds with the location of this instruction,
// if any.
optional<string> symbol;
@ -785,9 +843,8 @@ struct EvaluateResponse : public Response {
optional<integer> indexedVariables;
// A memory reference to a location appropriate for this result.
// For pointer type eval results, this is generally a reference to the memory
// address contained in the pointer. This attribute should be returned by a
// debug adapter if corresponding capability `supportsMemoryReferences` is
// true.
// address contained in the pointer. This attribute may be returned by a debug
// adapter if corresponding capability `supportsMemoryReferences` is true.
optional<string> memoryReference;
// The number of named child variables.
// The client can use this information to present the variables in a paged UI
@ -979,6 +1036,13 @@ DAP_DECLARE_STRUCT_TYPEINFO(GotoTargetsRequest);
struct InitializeResponse : public Response {
// The set of additional module information exposed by the debug adapter.
optional<array<ColumnDescriptor>> additionalModuleColumns;
// Modes of breakpoints supported by the debug adapter, such as 'hardware' or
// 'software'. If present, the client may allow the user to select a mode and
// include it in its `setBreakpoints` request.
//
// Clients may present the first applicable mode in this array as the
// 'default' mode in gestures that set breakpoints.
optional<array<BreakpointMode>> breakpointModes;
// The set of characters that should trigger completion in a REPL. If not
// specified, the UI should assume the `.` character.
optional<array<string>> completionTriggerCharacters;
@ -1774,6 +1838,9 @@ struct SourceBreakpoint {
// `hitCondition` or `condition` is specified, then the message should only be
// logged if those conditions are met.
optional<string> logMessage;
// The mode of this breakpoint. If defined, this must be one of the
// `breakpointModes` the debug adapter advertised in its `Capabilities`.
optional<string> mode;
};
DAP_DECLARE_STRUCT_TYPEINFO(SourceBreakpoint);
@ -1846,13 +1913,13 @@ DAP_DECLARE_STRUCT_TYPEINFO(SetDataBreakpointsRequest);
// the returned array must start with `filters` information first, followed by
// `filterOptions` information. The `verified` property of a `Breakpoint` object
// signals whether the exception breakpoint or filter could be successfully
// created and whether the condition or hit count expressions are valid. In case
// of an error the `message` property explains the problem. The `id` property
// can be used to introduce a unique ID for the exception breakpoint or filter
// so that it can be updated subsequently by sending breakpoint events. For
// backward compatibility both the `breakpoints` array and the enclosing `body`
// are optional. If these elements are missing a client is not able to show
// problems for individual exception breakpoints or filters.
// created and whether the condition is valid. In case of an error the `message`
// property explains the problem. The `id` property can be used to introduce a
// unique ID for the exception breakpoint or filter so that it can be updated
// subsequently by sending breakpoint events. For backward compatibility both
// the `breakpoints` array and the enclosing `body` are optional. If these
// elements are missing a client is not able to show problems for individual
// exception breakpoints or filters.
struct SetExceptionBreakpointsResponse : public Response {
// Information about the exception breakpoints or filters.
// The breakpoints returned are in the same order as the elements of the
@ -1901,15 +1968,20 @@ struct ExceptionFilterOptions {
// ID of an exception filter returned by the `exceptionBreakpointFilters`
// capability.
string filterId;
// The mode of this exception breakpoint. If defined, this must be one of the
// `breakpointModes` the debug adapter advertised in its `Capabilities`.
optional<string> mode;
};
DAP_DECLARE_STRUCT_TYPEINFO(ExceptionFilterOptions);
// The request configures the debugger's response to thrown exceptions.
// If an exception is configured to break, a `stopped` event is fired (with
// reason `exception`). Clients should only call this request if the
// corresponding capability `exceptionBreakpointFilters` returns one or more
// filters.
// The request configures the debugger's response to thrown exceptions. Each of
// the `filters`, `filterOptions`, and `exceptionOptions` in the request are
// independent configurations to a debug adapter indicating a kind of exception
// to catch. An exception thrown in a program should result in a `stopped` event
// from the debug adapter (with reason `exception`) if any of the configured
// filters match. Clients should only call this request if the corresponding
// capability `exceptionBreakpointFilters` returns one or more filters.
struct SetExceptionBreakpointsRequest : public Request {
using Response = SetExceptionBreakpointsResponse;
// Configuration options for selected exceptions.
@ -1937,6 +2009,11 @@ struct SetExpressionResponse : public Response {
// and fetch them in chunks. The value should be less than or equal to
// 2147483647 (2^31-1).
optional<integer> indexedVariables;
// A memory reference to a location appropriate for this result.
// For pointer type eval results, this is generally a reference to the memory
// address contained in the pointer. This attribute may be returned by a debug
// adapter if corresponding capability `supportsMemoryReferences` is true.
optional<string> memoryReference;
// The number of named child variables.
// The client can use this information to present the variables in a paged UI
// and fetch them in chunks. The value should be less than or equal to
@ -2047,7 +2124,10 @@ struct InstructionBreakpoint {
// `EvaluateResponse`, `Variable`, `StackFrame`, `GotoTarget`, or
// `Breakpoint`.
string instructionReference;
// The offset from the instruction reference.
// The mode of this breakpoint. If defined, this must be one of the
// `breakpointModes` the debug adapter advertised in its `Capabilities`.
optional<string> mode;
// The offset from the instruction reference in bytes.
// This can be negative.
optional<integer> offset;
};
@ -2075,6 +2155,11 @@ struct SetVariableResponse : public Response {
// and fetch them in chunks. The value should be less than or equal to
// 2147483647 (2^31-1).
optional<integer> indexedVariables;
// A memory reference to a location appropriate for this result.
// For pointer type eval results, this is generally a reference to the memory
// address contained in the pointer. This attribute may be returned by a debug
// adapter if corresponding capability `supportsMemoryReferences` is true.
optional<string> memoryReference;
// The number of named child variables.
// The client can use this information to present the variables in a paged UI
// and fetch them in chunks. The value should be less than or equal to
@ -2568,9 +2653,12 @@ struct Variable {
// The client can use this information to present the children in a paged UI
// and fetch them in chunks.
optional<integer> indexedVariables;
// The memory reference for the variable if the variable represents executable
// code, such as a function pointer. This attribute is only required if the
// corresponding capability `supportsMemoryReferences` is true.
// A memory reference associated with this variable.
// For pointer type variables, this is generally a reference to the memory
// address contained in the pointer. For executable data, this reference may
// later be used in a `disassemble` request. This attribute may be returned by
// a debug adapter if corresponding capability `supportsMemoryReferences` is
// true.
optional<string> memoryReference;
// The variable's name.
string name;
@ -2616,7 +2704,8 @@ DAP_DECLARE_STRUCT_TYPEINFO(VariablesResponse);
struct VariablesRequest : public Request {
using Response = VariablesResponse;
// The number of variables to return. If count is missing or 0, all variables
// are returned.
// are returned. The attribute is only honored by a debug adapter if the
// corresponding capability `supportsVariablePaging` is true.
optional<integer> count;
// Filter to limit the child variables to either named or indexed. If omitted,
// both types are fetched.
@ -2629,6 +2718,8 @@ struct VariablesRequest : public Request {
// capability `supportsValueFormattingOptions` is true.
optional<ValueFormat> format;
// The index of the first variable to return; if omitted children start at 0.
// The attribute is only honored by a debug adapter if the corresponding
// capability `supportsVariablePaging` is true.
optional<integer> start;
// The variable for which to retrieve its children. The `variablesReference`
// must have been obtained in the current suspended state. See 'Lifetime of

View File

@ -164,7 +164,7 @@ M member_type(M T::*);
bool TypeOf<STRUCT>::deserializeFields(const Deserializer* fd, void* obj) { \
using StructTy = STRUCT; \
(void)sizeof(StructTy); /* avoid unused 'using' warning */ \
for (auto field : std::initializer_list<Field>{__VA_ARGS__}) { \
for (auto& field : std::initializer_list<Field>{__VA_ARGS__}) { \
if (!fd->field(field.name, [&](Deserializer* d) { \
auto ptr = reinterpret_cast<uint8_t*>(obj) + field.offset; \
return field.type->deserialize(d, ptr); \
@ -177,7 +177,7 @@ M member_type(M T::*);
bool TypeOf<STRUCT>::serializeFields(FieldSerializer* fs, const void* obj) {\
using StructTy = STRUCT; \
(void)sizeof(StructTy); /* avoid unused 'using' warning */ \
for (auto field : std::initializer_list<Field>{__VA_ARGS__}) { \
for (auto& field : std::initializer_list<Field>{__VA_ARGS__}) { \
if (!fs->field(field.name, [&](Serializer* s) { \
auto ptr = reinterpret_cast<const uint8_t*>(obj) + field.offset; \
return field.type->serialize(s, ptr); \

View File

@ -32,10 +32,17 @@ class Impl : public dap::net::Server {
bool start(int port,
const OnConnect& onConnect,
const OnError& onError) override {
return start("localhost", port, onConnect, onError);
}
bool start(const char* address,
int port,
const OnConnect& onConnect,
const OnError& onError) override {
std::unique_lock<std::mutex> lock(mutex);
stopWithLock();
socket = std::unique_ptr<dap::Socket>(
new dap::Socket("localhost", std::to_string(port).c_str()));
new dap::Socket(address, std::to_string(port).c_str()));
if (!socket->isOpen()) {
onError("Failed to open socket");

View File

@ -15,7 +15,7 @@
// Generated with protocol_gen.go -- do not edit this file.
// go run scripts/protocol_gen/protocol_gen.go
//
// DAP version 1.59.0
// DAP version 1.65.0
#include "dap/protocol.h"

View File

@ -15,7 +15,7 @@
// Generated with protocol_gen.go -- do not edit this file.
// go run scripts/protocol_gen/protocol_gen.go
//
// DAP version 1.59.0
// DAP version 1.65.0
#include "dap/protocol.h"
@ -55,6 +55,7 @@ DAP_IMPLEMENT_STRUCT_TYPEINFO(ContinueRequest,
DAP_IMPLEMENT_STRUCT_TYPEINFO(DataBreakpointInfoRequest,
"dataBreakpointInfo",
DAP_FIELD(frameId, "frameId"),
DAP_FIELD(mode, "mode"),
DAP_FIELD(name, "name"),
DAP_FIELD(variablesReference,
"variablesReference"));

View File

@ -15,7 +15,7 @@
// Generated with protocol_gen.go -- do not edit this file.
// go run scripts/protocol_gen/protocol_gen.go
//
// DAP version 1.59.0
// DAP version 1.65.0
#include "dap/protocol.h"
@ -83,6 +83,7 @@ DAP_IMPLEMENT_STRUCT_TYPEINFO(
InitializeResponse,
"",
DAP_FIELD(additionalModuleColumns, "additionalModuleColumns"),
DAP_FIELD(breakpointModes, "breakpointModes"),
DAP_FIELD(completionTriggerCharacters, "completionTriggerCharacters"),
DAP_FIELD(exceptionBreakpointFilters, "exceptionBreakpointFilters"),
DAP_FIELD(supportSuspendDebuggee, "supportSuspendDebuggee"),
@ -177,6 +178,7 @@ DAP_IMPLEMENT_STRUCT_TYPEINFO(SetExceptionBreakpointsResponse,
DAP_IMPLEMENT_STRUCT_TYPEINFO(SetExpressionResponse,
"",
DAP_FIELD(indexedVariables, "indexedVariables"),
DAP_FIELD(memoryReference, "memoryReference"),
DAP_FIELD(namedVariables, "namedVariables"),
DAP_FIELD(presentationHint, "presentationHint"),
DAP_FIELD(type, "type"),
@ -195,6 +197,7 @@ DAP_IMPLEMENT_STRUCT_TYPEINFO(SetInstructionBreakpointsResponse,
DAP_IMPLEMENT_STRUCT_TYPEINFO(SetVariableResponse,
"",
DAP_FIELD(indexedVariables, "indexedVariables"),
DAP_FIELD(memoryReference, "memoryReference"),
DAP_FIELD(namedVariables, "namedVariables"),
DAP_FIELD(type, "type"),
DAP_FIELD(value, "value"),

View File

@ -15,7 +15,7 @@
// Generated with protocol_gen.go -- do not edit this file.
// go run scripts/protocol_gen/protocol_gen.go
//
// DAP version 1.59.0
// DAP version 1.65.0
#include "dap/protocol.h"
@ -48,6 +48,7 @@ DAP_IMPLEMENT_STRUCT_TYPEINFO(Breakpoint,
DAP_FIELD(line, "line"),
DAP_FIELD(message, "message"),
DAP_FIELD(offset, "offset"),
DAP_FIELD(reason, "reason"),
DAP_FIELD(source, "source"),
DAP_FIELD(verified, "verified"));
@ -66,6 +67,13 @@ DAP_IMPLEMENT_STRUCT_TYPEINFO(ColumnDescriptor,
DAP_FIELD(type, "type"),
DAP_FIELD(width, "width"));
DAP_IMPLEMENT_STRUCT_TYPEINFO(BreakpointMode,
"",
DAP_FIELD(appliesTo, "appliesTo"),
DAP_FIELD(description, "description"),
DAP_FIELD(label, "label"),
DAP_FIELD(mode, "mode"));
DAP_IMPLEMENT_STRUCT_TYPEINFO(ExceptionBreakpointsFilter,
"",
DAP_FIELD(conditionDescription,
@ -81,6 +89,7 @@ DAP_IMPLEMENT_STRUCT_TYPEINFO(
Capabilities,
"",
DAP_FIELD(additionalModuleColumns, "additionalModuleColumns"),
DAP_FIELD(breakpointModes, "breakpointModes"),
DAP_FIELD(completionTriggerCharacters, "completionTriggerCharacters"),
DAP_FIELD(exceptionBreakpointFilters, "exceptionBreakpointFilters"),
DAP_FIELD(supportSuspendDebuggee, "supportSuspendDebuggee"),
@ -148,6 +157,7 @@ DAP_IMPLEMENT_STRUCT_TYPEINFO(DisassembledInstruction,
DAP_FIELD(instructionBytes, "instructionBytes"),
DAP_FIELD(line, "line"),
DAP_FIELD(location, "location"),
DAP_FIELD(presentationHint, "presentationHint"),
DAP_FIELD(symbol, "symbol"));
DAP_IMPLEMENT_STRUCT_TYPEINFO(Message,
@ -223,7 +233,8 @@ DAP_IMPLEMENT_STRUCT_TYPEINFO(SourceBreakpoint,
DAP_FIELD(condition, "condition"),
DAP_FIELD(hitCondition, "hitCondition"),
DAP_FIELD(line, "line"),
DAP_FIELD(logMessage, "logMessage"));
DAP_FIELD(logMessage, "logMessage"),
DAP_FIELD(mode, "mode"));
DAP_IMPLEMENT_STRUCT_TYPEINFO(DataBreakpoint,
"",
@ -245,7 +256,8 @@ DAP_IMPLEMENT_STRUCT_TYPEINFO(ExceptionOptions,
DAP_IMPLEMENT_STRUCT_TYPEINFO(ExceptionFilterOptions,
"",
DAP_FIELD(condition, "condition"),
DAP_FIELD(filterId, "filterId"));
DAP_FIELD(filterId, "filterId"),
DAP_FIELD(mode, "mode"));
DAP_IMPLEMENT_STRUCT_TYPEINFO(FunctionBreakpoint,
"",
@ -259,6 +271,7 @@ DAP_IMPLEMENT_STRUCT_TYPEINFO(InstructionBreakpoint,
DAP_FIELD(hitCondition, "hitCondition"),
DAP_FIELD(instructionReference,
"instructionReference"),
DAP_FIELD(mode, "mode"),
DAP_FIELD(offset, "offset"));
DAP_IMPLEMENT_STRUCT_TYPEINFO(StackFrame,

View File

@ -138,7 +138,7 @@ class Impl : public dap::Session {
return send(s.dump());
}
~Impl() {
~Impl() override {
inbox.close();
reader.close();
writer.close();