================
@@ -8,72 +8,43 @@
 
 #include "DAP.h"
 #include "EventHelper.h"
-#include "JSONUtils.h"
+#include "Protocol/ProtocolRequests.h"
+#include "ProtocolUtils.h"
 #include "RequestHandler.h"
+#include "lldb/API/SBDebugger.h"
+#include "lldb/API/SBDefines.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace llvm;
+using namespace lldb_dap::protocol;
 
 namespace lldb_dap {
 
-// "ThreadsRequest": {
-//   "allOf": [ { "$ref": "#/definitions/Request" }, {
-//     "type": "object",
-//     "description": "Thread request; value of command field is 'threads'. The
-//     request retrieves a list of all threads.", "properties": {
-//       "command": {
-//         "type": "string",
-//         "enum": [ "threads" ]
-//       }
-//     },
-//     "required": [ "command" ]
-//   }]
-// },
-// "ThreadsResponse": {
-//   "allOf": [ { "$ref": "#/definitions/Response" }, {
-//     "type": "object",
-//     "description": "Response to 'threads' request.",
-//     "properties": {
-//       "body": {
-//         "type": "object",
-//         "properties": {
-//           "threads": {
-//             "type": "array",
-//             "items": {
-//               "$ref": "#/definitions/Thread"
-//             },
-//             "description": "All threads."
-//           }
-//         },
-//         "required": [ "threads" ]
-//       }
-//     },
-//     "required": [ "body" ]
-//   }]
-// }
-void ThreadsRequestHandler::operator()(
-    const llvm::json::Object &request) const {
-  llvm::json::Object response;
-  FillResponse(request, response);
+/// The request retrieves a list of all threads.
+Expected<ThreadsResponseBody>
+ThreadsRequestHandler::Run(const ThreadsArguments &) const {
+  lldb::SBProcess process = dap.target.GetProcess();
+  std::vector<Thread> threads;
 
-  llvm::json::Array threads;
   // Client requests the baseline of currently existing threads after
   // a successful launch or attach by sending a 'threads' request
   // right after receiving the configurationDone response.
   // If no thread has reported to the client, it prevents something
   // like the pause request from working in the running state.
   // Return the cache of initial threads as the process might have resumed
   if (dap.initial_thread_list) {
-    threads = dap.initial_thread_list.value();
+    threads = *dap.initial_thread_list;
     dap.initial_thread_list.reset();
-  } else {
-    threads = GetThreads(dap.target.GetProcess(), dap.thread_format);
-  }
+  } else if (!lldb::SBDebugger::StateIsStoppedState(process.GetState()))
+    return make_error<NotStoppedError>();
+  else
+    threads = GetThreads(process, dap.thread_format);
----------------
JDevlieghere wrote:

Nit: if one case has braces, all of them should according to the style guide.
```suggestion
  } else if (!lldb::SBDebugger::StateIsStoppedState(process.GetState())) {
    return make_error<NotStoppedError>();
  } else {
    threads = GetThreads(process, dap.thread_format);
  }
```

https://github.com/llvm/llvm-project/pull/142510
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to