49 Commits

Author SHA1 Message Date
Brad King
1344b56dc5 jsoncpp: Cast dap integer to largest JsonCpp integer type
JsonCpp is not always built with support for `int64_t`.
2023-05-23 19:16:39 +01:00
Brad King
4d9f296aa2 jsoncpp: Add missing include <memory>
We use `std::unique_ptr` from this header.
2023-05-23 19:16:39 +01:00
Ben McMorran
13de893d55 Address PR comments 2023-05-19 17:15:11 +01:00
Ben McMorran
6a3c173aab Add support for JsonCpp 2023-05-19 17:15:11 +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
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
zhouyi
574190fb63 fix bug in processEvent function 2023-01-05 15:54:39 +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
Ben Clayton
5f3169421e
Fix reconnection of sockets (#70)
This was entirely broken:
* The `Server` `Impl` used a `do{}while(false)` block, which never attempted to accept another connection after the first connection closed (#69)
* The `Server` `Impl` could deadlock with the mutex being locked by both the thread calling `isRunning()` and `stopWithLock()` waiting on `thread.join()`.
* `Socket::accept()` didn't check that the returned socket was valid, and could return a `ReaderWriter` that would just error on IO.
* `Socket::accept()` could deadlock on macOS as `shutdown()` can seemingly fail to unblock an accept call. This has been worked around by calling `close()` outside of the mutex write-lock. This introduces a potential race, but I'm not sure of a better solution right now.
 
Fixes: #69
2021-09-07 18:55:02 +01:00
Ben Clayton
ebe7143ef1 json serializers: Support 64-bit integers.
Fixes: #66
2021-08-23 19:39:43 +01:00
Ben Clayton
23c95f91b5 rapid_json_serializer: Fix warning about shadowing
Fixes: #65
2021-08-23 19:39:19 +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
Ben Clayton
6d6cbf17d7 Add support for rapidjson as the JSON library
nlohmann is still the default, but if `CPPDAP_JSON_DIR` points to rapidjson, then this will be used instead

Most of this was upstreamed from:
https://fuchsia-review.googlesource.com/c/third_party/github.com/google/cppdap/+/456566
2020-12-02 17:44:24 +00:00
Puneetha Ramachandra
77209caf04 Fix content reader for partial input
When there is partial message in reader, popping out the
characters lead to parse errors on the subsequent attempt
to parse. To avoid this, the last matched characters'
index is stored during parsing and reset on error.
2020-12-01 18:13:31 +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
c9630a9aee TypeOf: Move Move TypeInfos to anon namespace
Instead of constructing them as static fields.
Slightly less cludgy.

Related issue: #40
2020-06-15 15:28:07 +01:00
Ben Clayton
ed0af8fa21 Add lots more tests for dap::any.
Exercise copy, assign, moves.
2020-06-15 15:16:10 +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
2f607e077a Fix deadlock closing socket on another thread
while another thread is stuck in read() or write().

Fixes: #37
2020-06-10 10:28:39 +01:00
Ben Clayton
9003ee55b9 Socket: Use the RWMutex to fix TSAN error
... about `close()`ing the socket on one thread while in a blocking `recv()` or `send()` call on another thread.

Fixes #35
2020-06-08 21:32:05 +01:00
Ben Clayton
53a62fd794 Add dap::RWMutex. A read / write mutex.
Also known as a shared mutex.
`std::shared_mutex` was introduced in C++17, but cppdap is C++11.

To be used to fix #35.
2020-06-08 21:32:05 +01:00
Ben Clayton
13c9e7d465 Implement timeouts for dap::Socket::connect
Fixes: #24
2020-06-08 20:22:05 +01:00
Ben Clayton
261d62d91e Remove unnecessary virtual inheritance
Looks like a copypasta mistake
2020-06-05 10:53:52 +01:00
Ben Clayton
aeb66147da json_serializer: Disable exceptions
Define `JSON_NOEXCEPTION` to avoid raising exceptions.
Exceptions are usually disabled for Google projects (https://google.github.io/styleguide/cppguide.html#Exceptions).

Also pass `false` to the `allow_exceptions` parameter of `nlohmann::json::parse()`.

Issue identified by @kuafuwang in #26.
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
c9187480d1 Fix short reads in ContentReader::buffer()
The actual length of data read by `dap::Reader::read()` was not being correctly inspected.

Fixed, added test.

Bug identified by @kuafuwang.

Fixes #27
2020-05-27 18:40:48 +01:00
Ben Clayton
ad9b4588f2 Fix dap::Socket::read() when recv() errors
Identified by @kuafuwang.

Fixes #29
2020-05-27 18:40:08 +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
4dcca57756 Socket: Enable TCP_NODELAY
DAP usually consists of small packet requests, with small packet responses. When there are many frequent, blocking requests made, Nagle's algorithm can dramatically limit the request->response rates.
2020-03-13 07:01:42 +00:00
Ben Clayton
de7dffaf66 Socket: Use SO_REUSEADDR, disable SO_LINGER
Use these to avoid "socket in use" errors when restarting a DAP that uses the same port.
2020-01-28 14:44:35 +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
96b25aafe0 src/io.cpp: Fix uninitialized variable.
`std::atomic<bool>` does not default initialize to `false`.

Bug: #12
2020-01-17 20:07:55 +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
Ben Clayton
3a10d4cabd Format all source files 2020-01-06 15:00:24 +00:00
Ben Clayton
d19d8f83c9
Address #7 nits and fix compiler warning (#9)
Compiler warning was signed / unsigned compare.
2019-12-31 21:04:57 +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
44d158805c Reimplement std::future and std::promise to workaround TSAN false positives 2019-11-14 08:10:16 +00:00
Ben Clayton
1f7f48904a Fix memory leak in src/socket.cpp 2019-11-14 00:37:38 +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