diff options
Diffstat (limited to 'lldb/tools/lldb-dap/Handler/ThreadsRequestHandler.cpp')
| -rw-r--r-- | lldb/tools/lldb-dap/Handler/ThreadsRequestHandler.cpp | 77 |
1 files changed, 25 insertions, 52 deletions
diff --git a/lldb/tools/lldb-dap/Handler/ThreadsRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/ThreadsRequestHandler.cpp index 16d797c2ab32..8b328d8348e3 100644 --- a/lldb/tools/lldb-dap/Handler/ThreadsRequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/ThreadsRequestHandler.cpp @@ -8,72 +8,45 @@ #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(); - dap.initial_thread_list.reset(); + if (!dap.initial_thread_list.empty()) { + threads = dap.initial_thread_list; + dap.initial_thread_list.clear(); } else { - threads = GetThreads(dap.target.GetProcess(), dap.thread_format); - } + if (!lldb::SBDebugger::StateIsStoppedState(process.GetState())) + return make_error<NotStoppedError>(); - if (threads.size() == 0) { - response["success"] = llvm::json::Value(false); + threads = GetThreads(process, dap.thread_format); } - llvm::json::Object body; - body.try_emplace("threads", std::move(threads)); - response.try_emplace("body", std::move(body)); - dap.SendJSON(llvm::json::Value(std::move(response))); + + if (threads.size() == 0) + return make_error<DAPError>("failed to retrieve threads from process"); + + return ThreadsResponseBody{threads}; } } // namespace lldb_dap |
