35 Commits

Author SHA1 Message Date
Brad King
03cc18678e optional: Fix compilation on XLClang 16.1.0
The compiler rejects initialization with `= {}`:

    error: chosen constructor is explicit in copy-initialization

Use just `{}` instead.
2023-05-26 00:20:21 +01:00
Brad King
79562e0742 any: Add missing include <stdint.h>
We use `uint8_t` and `uintptr_t` from this header.
2023-05-22 23:27:25 +01:00
Brad King
385f9ed3ad
any: Tell clang-analyzer a pointer is not nullptr (#107)
Previously, clang-analyzer warned:

    /.../any.h:146:5: warning: Called C++ object pointer is null [core.CallAndMessage]
2023-05-17 20:02:57 +01:00
Brad King
5f49573daf
Fix compiler warning and error encountered on some platforms (#106)
* typeof: Avoid -Wshadow-uncaptured-local in DAP_IMPLEMENT_STRUCT_TYPEINFO

Previously, applications using `DAP_IMPLEMENT_STRUCT_TYPEINFO` may see:

    <app-file>:<app-line>:1: warning: declaration shadows a local variable [-Wshadow-uncaptured-local]
    DAP_IMPLEMENT_STRUCT_TYPEINFO(<app-args>),
    ^
    /.../include/dap/typeof.h:199:3: note: expanded from macro 'DAP_IMPLEMENT_STRUCT_TYPEINFO'
    DAP_IMPLEMENT_STRUCT_FIELD_SERIALIZATION(STRUCT, NAME, __VA_ARGS__)       \
    ^
    /.../include/dap/typeof.h:168:51: note: expanded from macro 'DAP_IMPLEMENT_STRUCT_FIELD_SERIALIZATION'
        if (!d->field(field.name, [&](Deserializer* d) {                        \
                                                    ^
    <app-file>:<app-line>:1: note: previous declaration is here
    /.../include/dap/typeof.h:199:3: note: expanded from macro 'DAP_IMPLEMENT_STRUCT_TYPEINFO'
    DAP_IMPLEMENT_STRUCT_FIELD_SERIALIZATION(STRUCT, NAME, __VA_ARGS__)       \
    ^
    /.../include/dap/typeof.h:164:62: note: expanded from macro 'DAP_IMPLEMENT_STRUCT_FIELD_SERIALIZATION'
    bool TypeOf<STRUCT>::deserializeFields(const Deserializer* d, void* obj) {  \
                                                               ^

* io: add missing include for std::string
2023-05-17 19:10:58 +01:00
Ben Clayton
619435a703
Add missing include to io.h (#105)
Fixes #104
2023-05-05 18:05:53 +01:00
Ben Clayton
59819690ec
Add Session::ClosedHandler (#99)
A callback function to signal that the endpoint has closed its connection.

Add this as an optional argument to Session::bind() and Session::startProcessingMessages().

Bug: #98
2023-02-28 14:26:12 +00:00
nikitalita
315ffff9e7
Fix any, embedded object, array, and struct serialization (#94)
* add embedded object serialization tests (failing)

* Add empty object tests (failing)

* test for deserializing null field object (failing)

* Fix embedded object deserialization

* Fix serializing empty objects on nlohmann

* Fix nullptr_t handling in `any`

* Add test for de/serializing struct embedded in `object`

* Remove extraneous `get()` from `any`

* fix compiler errors and warnings on gcc

* add `any = dap::null` assignment test

* Remove extraneous template
2023-02-16 23:09:45 +00:00
nikitalita
d9041149a8
Auto-update cmakelists on protocol sync, update to 1.59.0 (#93)
* CMake: Fix target options

* update CMake package version after protocol sync

* Update protocol to 1.59.0

* protocol_gen: change OneOf to `object` type

The DAP spec introduces ambiguities with its particular uses of OneOf,
which means that we can't deserialize the variants generated from it.
Just set OneOf to an `object` type, like godap does.
2023-02-13 22:55:48 +00:00
nikitalita
87f8b4a06b
Fix "oneOf" parsing, update to protocol version 1.58 (#85)
* fix "oneOf" parsing in protocol_gen

* update protocol version to 1.58.0
2022-12-16 13:43:39 +00:00
luzhen
a841177c5b
Fix valid function invoke failed in future class (#75)
In C++11, shared_ptr has an explicit operator bool which
means that a shared_ptr can't be implicitly converted to a bool.
adding an explicit cast is a valid fix to the code.
2021-12-23 07:21:55 +00:00
Ben Clayton
323e91d80b Session: Expose 'protected' API.
Classify 'advanced' APIs from the 'basic' API.
Move `bind()` up top, which is the typical way to use the Session.
Comment on the other APIs that you should probably just use `bind()`.

Document all the members that are now public.

Fixes: #63
2021-09-07 18:43:12 +01:00
Ben Clayton
9a97ffce52 traits.h: Rename TRUE to TRUE_TY
A workaround for `TRUE` being a `#define` in Windows headers.
Fixes #62
2021-08-23 19:39:55 +01:00
Ben Clayton
be5b677c7b Fix generation of named enumerator types
Schema top-level definitions, such as `InvalidatedAreas` and `SteppingGranularity` were being emitted as empty structures, when they were actually enumerators.

Re-work protocol_gen.go to emit these correctly.

Also bumps the protocol to DAP version 1.46.0
2021-04-14 22:00:29 +01:00
Ben Clayton
2a3ba20937
Merge pull request #58 from ben-clayton/response-callbacks
Add Session::registerHandler() overloads that support response callbacks
2021-02-03 19:08:27 +00:00
Ben Clayton
e10691ab3f Update DAP protocol to 1.43.0 2021-01-14 12:49:37 +00:00
Puneetha Ramachandra
e53575d272 Split bind API
Bind API is split into connect and startProcessingMessages calls.
This enables users to directly call connect and manage processing
messages on user threads.
2020-12-01 17:59:43 +00:00
Puneetha Ramachandra
ea6098df7f Added bindNoThread
bindNoThread in conjunction with OnDataAvailable will provide
users with a choice of thread to process requests on. This is
useful when the user relies on single threaded message loop based
design to avoid locking.
2020-12-01 17:59:43 +00:00
Ben Clayton
1e5ec3e405 Change dap::integer backing type to int64_t
`int` may be < 64 bit, and some dap protocols use a 64 bit integer. Chnage to `int64_t` to be consistent.

Fixes: #45
2020-06-30 11:57:51 +01:00
Ben Clayton
7b02b9f73a Add dap::initialize() and terminate() functions
Can be used to explicitly control when the TypeInfo static initializers / destructors are called.
Usually not needed.

Issue: #40
2020-06-22 19:51:39 +01:00
Ben Clayton
9d3f5c8f1d clang: Enable -Weverything, fix all warnings
This change fixes the following warnings:

```
    -Wc++98-compat-extra-semi
    -Wc++98-compat-local-type-template-args
    -Wc++98-compat-pedantic
    -Wc++98-compat
    -Wcomma
    -Wdeprecated-copy-dtor
    -Wexit-time-destructors
    -Wextra-semi-stmt
    -Wextra-semi
    -Wfloat-conversion
    -Wfloat-equal
    -Wformat-nonliteral
    -Wglobal-constructors
    -Winconsistent-missing-destructor-override
    -Wnon-virtual-dtor
    -Wold-style-cast
    -Wpadded
    -Wreturn-std-move-in-c++11
    -Wshadow-field-in-constructor
    -Wshadow-uncaptured-local
    -Wshift-sign-overflow
    -Wsign-conversion
    -Wundef
    -Wunreachable-code-return
    -Wused-but-marked-unused
    -Wweak-vtables
    -Wzero-as-null-pointer-constant
```
2020-06-10 15:10:57 +01:00
Ben Clayton
bb3dbcd2c3 Update DAP protocol to 1.41.0
Update the script to include the DAP version in the file headers.

Remove http file caching. Was never used.
2020-06-10 15:10:57 +01:00
Ben Clayton
f0c28f93dd Fix moves of any when value isInBuffer
This was copying the pointer to the other's value in other.buffer.
2020-06-10 15:10:57 +01:00
Ben Clayton
13c9e7d465 Implement timeouts for dap::Socket::connect
Fixes: #24
2020-06-08 20:22:05 +01:00
Ben Clayton
773f0dff68 Add support for fuzzing cppdap
Add build rules, scripts, basic corpus, and dictionary.
Currently requires recent clang toolchain.
2020-06-05 10:53:52 +01:00
Ben Clayton
cc93ba9747 Add the ability to derive message types from one another.
`DAP_IMPLEMENT_STRUCT_TYPEINFO_EXT` and `DAP_STRUCT_TYPEINFO_EXT` are two new flavors of `DAP_IMPLEMENT_STRUCT_TYPEINFO` and `DAP_STRUCT_TYPEINFO` that allow you to derive message types.

This involved a bit of reworking on the serializer interfaces.

Added test.

Issue: #32
2020-06-02 17:18:32 +01:00
Ben Clayton
4bc690cba8 Update DAP protocol to Version 1.40
Updated with:
 `go run scripts/protocol_gen/protocol_gen.go`
2020-05-05 13:03:20 +01:00
Ben Clayton
c4358807e2 Fix new gcc 9 'deprecated-copy' warning.
Example warning:

cppdap/include/dap/future.h:172:14: error: implicitly-declared ‘dap::ResponseOrError<dap::StackTraceResponse>& dap::ResponseOrError<dap::StackTraceResponse>::operator=(const dap::ResponseOrError<dap::StackTraceResponse>&)’ is deprecated [-Werror=deprecated-copy]

Add missing constructors and assignment operators.
This probably adds more than is absolutely necessary, but there's no
harm in being thorough.
2020-02-06 13:37:41 +00:00
Ben Clayton
9a9d46f6b6 Fix bad usage of std::move
Issue #16 describes the problem and solution perfectly.

Updated tests to cover this.

Fixes #16
2020-01-24 15:21:26 +00:00
Ben Clayton
4abe43c131 optional: Remove the value() method that returns non-const-ref.
I'm not convinced that `opt.value() = foo` is a desirable pattern,
and worse still it confuses some compilers about which overload to
use.

Just remove it.
2020-01-24 07:25:33 +00:00
Ben Clayton
cdc19ac4d9 Serialization: Correctly encode structs with no fields
Empty structs were being serialized as `null`, when they should have been serialized as `{}`.

This was due to the type inference on the serializer - where no calls to `field()` would result in the default `null` type.

To solve this, the `serialize(const void* object, const std::initializer_list<Field>&)` inline helper has been promoted to a virtual function (and renamed to `fields()`).
The JSON serializer implementation of this now first sets the object type to `object`, even if there are no fields to serialize.

Added test for this.

Fixes: #10
2020-01-06 15:00:24 +00:00
kuafuwang
73d697eac4 Fix Response type info, make response 'body' field optional
The `body` field of the Response is optional. Do not error if it is missing.

If the typeinfo of the response. This was incorrectly using the Request type.

Authored by kuafuwang, squashed by ben-clayton.
2019-12-31 20:58:33 +00:00
Ben Clayton
eab43f3518 net::Server: Fix onError parameter default.
The onError parameter of Server::start was default initialized with
OnError(), which is an 'invalid target', not a no-op implementation.

Replace with a true no-op implementation.
2019-12-05 15:12:56 +00:00
Ben Clayton
44d158805c Reimplement std::future and std::promise to workaround TSAN false positives 2019-11-14 08:10:16 +00:00
Ben Clayton
d13d4a4151 GCC build fixes 2019-11-14 00:29:38 +00:00
Ben Clayton
2dfd15462f Initial drop of cppdap 2019-11-08 21:58:50 +00:00