| 1 | //===-- ModulesRequestHandler.cpp -----------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "DAP.h" |
| 10 | #include "EventHelper.h" |
| 11 | #include "JSONUtils.h" |
| 12 | #include "RequestHandler.h" |
| 13 | |
| 14 | namespace lldb_dap { |
| 15 | |
| 16 | // "modulesRequest": { |
| 17 | // "allOf": [ { "$ref": "#/definitions/Request" }, { |
| 18 | // "type": "object", |
| 19 | // "description": "Modules request; value of command field is |
| 20 | // 'modules'.", |
| 21 | // "properties": { |
| 22 | // "command": { |
| 23 | // "type": "string", |
| 24 | // "enum": [ "modules" ] |
| 25 | // }, |
| 26 | // }, |
| 27 | // "required": [ "command" ] |
| 28 | // }] |
| 29 | // }, |
| 30 | // "modulesResponse": { |
| 31 | // "allOf": [ { "$ref": "#/definitions/Response" }, { |
| 32 | // "type": "object", |
| 33 | // "description": "Response to 'modules' request.", |
| 34 | // "properties": { |
| 35 | // "body": { |
| 36 | // "description": "Response to 'modules' request. Array of |
| 37 | // module objects." |
| 38 | // } |
| 39 | // } |
| 40 | // }] |
| 41 | // } |
| 42 | void ModulesRequestHandler::operator()( |
| 43 | const llvm::json::Object &request) const { |
| 44 | llvm::json::Object response; |
| 45 | FillResponse(request, response); |
| 46 | |
| 47 | llvm::json::Array modules; |
| 48 | |
| 49 | { |
| 50 | std::lock_guard<std::mutex> guard(dap.modules_mutex); |
| 51 | for (size_t i = 0; i < dap.target.GetNumModules(); i++) { |
| 52 | lldb::SBModule module = dap.target.GetModuleAtIndex(idx: i); |
| 53 | if (!module.IsValid()) |
| 54 | continue; |
| 55 | |
| 56 | llvm::StringRef module_id = module.GetUUIDString(); |
| 57 | if (!module_id.empty()) |
| 58 | dap.modules.insert(key: module_id); |
| 59 | |
| 60 | modules.emplace_back(A: CreateModule(target&: dap.target, module)); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | llvm::json::Object body; |
| 65 | body.try_emplace(K: "modules" , Args: std::move(modules)); |
| 66 | response.try_emplace(K: "body" , Args: std::move(body)); |
| 67 | dap.SendJSON(json: llvm::json::Value(std::move(response))); |
| 68 | } |
| 69 | |
| 70 | } // namespace lldb_dap |
| 71 | |