| //===-- ThreadsRequestHandler.cpp -----------------------------------------===// |
| // |
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| // See https://llvm.org/LICENSE.txt for license information. |
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| // |
| //===----------------------------------------------------------------------===// |
| |
| #include "DAP.h" |
| #include "EventHelper.h" |
| #include "JSONUtils.h" |
| #include "RequestHandler.h" |
| |
| 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); |
| |
| 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(); |
| } else { |
| threads = GetThreads(dap.target.GetProcess(), dap.thread_format); |
| } |
| |
| if (threads.size() == 0) { |
| response["success"] = llvm::json::Value(false); |
| } |
| 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))); |
| } |
| |
| } // namespace lldb_dap |