|
9 | 9 | #include "DAP.h" |
10 | 10 | #include "JSONUtils.h" |
11 | 11 | #include "RequestHandler.h" |
| 12 | +#include <vector> |
12 | 13 |
|
13 | 14 | namespace lldb_dap { |
14 | 15 |
|
15 | | -// "BreakpointLocationsRequest": { |
16 | | -// "allOf": [ { "$ref": "#/definitions/Request" }, { |
17 | | -// "type": "object", |
18 | | -// "description": "The `breakpointLocations` request returns all possible |
19 | | -// locations for source breakpoints in a given range.\nClients should only |
20 | | -// call this request if the corresponding capability |
21 | | -// `supportsBreakpointLocationsRequest` is true.", |
22 | | -// "properties": { |
23 | | -// "command": { |
24 | | -// "type": "string", |
25 | | -// "enum": [ "breakpointLocations" ] |
26 | | -// }, |
27 | | -// "arguments": { |
28 | | -// "$ref": "#/definitions/BreakpointLocationsArguments" |
29 | | -// } |
30 | | -// }, |
31 | | -// "required": [ "command" ] |
32 | | -// }] |
33 | | -// }, |
34 | | -// "BreakpointLocationsArguments": { |
35 | | -// "type": "object", |
36 | | -// "description": "Arguments for `breakpointLocations` request.", |
37 | | -// "properties": { |
38 | | -// "source": { |
39 | | -// "$ref": "#/definitions/Source", |
40 | | -// "description": "The source location of the breakpoints; either |
41 | | -// `source.path` or `source.sourceReference` must be specified." |
42 | | -// }, |
43 | | -// "line": { |
44 | | -// "type": "integer", |
45 | | -// "description": "Start line of range to search possible breakpoint |
46 | | -// locations in. If only the line is specified, the request returns all |
47 | | -// possible locations in that line." |
48 | | -// }, |
49 | | -// "column": { |
50 | | -// "type": "integer", |
51 | | -// "description": "Start position within `line` to search possible |
52 | | -// breakpoint locations in. It is measured in UTF-16 code units and the |
53 | | -// client capability `columnsStartAt1` determines whether it is 0- or |
54 | | -// 1-based. If no column is given, the first position in the start line is |
55 | | -// assumed." |
56 | | -// }, |
57 | | -// "endLine": { |
58 | | -// "type": "integer", |
59 | | -// "description": "End line of range to search possible breakpoint |
60 | | -// locations in. If no end line is given, then the end line is assumed to |
61 | | -// be the start line." |
62 | | -// }, |
63 | | -// "endColumn": { |
64 | | -// "type": "integer", |
65 | | -// "description": "End position within `endLine` to search possible |
66 | | -// breakpoint locations in. It is measured in UTF-16 code units and the |
67 | | -// client capability `columnsStartAt1` determines whether it is 0- or |
68 | | -// 1-based. If no end column is given, the last position in the end line |
69 | | -// is assumed." |
70 | | -// } |
71 | | -// }, |
72 | | -// "required": [ "source", "line" ] |
73 | | -// }, |
74 | | -// "BreakpointLocationsResponse": { |
75 | | -// "allOf": [ { "$ref": "#/definitions/Response" }, { |
76 | | -// "type": "object", |
77 | | -// "description": "Response to `breakpointLocations` request.\nContains |
78 | | -// possible locations for source breakpoints.", |
79 | | -// "properties": { |
80 | | -// "body": { |
81 | | -// "type": "object", |
82 | | -// "properties": { |
83 | | -// "breakpoints": { |
84 | | -// "type": "array", |
85 | | -// "items": { |
86 | | -// "$ref": "#/definitions/BreakpointLocation" |
87 | | -// }, |
88 | | -// "description": "Sorted set of possible breakpoint locations." |
89 | | -// } |
90 | | -// }, |
91 | | -// "required": [ "breakpoints" ] |
92 | | -// } |
93 | | -// }, |
94 | | -// "required": [ "body" ] |
95 | | -// }] |
96 | | -// }, |
97 | | -// "BreakpointLocation": { |
98 | | -// "type": "object", |
99 | | -// "description": "Properties of a breakpoint location returned from the |
100 | | -// `breakpointLocations` request.", |
101 | | -// "properties": { |
102 | | -// "line": { |
103 | | -// "type": "integer", |
104 | | -// "description": "Start line of breakpoint location." |
105 | | -// }, |
106 | | -// "column": { |
107 | | -// "type": "integer", |
108 | | -// "description": "The start position of a breakpoint location. Position |
109 | | -// is measured in UTF-16 code units and the client capability |
110 | | -// `columnsStartAt1` determines whether it is 0- or 1-based." |
111 | | -// }, |
112 | | -// "endLine": { |
113 | | -// "type": "integer", |
114 | | -// "description": "The end line of breakpoint location if the location |
115 | | -// covers a range." |
116 | | -// }, |
117 | | -// "endColumn": { |
118 | | -// "type": "integer", |
119 | | -// "description": "The end position of a breakpoint location (if the |
120 | | -// location covers a range). Position is measured in UTF-16 code units and |
121 | | -// the client capability `columnsStartAt1` determines whether it is 0- or |
122 | | -// 1-based." |
123 | | -// } |
124 | | -// }, |
125 | | -// "required": [ "line" ] |
126 | | -// }, |
127 | | -void BreakpointLocationsRequestHandler::operator()( |
128 | | - const llvm::json::Object &request) const { |
129 | | - llvm::json::Object response; |
130 | | - FillResponse(request, response); |
131 | | - auto *arguments = request.getObject("arguments"); |
132 | | - auto *source = arguments->getObject("source"); |
133 | | - std::string path = GetString(source, "path").value_or("").str(); |
134 | | - const auto start_line = GetInteger<uint64_t>(arguments, "line") |
135 | | - .value_or(LLDB_INVALID_LINE_NUMBER); |
136 | | - const auto start_column = GetInteger<uint64_t>(arguments, "column") |
137 | | - .value_or(LLDB_INVALID_COLUMN_NUMBER); |
138 | | - const auto end_line = |
139 | | - GetInteger<uint64_t>(arguments, "endLine").value_or(start_line); |
140 | | - const auto end_column = GetInteger<uint64_t>(arguments, "endColumn") |
141 | | - .value_or(std::numeric_limits<uint64_t>::max()); |
| 16 | +/// The `breakpointLocations` request returns all possible locations for source |
| 17 | +/// breakpoints in a given range. Clients should only call this request if the |
| 18 | +/// corresponding capability `supportsBreakpointLocationsRequest` is true. |
| 19 | +llvm::Expected<protocol::BreakpointLocationsResponseBody> |
| 20 | +BreakpointLocationsRequestHandler::Run( |
| 21 | + const protocol::BreakpointLocationsArguments &args) const { |
| 22 | + std::string path = args.source.path.value_or(""); |
| 23 | + uint32_t start_line = args.line; |
| 24 | + uint32_t start_column = args.column.value_or(LLDB_INVALID_COLUMN_NUMBER); |
| 25 | + uint32_t end_line = args.endLine.value_or(start_line); |
| 26 | + uint32_t end_column = |
| 27 | + args.endColumn.value_or(std::numeric_limits<uint32_t>::max()); |
142 | 28 |
|
143 | 29 | lldb::SBFileSpec file_spec(path.c_str(), true); |
144 | 30 | lldb::SBSymbolContextList compile_units = |
@@ -191,18 +77,16 @@ void BreakpointLocationsRequestHandler::operator()( |
191 | 77 | std::sort(locations.begin(), locations.end()); |
192 | 78 | locations.erase(llvm::unique(locations), locations.end()); |
193 | 79 |
|
194 | | - llvm::json::Array locations_json; |
| 80 | + std::vector<protocol::BreakpointLocation> breakpoint_locations; |
195 | 81 | for (auto &l : locations) { |
196 | | - llvm::json::Object location; |
197 | | - location.try_emplace("line", l.first); |
198 | | - location.try_emplace("column", l.second); |
199 | | - locations_json.emplace_back(std::move(location)); |
| 82 | + protocol::BreakpointLocation lc; |
| 83 | + lc.line = l.first; |
| 84 | + lc.column = l.second; |
| 85 | + breakpoint_locations.push_back(std::move(lc)); |
200 | 86 | } |
201 | 87 |
|
202 | | - llvm::json::Object body; |
203 | | - body.try_emplace("breakpoints", std::move(locations_json)); |
204 | | - response.try_emplace("body", std::move(body)); |
205 | | - dap.SendJSON(llvm::json::Value(std::move(response))); |
| 88 | + return protocol::BreakpointLocationsResponseBody{ |
| 89 | + /*breakpoints=*/std::move(breakpoint_locations)}; |
206 | 90 | } |
207 | 91 |
|
208 | 92 | } // namespace lldb_dap |
0 commit comments