[Lldb-commits] [lldb] [lldb-dap] Updating RequestHandler to encode/decode arguments and response. (PR #130090)
Adrian Vogelsgesang via lldb-commits
lldb-commits at lists.llvm.org
Thu Mar 6 13:33:29 PST 2025
================
@@ -57,235 +68,288 @@ class RequestHandler {
DAP &dap;
};
-class AttachRequestHandler : public RequestHandler {
-public:
- using RequestHandler::RequestHandler;
+/// Base class for handling DAP requests. Handlers should declare their
+/// arguments and response body types like:
+///
+/// class MyRequestHandler : public RequestHandler<Arguments, ResponseBody> {
+/// ....
+/// };
+template <typename Args, typename Body>
+class RequestHandler : public BaseRequestHandler {
+ using BaseRequestHandler::BaseRequestHandler;
+
+ void operator()(const llvm::json::Object &request) const override {
+ /* no-op, the other overload handles json coding. */
+ }
+
+ void operator()(const protocol::Request &request) const override {
+ protocol::Response response;
+ response.request_seq = request.seq;
+ response.command = request.command;
+ Args arguments;
+ llvm::json::Path::Root root;
+ if (request.rawArguments &&
+ !fromJSON(request.rawArguments, arguments, root)) {
+ std::string parseFailure;
+ llvm::raw_string_ostream OS(parseFailure);
+ root.printErrorContext(request.rawArguments, OS);
+ response.success = false;
+ response.message = parseFailure;
----------------
vogelsgesang wrote:
message is not meant to contain a user-readable string, It is meant to contain an enum-like value.
I know that large parts of DAP don't do this correctly. But for newly written code, I think we should directly be protocol-compliant. Or at least add a `FIXME` similar to how you did further down
We might want to extend our error message enum to also have an `protocolViolation` in addition to `cancelled` and `notStopped`. The more descriptive `parseFailure` string should go into the `message` inside the `ErrorResponse`.
I think this one we would like to mark as `showUser: true`?
https://github.com/llvm/llvm-project/pull/130090
More information about the lldb-commits
mailing list