brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · 0e5c2b2 Raw
83 lines · cpp
1//===-- CompileUnitsRequestHandler.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-exception6//7//===----------------------------------------------------------------------===//8 9#include "DAP.h"10#include "EventHelper.h"11#include "JSONUtils.h"12#include "RequestHandler.h"13 14namespace lldb_dap {15 16// "compileUnitsRequest": {17//   "allOf": [ { "$ref": "#/definitions/Request" }, {18//     "type": "object",19//     "description": "Compile Unit request; value of command field is20//                     'compileUnits'.",21//     "properties": {22//       "command": {23//         "type": "string",24//         "enum": [ "compileUnits" ]25//       },26//       "arguments": {27//         "$ref": "#/definitions/compileUnitRequestArguments"28//       }29//     },30//     "required": [ "command", "arguments" ]31//   }]32// },33// "compileUnitsRequestArguments": {34//   "type": "object",35//   "description": "Arguments for 'compileUnits' request.",36//   "properties": {37//     "moduleId": {38//       "type": "string",39//       "description": "The ID of the module."40//     }41//   },42//   "required": [ "moduleId" ]43// },44// "compileUnitsResponse": {45//   "allOf": [ { "$ref": "#/definitions/Response" }, {46//     "type": "object",47//     "description": "Response to 'compileUnits' request.",48//     "properties": {49//       "body": {50//         "description": "Response to 'compileUnits' request. Array of51//                         paths of compile units."52//       }53//     }54//   }]55// }56void CompileUnitsRequestHandler::operator()(57    const llvm::json::Object &request) const {58  llvm::json::Object response;59  FillResponse(request, response);60  llvm::json::Object body;61  llvm::json::Array units;62  const auto *arguments = request.getObject("arguments");63  const llvm::StringRef module_id =64      GetString(arguments, "moduleId").value_or("");65  int num_modules = dap.target.GetNumModules();66  for (int i = 0; i < num_modules; i++) {67    auto curr_module = dap.target.GetModuleAtIndex(i);68    if (module_id == llvm::StringRef(curr_module.GetUUIDString())) {69      int num_units = curr_module.GetNumCompileUnits();70      for (int j = 0; j < num_units; j++) {71        auto curr_unit = curr_module.GetCompileUnitAtIndex(j);72        units.emplace_back(CreateCompileUnit(curr_unit));73      }74      body.try_emplace("compileUnits", std::move(units));75      break;76    }77  }78  response.try_emplace("body", std::move(body));79  dap.SendJSON(llvm::json::Value(std::move(response)));80}81 82} // namespace lldb_dap83