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 "ProtocolUtils.h"
11#include "RequestHandler.h"
12
13using namespace lldb_dap::protocol;
14namespace lldb_dap {
15
16/// Modules can be retrieved from the debug adapter with this request which can
17/// either return all modules or a range of modules to support paging.
18///
19/// Clients should only call this request if the corresponding capability
20/// `supportsModulesRequest` is true.
21llvm::Expected<ModulesResponseBody>
22ModulesRequestHandler::Run(const std::optional<ModulesArguments> &args) const {
23 ModulesResponseBody response;
24
25 std::vector<Module> &modules = response.modules;
26 std::lock_guard<std::mutex> guard(dap.modules_mutex);
27 const uint32_t total_modules = dap.target.GetNumModules();
28 response.totalModules = total_modules;
29
30 modules.reserve(n: total_modules);
31 for (uint32_t i = 0; i < total_modules; i++) {
32 lldb::SBModule module = dap.target.GetModuleAtIndex(idx: i);
33
34 std::optional<Module> result = CreateModule(target: dap.target, module);
35 if (result && !result->id.empty()) {
36 dap.modules.insert(key: result->id);
37 modules.emplace_back(args: std::move(result).value());
38 }
39 }
40
41 return response;
42}
43
44} // namespace lldb_dap
45

source code of lldb/tools/lldb-dap/Handler/ModulesRequestHandler.cpp