7
7
// ===----------------------------------------------------------------------===//
8
8
9
9
#include " DAP.h"
10
- #include " EventHelper.h"
11
- #include " JSONUtils.h"
12
10
#include " RequestHandler.h"
13
11
12
+ using namespace lldb_dap ::protocol;
14
13
namespace lldb_dap {
15
14
16
- // "ScopesRequest": {
17
- // "allOf": [ { "$ref": "#/definitions/Request" }, {
18
- // "type": "object",
19
- // "description": "Scopes request; value of command field is 'scopes'. The
20
- // request returns the variable scopes for a given stackframe ID.",
21
- // "properties": {
22
- // "command": {
23
- // "type": "string",
24
- // "enum": [ "scopes" ]
25
- // },
26
- // "arguments": {
27
- // "$ref": "#/definitions/ScopesArguments"
28
- // }
29
- // },
30
- // "required": [ "command", "arguments" ]
31
- // }]
32
- // },
33
- // "ScopesArguments": {
34
- // "type": "object",
35
- // "description": "Arguments for 'scopes' request.",
36
- // "properties": {
37
- // "frameId": {
38
- // "type": "integer",
39
- // "description": "Retrieve the scopes for this stackframe."
40
- // }
41
- // },
42
- // "required": [ "frameId" ]
43
- // },
44
- // "ScopesResponse": {
45
- // "allOf": [ { "$ref": "#/definitions/Response" }, {
46
- // "type": "object",
47
- // "description": "Response to 'scopes' request.",
48
- // "properties": {
49
- // "body": {
50
- // "type": "object",
51
- // "properties": {
52
- // "scopes": {
53
- // "type": "array",
54
- // "items": {
55
- // "$ref": "#/definitions/Scope"
56
- // },
57
- // "description": "The scopes of the stackframe. If the array has
58
- // length zero, there are no scopes available."
59
- // }
60
- // },
61
- // "required": [ "scopes" ]
62
- // }
63
- // },
64
- // "required": [ "body" ]
65
- // }]
66
- // }
67
-
68
- // / Create a "Scope" JSON object as described in the debug adapter definition.
15
+ // / Creates a `protocol::Scope` struct.
16
+ // /
69
17
// /
70
18
// / \param[in] name
71
19
// / The value to place into the "name" key
72
- //
20
+ // /
73
21
// / \param[in] variablesReference
74
22
// / The value to place into the "variablesReference" key
75
- //
23
+ // /
76
24
// / \param[in] namedVariables
77
25
// / The value to place into the "namedVariables" key
78
- //
26
+ // /
79
27
// / \param[in] expensive
80
28
// / The value to place into the "expensive" key
81
29
// /
82
30
// / \return
83
- // / A "Scope" JSON object with that follows the formal JSON
84
- // / definition outlined by Microsoft.
85
- protocol::Scope CreateScope2 (const llvm::StringRef name,
86
- int64_t variablesReference, int64_t namedVariables,
87
- bool expensive) {
88
- protocol::Scope scope;
89
-
31
+ // / A `protocol::Scope`
32
+ static Scope CreateScope (const llvm::StringRef name, int64_t variablesReference,
33
+ int64_t namedVariables, bool expensive) {
34
+ Scope scope;
90
35
scope.name = name;
91
36
92
- // TODO: Support "arguments" scope. At the moment lldb-dap includes the
93
- // arguments into the "locals" scope.
94
- // add presentation hint;
37
+ // TODO: Support "arguments" and "return value" scope.
38
+ // At the moment lldb-dap includes the arguments and return_value into the
39
+ // "locals" scope. add presentation hint;
40
+ // vscode only expands the first non-expensive scope, this causes friction
41
+ // as the locals scope will not be expanded. It becomes more annoying when
42
+ // the scope has arguments, return_value and locals.
95
43
if (variablesReference == VARREF_LOCALS)
96
- scope.presentationHint = protocol:: Scope::ePresentationHintLocals;
44
+ scope.presentationHint = Scope::ePresentationHintLocals;
97
45
else if (variablesReference == VARREF_REGS)
98
- scope.presentationHint = protocol:: Scope::ePresentationHintRegisters;
46
+ scope.presentationHint = Scope::ePresentationHintRegisters;
99
47
100
48
scope.variablesReference = variablesReference;
101
49
scope.namedVariables = namedVariables;
@@ -104,21 +52,8 @@ protocol::Scope CreateScope2(const llvm::StringRef name,
104
52
return scope;
105
53
}
106
54
107
- static std::vector<protocol::Scope> CreateTopLevelScopes (DAP &dap) {
108
- std::vector<protocol::Scope> scopes;
109
- scopes.reserve (3 );
110
- scopes.emplace_back (CreateScope2 (" Locals" , VARREF_LOCALS,
111
- dap.variables .locals .GetSize (), false ));
112
- scopes.emplace_back (CreateScope2 (" Globals" , VARREF_GLOBALS,
113
- dap.variables .globals .GetSize (), false ));
114
- scopes.emplace_back (CreateScope2 (" Registers" , VARREF_REGS,
115
- dap.variables .registers .GetSize (), false ));
116
-
117
- return scopes;
118
- }
119
-
120
- llvm::Expected<protocol::ScopesResponseBody>
121
- ScopesRequestHandler::Run (const protocol::ScopesArguments &args) const {
55
+ llvm::Expected<ScopesResponseBody>
56
+ ScopesRequestHandler::Run (const ScopesArguments &args) const {
122
57
lldb::SBFrame frame = dap.GetLLDBFrame (args.frameId );
123
58
124
59
// As the user selects different stack frames in the GUI, a "scopes" request
@@ -129,9 +64,9 @@ ScopesRequestHandler::Run(const protocol::ScopesArguments &args) const {
129
64
// are sent, this allows users to type commands in the debugger console
130
65
// with a backtick character to run lldb commands and these lldb commands
131
66
// will now have the right context selected as they are run. If the user
132
- // types "`bt" into the debugger console and we had another thread selected
67
+ // types "`bt" into the debugger console, and we had another thread selected
133
68
// in the LLDB library, we would show the wrong thing to the user. If the
134
- // users switches threads with a lldb command like "`thread select 14", the
69
+ // users switch threads with a lldb command like "`thread select 14", the
135
70
// GUI will not update as there are no "event" notification packets that
136
71
// allow us to change the currently selected thread or frame in the GUI that
137
72
// I am aware of.
@@ -149,7 +84,14 @@ ScopesRequestHandler::Run(const protocol::ScopesArguments &args) const {
149
84
/* in_scope_only=*/ true );
150
85
dap.variables .registers = frame.GetRegisters ();
151
86
152
- return protocol::ScopesResponseBody{CreateTopLevelScopes (dap)};
87
+ std::vector scopes = {CreateScope (" Locals" , VARREF_LOCALS,
88
+ dap.variables .locals .GetSize (), false ),
89
+ CreateScope (" Globals" , VARREF_GLOBALS,
90
+ dap.variables .globals .GetSize (), false ),
91
+ CreateScope (" Registers" , VARREF_REGS,
92
+ dap.variables .registers .GetSize (), false )};
93
+
94
+ return ScopesResponseBody{std::move (scopes)};
153
95
}
154
96
155
97
} // namespace lldb_dap
0 commit comments