Skip to content

Commit d539169

Browse files
committed
[lldb][lldb-dap] Cleanup
1 parent a29da42 commit d539169

File tree

1 file changed

+30
-88
lines changed

1 file changed

+30
-88
lines changed

lldb/tools/lldb-dap/Handler/ScopesRequestHandler.cpp

Lines changed: 30 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -7,95 +7,43 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "DAP.h"
10-
#include "EventHelper.h"
11-
#include "JSONUtils.h"
1210
#include "RequestHandler.h"
1311

12+
using namespace lldb_dap::protocol;
1413
namespace lldb_dap {
1514

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+
///
6917
///
7018
/// \param[in] name
7119
/// The value to place into the "name" key
72-
//
20+
///
7321
/// \param[in] variablesReference
7422
/// The value to place into the "variablesReference" key
75-
//
23+
///
7624
/// \param[in] namedVariables
7725
/// The value to place into the "namedVariables" key
78-
//
26+
///
7927
/// \param[in] expensive
8028
/// The value to place into the "expensive" key
8129
///
8230
/// \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;
9035
scope.name = name;
9136

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.
9543
if (variablesReference == VARREF_LOCALS)
96-
scope.presentationHint = protocol::Scope::ePresentationHintLocals;
44+
scope.presentationHint = Scope::ePresentationHintLocals;
9745
else if (variablesReference == VARREF_REGS)
98-
scope.presentationHint = protocol::Scope::ePresentationHintRegisters;
46+
scope.presentationHint = Scope::ePresentationHintRegisters;
9947

10048
scope.variablesReference = variablesReference;
10149
scope.namedVariables = namedVariables;
@@ -104,21 +52,8 @@ protocol::Scope CreateScope2(const llvm::StringRef name,
10452
return scope;
10553
}
10654

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 {
12257
lldb::SBFrame frame = dap.GetLLDBFrame(args.frameId);
12358

12459
// As the user selects different stack frames in the GUI, a "scopes" request
@@ -129,9 +64,9 @@ ScopesRequestHandler::Run(const protocol::ScopesArguments &args) const {
12964
// are sent, this allows users to type commands in the debugger console
13065
// with a backtick character to run lldb commands and these lldb commands
13166
// 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
13368
// 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
13570
// GUI will not update as there are no "event" notification packets that
13671
// allow us to change the currently selected thread or frame in the GUI that
13772
// I am aware of.
@@ -149,7 +84,14 @@ ScopesRequestHandler::Run(const protocol::ScopesArguments &args) const {
14984
/*in_scope_only=*/true);
15085
dap.variables.registers = frame.GetRegisters();
15186

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)};
15395
}
15496

15597
} // namespace lldb_dap

0 commit comments

Comments
 (0)