9
9
#include " DAP.h"
10
10
11
11
#include " JSONUtils.h"
12
+ #include " Protocol/ProtocolRequests.h"
13
+ #include " RequestHandler.h"
12
14
13
15
#include < lldb/API/SBBreakpointLocation.h>
14
16
#include < lldb/API/SBListener.h>
@@ -20,7 +22,7 @@ static llvm::SmallVector<lldb::SBLineEntry>
20
22
GetLineValidEntry (DAP &dap, const lldb::SBFileSpec &file_spec, uint32_t line) {
21
23
// Disable breakpoint listeners so they do not send events to the DAP client.
22
24
lldb::SBListener listener = dap.debugger .GetListener ();
23
- lldb::SBBroadcaster broadcaster = dap.target .GetBroadcaster ();
25
+ const lldb::SBBroadcaster broadcaster = dap.target .GetBroadcaster ();
24
26
constexpr auto event_mask = lldb::SBTarget::eBroadcastBitBreakpointChanged;
25
27
listener.StopListeningForEvents (broadcaster, event_mask);
26
28
@@ -55,111 +57,35 @@ GetLineValidEntry(DAP &dap, const lldb::SBFileSpec &file_spec, uint32_t line) {
55
57
return entry_locations;
56
58
}
57
59
58
- // "GotoTargetsRequest": {
59
- // "allOf": [ { "$ref": "#/definitions/Request" }, {
60
- // "type": "object",
61
- // "description": "This request retrieves the possible goto targets for the
62
- // specified source location.\nThese targets can be used in the `goto`
63
- // request.\nClients should only call this request if the corresponding
64
- // capability `supportsGotoTargetsRequest` is true.",
65
- // . "properties": {
66
- // "command": {
67
- // "type": "string",
68
- // "enum": [ "gotoTargets" ]
69
- // },
70
- // "arguments": {
71
- // "$ref": "#/definitions/GotoTargetsArguments"
72
- // }
73
- // },
74
- // "required": [ "command", "arguments" ]
75
- // }]
76
- // },
77
- // "GotoTargetsArguments": {
78
- // "type": "object",
79
- // "description": "Arguments for `gotoTargets` request.",
80
- // "properties": {
81
- // "source": {
82
- // "$ref": "#/definitions/Source",
83
- // "description": "The source location for which the goto targets are
84
- // determined."
85
- // },
86
- // "line": {
87
- // "type": "integer",
88
- // "description": "The line location for which the goto targets are
89
- // determined."
90
- // },
91
- // "column": {
92
- // "type": "integer",
93
- // "description": "The position within `line` for which the goto targets
94
- // are determined. It is measured in UTF-16 code units and the client
95
- // capability `columnsStartAt1` determines whether it is 0- or 1-based."
96
- // }
97
- // },
98
- // "required": [ "source", "line" ]
99
- // },
100
- // "GotoTargetsResponse": {
101
- // "allOf": [ { "$ref": "#/definitions/Response" }, {
102
- // "type": "object",
103
- // "description": "Response to `gotoTargets` request.",
104
- // "properties": {
105
- // "body": {
106
- // "type": "object",
107
- // "properties": {
108
- // "targets": {
109
- // "type": "array",
110
- // "items": {
111
- // "$ref": "#/definitions/GotoTarget"
112
- // },
113
- // "description": "The possible goto targets of the specified
114
- // location."
115
- // }
116
- // },
117
- // "required": [ "targets" ]
118
- // }
119
- // },
120
- // "required": [ "body" ]
121
- // }]
122
- // },
123
- void GoToTargetsRequestHandler::operator ()(
124
- const llvm::json::Object &request) const {
125
- llvm::json::Object response;
126
- FillResponse (request, response);
127
-
128
- const llvm::json::Object *arguments = request.getObject (" arguments" );
129
- const llvm::json::Object *source = arguments->getObject (" source" );
130
- const std::string path = GetString (source, " path" ).str ();
131
- const lldb::SBFileSpec file_spec (path.c_str (), true );
132
- const uint64_t goto_line =
133
- GetInteger<uint64_t >(arguments, " line" ).value_or (1U );
134
-
135
- llvm::json::Object body;
60
+ // / GotoTargets request; value of command field is 'gotoTargets'.
61
+ llvm::Expected<protocol::GotoTargetsResponseBody>
62
+ GotoTargetsRequestHandler::Run (
63
+ const protocol::GotoTargetsArguments &args) const {
64
+ const lldb::SBFileSpec file_spec (args.source .path .value_or (" " ).c_str (), true );
65
+ const uint64_t goto_line = args.line ;
136
66
137
67
llvm::SmallVector<lldb::SBLineEntry> goto_locations =
138
68
GetLineValidEntry (dap, file_spec, goto_line);
139
- if (goto_locations.empty ()) {
140
- response[" success" ] = false ;
141
- response[" message" ] = " Invalid jump location" ;
142
- } else {
143
- llvm::json::Array response_targets;
144
- for (lldb::SBLineEntry &line_entry : goto_locations) {
145
- const uint64_t target_id = dap.gotos .InsertLineEntry (line_entry);
146
- const uint32_t target_line = line_entry.GetLine ();
147
- auto target = llvm::json::Object ();
148
- target.try_emplace (" id" , target_id);
149
-
150
- lldb::SBStream stream;
151
- line_entry.GetDescription (stream);
152
- target.try_emplace (" label" ,
153
- llvm::StringRef (stream.GetData (), stream.GetSize ()));
154
- target.try_emplace (" line" , target_line);
155
- response_targets.push_back (std::move (target));
156
- }
157
-
158
- body.try_emplace (" targets" , std::move (response_targets));
69
+
70
+ if (goto_locations.empty ())
71
+ return llvm::createStringError (" Invalid jump location" );
72
+
73
+ protocol::GotoTargetsResponseBody body{};
74
+
75
+ for (lldb::SBLineEntry &line_entry : goto_locations) {
76
+ const uint64_t target_id = dap.gotos .InsertLineEntry (line_entry);
77
+ const uint32_t target_line = line_entry.GetLine ();
78
+ protocol::GotoTarget target{};
79
+ target.id = target_id;
80
+
81
+ lldb::SBStream stream;
82
+ line_entry.GetDescription (stream);
83
+ target.label = std::string (stream.GetData (), stream.GetSize ());
84
+ target.line = target_line;
85
+ body.targets .emplace_back (target);
159
86
}
160
87
161
- response.try_emplace (" body" , std::move (body));
162
- dap.SendJSON (llvm::json::Value (std::move (response)));
88
+ return body;
163
89
}
164
90
165
91
} // namespace lldb_dap
0 commit comments