89 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
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
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
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
Brad King
558886e7e0
cmake: Avoid exposing implementation dependencies publicly (#102)
The `CPPDAP_JSON_{NLOHMANN,RAPID}` compile definition is used only in
cppdap's implementation sources, and does not need to be defined by
dependents including our headers.

Also avoid exposing `nlohmann_json::nlohmann_json` as a public link
dependency of our installed package.  It is used only when compiling
cppdap.
2023-03-23 17:56:22 +00:00
nikitalita
bf1f56547c
autogenerate fuzzing data from spec (#95) 2023-03-13 17:17:41 +00: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
0a340c6d71
Add options to link against external JSON libraries (#91)
Add options to link against external JSON libraries

This adds two options to the CMake config:

`CPPDAP_USE_EXTERNAL_NLOHMANN_JSON_PACKAGE` and `CPPDAP_USE_EXTERNAL_RAPIDJSON_PACKAGE`
If either of these is set, instead of using the json submodule, the build will be configured by using `find_package()` and linking against the specified JSON library.
2023-01-10 13:35:23 +00:00
nikitalita
a4bc977343 Exclude .gitattributes from license checker 2023-01-06 15:54:31 +00:00
nikitalita
f08774e5f6 Fix CRLF EOL in config.cmake.in, add gitattributes 2023-01-06 15:54:31 +00:00
zhouyi
574190fb63 fix bug in processEvent function 2023-01-05 15:54:39 +00:00
nikitalita
3b01ef99ae Bump version of cmake in Windows kokoro script 2023-01-05 12:40:05 +00:00
nikitalita
5b796454c1 Bump required CMake to 3.11 2023-01-05 12:40:05 +00:00
nikitalita
7c31141c5a White space fixes 2023-01-05 12:40:05 +00:00
nikitalita
a25be1fa0b cmakelists.txt: add destinations to install targets
Add proper ARCHIVE, LIBRARY, and INCLUDES to install target
2023-01-05 12:40:05 +00:00
nikitalita
eedb5e02b6 add license header to config.in, bump copyright date 2023-01-05 12:40:05 +00:00
nikitalita
22779a0052 bump cmake package version 2023-01-05 12:40:05 +00:00
nikitalita
ebdcc5b9b4 fix semver require, config template 2023-01-05 12:40:05 +00:00
nikitalita
fe8695c502 Add package install and config 2023-01-05 12:40:05 +00:00
Ben Clayton
03e975779e Add a simple network client / server example
Issue: #77
2023-01-04 10:48:24 +00:00
Ben Clayton
8a320f56dc
Minor cleanup + kokoro ubuntu fix (#86)
* tools: Minor clean up of protocol_gen.go

* Fix kokoro/ubuntu builds
2022-12-16 13:53:50 +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
88e8952014
kokoro: Fix ASAN build (#76)
The VM has been updated to Kokoro 14.04, and now the docker instance requires escalated privileges in order to run some sanitizer builds.
2021-12-23 17:35:56 +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
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
51cf2951d0 CMake: Remove installation target
CMake installation target has been broken for years.
cppdap is only internally used and tested as a library that is included as a sub-module of another project.

In order for a package to be installable, it really needs a stable ABI / API, which we've made no explicit guarantees about.
cppdap is small enough that it can easily be included in a third_party directory of another project.

Remove the broken, unmaintained installation rules.

Fixes: #54
2021-09-07 18:52:14 +01: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
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
ad185ee762 license-checker.cfg: Update rules
The license classification rules in github.com/google/licensecheck have been updated.
2021-02-11 21:58:21 +00: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
1fd23dda91 Add license checker config and kokoro presubmit
`license-checker` is a tool that verifies each file has contains a permitted license header.

See https://github.com/ben-clayton/license-checker for more information.

Also add missing licenses to presubmit scripts.
2020-07-21 16:31:05 +01: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