|
8 | 8 |
|
9 | 9 | #include "DAP.h" |
10 | 10 | #include "EventHelper.h" |
11 | | -#include "JSONUtils.h" |
| 11 | +#include "Protocol/ProtocolRequests.h" |
12 | 12 | #include "RequestHandler.h" |
13 | 13 |
|
14 | | -namespace lldb_dap { |
| 14 | +using namespace lldb_dap; |
| 15 | +using namespace lldb_dap::protocol; |
15 | 16 |
|
16 | | -// "compileUnitsRequest": { |
17 | | -// "allOf": [ { "$ref": "#/definitions/Request" }, { |
18 | | -// "type": "object", |
19 | | -// "description": "Compile Unit request; value of command field is |
20 | | -// '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 of |
51 | | -// paths of compile units." |
52 | | -// } |
53 | | -// } |
54 | | -// }] |
55 | | -// } |
56 | | -void 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(""); |
| 17 | +static CompileUnit CreateCompileUnit(lldb::SBCompileUnit &unit) { |
| 18 | + char unit_path_arr[PATH_MAX]; |
| 19 | + unit.GetFileSpec().GetPath(unit_path_arr, sizeof(unit_path_arr)); |
| 20 | + std::string unit_path(unit_path_arr); |
| 21 | + return {std::move(unit_path)}; |
| 22 | +} |
| 23 | + |
| 24 | +/// The `compileUnits` request returns an array of path of compile units for |
| 25 | +/// given module specified by `moduleId`. |
| 26 | +llvm::Expected<CompileUnitsResponseBody> CompileUnitsRequestHandler::Run( |
| 27 | + const std::optional<CompileUnitsArguments> &args) const { |
| 28 | + std::vector<CompileUnit> units; |
65 | 29 | int num_modules = dap.target.GetNumModules(); |
66 | 30 | for (int i = 0; i < num_modules; i++) { |
67 | 31 | auto curr_module = dap.target.GetModuleAtIndex(i); |
68 | | - if (module_id == llvm::StringRef(curr_module.GetUUIDString())) { |
| 32 | + if (args->moduleId == llvm::StringRef(curr_module.GetUUIDString())) { |
69 | 33 | int num_units = curr_module.GetNumCompileUnits(); |
70 | 34 | for (int j = 0; j < num_units; j++) { |
71 | 35 | auto curr_unit = curr_module.GetCompileUnitAtIndex(j); |
72 | 36 | units.emplace_back(CreateCompileUnit(curr_unit)); |
73 | 37 | } |
74 | | - body.try_emplace("compileUnits", std::move(units)); |
75 | 38 | break; |
76 | 39 | } |
77 | 40 | } |
78 | | - response.try_emplace("body", std::move(body)); |
79 | | - dap.SendJSON(llvm::json::Value(std::move(response))); |
| 41 | + return CompileUnitsResponseBody{std::move(units)}; |
80 | 42 | } |
81 | | - |
82 | | -} // namespace lldb_dap |
0 commit comments