8
8
9
9
#include " DAP.h"
10
10
#include " EventHelper.h"
11
+ #include " Handler/RequestHandler.h"
11
12
#include " JSONUtils.h"
12
- #include " RequestHandler.h"
13
+ #include " ProtocolUtils.h"
14
+
15
+ using namespace llvm ;
16
+ using namespace lldb_dap ::protocol;
13
17
14
18
namespace lldb_dap {
15
19
16
- // "VariablesRequest": {
17
- // "allOf": [ { "$ref": "#/definitions/Request" }, {
18
- // "type": "object",
19
- // "description": "Variables request; value of command field is 'variables'.
20
- // Retrieves all child variables for the given variable reference. An
21
- // optional filter can be used to limit the fetched children to either named
22
- // or indexed children.", "properties": {
23
- // "command": {
24
- // "type": "string",
25
- // "enum": [ "variables" ]
26
- // },
27
- // "arguments": {
28
- // "$ref": "#/definitions/VariablesArguments"
29
- // }
30
- // },
31
- // "required": [ "command", "arguments" ]
32
- // }]
33
- // },
34
- // "VariablesArguments": {
35
- // "type": "object",
36
- // "description": "Arguments for 'variables' request.",
37
- // "properties": {
38
- // "variablesReference": {
39
- // "type": "integer",
40
- // "description": "The Variable reference."
41
- // },
42
- // "filter": {
43
- // "type": "string",
44
- // "enum": [ "indexed", "named" ],
45
- // "description": "Optional filter to limit the child variables to either
46
- // named or indexed. If ommited, both types are fetched."
47
- // },
48
- // "start": {
49
- // "type": "integer",
50
- // "description": "The index of the first variable to return; if omitted
51
- // children start at 0."
52
- // },
53
- // "count": {
54
- // "type": "integer",
55
- // "description": "The number of variables to return. If count is missing
56
- // or 0, all variables are returned."
57
- // },
58
- // "format": {
59
- // "$ref": "#/definitions/ValueFormat",
60
- // "description": "Specifies details on how to format the Variable
61
- // values."
62
- // }
63
- // },
64
- // "required": [ "variablesReference" ]
65
- // },
66
- // "VariablesResponse": {
67
- // "allOf": [ { "$ref": "#/definitions/Response" }, {
68
- // "type": "object",
69
- // "description": "Response to 'variables' request.",
70
- // "properties": {
71
- // "body": {
72
- // "type": "object",
73
- // "properties": {
74
- // "variables": {
75
- // "type": "array",
76
- // "items": {
77
- // "$ref": "#/definitions/Variable"
78
- // },
79
- // "description": "All (or a range) of variables for the given
80
- // variable reference."
81
- // }
82
- // },
83
- // "required": [ "variables" ]
84
- // }
85
- // },
86
- // "required": [ "body" ]
87
- // }]
88
- // }
89
- void VariablesRequestHandler::operator ()(
90
- const llvm::json::Object &request) const {
91
- llvm::json::Object response;
92
- FillResponse (request, response);
93
- llvm::json::Array variables;
94
- const auto *arguments = request.getObject (" arguments" );
95
- const auto variablesReference =
96
- GetInteger<uint64_t >(arguments, " variablesReference" ).value_or (0 );
97
- const auto start = GetInteger<int64_t >(arguments, " start" ).value_or (0 );
98
- const auto count = GetInteger<int64_t >(arguments, " count" ).value_or (0 );
20
+ // / Retrieves all child variables for the given variable reference.
21
+ // /
22
+ // / A filter can be used to limit the fetched children to either named or
23
+ // / indexed children.
24
+ Expected<VariablesResponseBody>
25
+ VariablesRequestHandler::Run (const VariablesArguments &arguments) const {
26
+ uint64_t var_ref = arguments.variablesReference ;
27
+ uint64_t count = arguments.count ;
28
+ uint64_t start = arguments.start ;
99
29
bool hex = false ;
100
- const auto *format = arguments->getObject (" format" );
101
- if (format)
102
- hex = GetBoolean (format, " hex" ).value_or (false );
30
+ if (arguments.format )
31
+ hex = arguments.format ->hex .value_or (false );
32
+
33
+ std::vector<Variable> variables;
103
34
104
- if (lldb::SBValueList *top_scope =
105
- dap.variables .GetTopLevelScope (variablesReference)) {
35
+ if (lldb::SBValueList *top_scope = dap.variables .GetTopLevelScope (var_ref)) {
106
36
// variablesReference is one of our scopes, not an actual variable it is
107
37
// asking for the list of args, locals or globals.
108
38
int64_t start_idx = 0 ;
109
39
int64_t num_children = 0 ;
110
40
111
- if (variablesReference == VARREF_REGS) {
41
+ if (var_ref == VARREF_REGS) {
112
42
// Change the default format of any pointer sized registers in the first
113
43
// register set to be the lldb::eFormatAddressInfo so we show the pointer
114
44
// and resolve what the pointer resolves to. Only change the format if the
@@ -128,7 +58,7 @@ void VariablesRequestHandler::operator()(
128
58
}
129
59
130
60
num_children = top_scope->GetSize ();
131
- if (num_children == 0 && variablesReference == VARREF_LOCALS) {
61
+ if (num_children == 0 && var_ref == VARREF_LOCALS) {
132
62
// Check for an error in the SBValueList that might explain why we don't
133
63
// have locals. If we have an error display it as the sole value in the
134
64
// the locals.
@@ -145,12 +75,11 @@ void VariablesRequestHandler::operator()(
145
75
// errors are only set when there is a problem that the user could
146
76
// fix, so no error will show up when you have no debug info, only when
147
77
// we do have debug info and something that is fixable can be done.
148
- llvm::json::Object object;
149
- EmplaceSafeString (object, " name" , " <error>" );
150
- EmplaceSafeString (object, " type" , " const char *" );
151
- EmplaceSafeString (object, " value" , var_err);
152
- object.try_emplace (" variablesReference" , (int64_t )0 );
153
- variables.emplace_back (std::move (object));
78
+ Variable var;
79
+ var.name = " <error>" ;
80
+ var.type = " const char *" ;
81
+ var.value = var_err;
82
+ variables.emplace_back (var);
154
83
}
155
84
}
156
85
const int64_t end_idx = start_idx + ((count == 0 ) ? num_children : count);
@@ -165,7 +94,7 @@ void VariablesRequestHandler::operator()(
165
94
}
166
95
167
96
// Show return value if there is any ( in the local top frame )
168
- if (variablesReference == VARREF_LOCALS) {
97
+ if (var_ref == VARREF_LOCALS) {
169
98
auto process = dap.target .GetProcess ();
170
99
auto selected_thread = process.GetSelectedThread ();
171
100
lldb::SBValue stop_return_value = selected_thread.GetStopReturnValue ();
@@ -204,14 +133,13 @@ void VariablesRequestHandler::operator()(
204
133
} else {
205
134
// We are expanding a variable that has children, so we will return its
206
135
// children.
207
- lldb::SBValue variable = dap.variables .GetVariable (variablesReference );
136
+ lldb::SBValue variable = dap.variables .GetVariable (var_ref );
208
137
if (variable.IsValid ()) {
209
138
auto addChild = [&](lldb::SBValue child,
210
139
std::optional<std::string> custom_name = {}) {
211
140
if (!child.IsValid ())
212
141
return ;
213
- bool is_permanent =
214
- dap.variables .IsPermanentVariableReference (variablesReference);
142
+ bool is_permanent = dap.variables .IsPermanentVariableReference (var_ref);
215
143
int64_t var_ref = dap.variables .InsertVariable (child, is_permanent);
216
144
variables.emplace_back (CreateVariable (
217
145
child, var_ref, hex, dap.configuration .enableAutoVariableSummaries ,
@@ -233,10 +161,8 @@ void VariablesRequestHandler::operator()(
233
161
addChild (variable.GetNonSyntheticValue (), " [raw]" );
234
162
}
235
163
}
236
- llvm::json::Object body;
237
- body.try_emplace (" variables" , std::move (variables));
238
- response.try_emplace (" body" , std::move (body));
239
- dap.SendJSON (llvm::json::Value (std::move (response)));
164
+
165
+ return VariablesResponseBody{variables};
240
166
}
241
167
242
168
} // namespace lldb_dap
0 commit comments