Skip to content

Commit 26f9984

Browse files
committed
[lldb][lldb-dap] add review changes
1 parent b9d8194 commit 26f9984

File tree

4 files changed

+100
-20
lines changed

4 files changed

+100
-20
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ static Scope CreateScope(const llvm::StringRef name, int64_t variablesReference,
4141
// as the locals scope will not be expanded. It becomes more annoying when
4242
// the scope has arguments, return_value and locals.
4343
if (variablesReference == VARREF_LOCALS)
44-
scope.presentationHint = Scope::ePresentationHintLocals;
44+
scope.presentationHint = Scope::eScopePresentationHintLocals;
4545
else if (variablesReference == VARREF_REGS)
46-
scope.presentationHint = Scope::ePresentationHintRegisters;
46+
scope.presentationHint = Scope::eScopePresentationHintRegisters;
4747

4848
scope.variablesReference = variablesReference;
4949
scope.namedVariables = namedVariables;

lldb/tools/lldb-dap/Protocol/ProtocolTypes.cpp

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ bool fromJSON(const json::Value &Params, Source::PresentationHint &PH,
2525
}
2626
std::optional<Source::PresentationHint> hint =
2727
StringSwitch<std::optional<Source::PresentationHint>>(*rawHint)
28-
.Case("normal", Source::ePresentationHintNormal)
29-
.Case("emphasize", Source::ePresentationHintEmphasize)
30-
.Case("deemphasize", Source::ePresentationHintDeemphasize)
28+
.Case("normal", Source::eSourcePresentationHintNormal)
29+
.Case("emphasize", Source::eSourcePresentationHintEmphasize)
30+
.Case("deemphasize", Source::eSourcePresentationHintDeemphasize)
3131
.Default(std::nullopt);
3232
if (!hint) {
3333
P.report("unexpected value");
@@ -43,13 +43,14 @@ bool fromJSON(const json::Value &Params, Source &S, json::Path P) {
4343
O.map("presentationHint", S.presentationHint) &&
4444
O.map("sourceReference", S.sourceReference);
4545
}
46+
4647
llvm::json::Value toJSON(Source::PresentationHint hint) {
4748
switch (hint) {
48-
case Source::ePresentationHintNormal:
49+
case Source::eSourcePresentationHintNormal:
4950
return "normal";
50-
case Source::ePresentationHintEmphasize:
51+
case Source::eSourcePresentationHintEmphasize:
5152
return "emphasize";
52-
case Source::ePresentationHintDeemphasize:
53+
case Source::eSourcePresentationHintDeemphasize:
5354
return "deemphasize";
5455
}
5556
llvm_unreachable("unhandled presentation hint.");
@@ -331,6 +332,41 @@ json::Value toJSON(const Capabilities &C) {
331332
return result;
332333
}
333334

335+
bool fromJSON(const json::Value &Params, Scope::PresentationHint &PH,
336+
json::Path P) {
337+
auto rawHint = Params.getAsString();
338+
if (!rawHint) {
339+
P.report("expected a string");
340+
return false;
341+
}
342+
const std::optional<Scope::PresentationHint> hint =
343+
StringSwitch<std::optional<Scope::PresentationHint>>(*rawHint)
344+
.Case("arguments", Scope::eScopePresentationHintArguments)
345+
.Case("locals", Scope::eScopePresentationHintLocals)
346+
.Case("registers", Scope::eScopePresentationHintRegisters)
347+
.Case("returnValue", Scope::eScopePresentationHintReturnValue)
348+
.Default(std::nullopt);
349+
if (!hint) {
350+
P.report("unexpected value");
351+
return false;
352+
}
353+
PH = *hint;
354+
return true;
355+
}
356+
357+
bool fromJSON(const json::Value &Params, Scope &S, json::Path P) {
358+
json::ObjectMapper O(Params, P);
359+
return O && O.map("name", S.name) &&
360+
O.mapOptional("presentationHint", S.presentationHint) &&
361+
O.map("variablesReference", S.variablesReference) &&
362+
O.mapOptional("namedVariables", S.namedVariables) &&
363+
O.map("indexedVariables", S.indexedVariables) &&
364+
O.mapOptional("source", S.source) && O.map("expensive", S.expensive) &&
365+
O.mapOptional("line", S.line) && O.mapOptional("column", S.column) &&
366+
O.mapOptional("endLine", S.endLine) &&
367+
O.mapOptional("endColumn", S.endColumn);
368+
}
369+
334370
llvm::json::Value toJSON(const Scope &SC) {
335371
llvm::json::Object result{{"name", SC.name},
336372
{"variablesReference", SC.variablesReference},
@@ -339,16 +375,16 @@ llvm::json::Value toJSON(const Scope &SC) {
339375
if (SC.presentationHint.has_value()) {
340376
llvm::StringRef presentationHint;
341377
switch (*SC.presentationHint) {
342-
case Scope::ePresentationHintArguments:
378+
case Scope::eScopePresentationHintArguments:
343379
presentationHint = "arguments";
344380
break;
345-
case Scope::ePresentationHintLocals:
381+
case Scope::eScopePresentationHintLocals:
346382
presentationHint = "locals";
347383
break;
348-
case Scope::ePresentationHintRegisters:
384+
case Scope::eScopePresentationHintRegisters:
349385
presentationHint = "registers";
350386
break;
351-
case Scope::ePresentationHintReturnValue:
387+
case Scope::eScopePresentationHintReturnValue:
352388
presentationHint = "returnValue";
353389
break;
354390
}

lldb/tools/lldb-dap/Protocol/ProtocolTypes.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,9 @@ llvm::json::Value toJSON(const Capabilities &);
284284
/// breakpoints.
285285
struct Source {
286286
enum PresentationHint : unsigned {
287-
ePresentationHintNormal,
288-
ePresentationHintEmphasize,
289-
ePresentationHintDeemphasize,
287+
eSourcePresentationHintNormal,
288+
eSourcePresentationHintEmphasize,
289+
eSourcePresentationHintDeemphasize,
290290
};
291291

292292
/// The short name of the source. Every source returned from the debug adapter
@@ -320,10 +320,10 @@ llvm::json::Value toJSON(const Source &);
320320
/// a source or a range within a source.
321321
struct Scope {
322322
enum PresentationHint : unsigned {
323-
ePresentationHintArguments,
324-
ePresentationHintLocals,
325-
ePresentationHintRegisters,
326-
ePresentationHintReturnValue
323+
eScopePresentationHintArguments,
324+
eScopePresentationHintLocals,
325+
eScopePresentationHintRegisters,
326+
eScopePresentationHintReturnValue
327327
};
328328
/// Name of the scope such as 'Arguments', 'Locals', or 'Registers'. This
329329
/// string is shown in the UI as is and can be translated.
@@ -381,6 +381,9 @@ struct Scope {
381381
/// it is 0- or 1-based.
382382
std::optional<uint64_t> endColumn;
383383
};
384+
bool fromJSON(const llvm::json::Value &Params, Scope::PresentationHint &PH,
385+
llvm::json::Path);
386+
bool fromJSON(const llvm::json::Value &, Scope &, llvm::json::Path);
384387
llvm::json::Value toJSON(const Scope &);
385388

386389
/// The granularity of one `step` in the stepping requests `next`, `stepIn`,

lldb/unittests/DAP/ProtocolTypesTest.cpp

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ TEST(ProtocolTypesTest, Source) {
5050
source.name = "testName";
5151
source.path = "/path/to/source";
5252
source.sourceReference = 12345;
53-
source.presentationHint = ePresentationHintEmphasize;
53+
source.presentationHint = Source::eSourcePresentationHintEmphasize;
5454

5555
llvm::Expected<Source> deserialized_source = roundtrip(source);
5656
ASSERT_THAT_EXPECTED(deserialized_source, llvm::Succeeded());
@@ -132,3 +132,44 @@ TEST(ProtocolTypesTest, Breakpoint) {
132132
EXPECT_EQ(breakpoint.offset, deserialized_breakpoint->offset);
133133
EXPECT_EQ(breakpoint.reason, deserialized_breakpoint->reason);
134134
}
135+
136+
TEST(ProtocolTypesTest, Scope) {
137+
Scope scope;
138+
scope.name = "Locals";
139+
scope.presentationHint = Scope::eScopePresentationHintLocals;
140+
scope.variablesReference = 1;
141+
scope.namedVariables = 2;
142+
scope.indexedVariables = std::nullopt;
143+
scope.expensive = false;
144+
scope.line = 2;
145+
scope.column = 3;
146+
scope.endLine = 10;
147+
scope.endColumn = 20;
148+
149+
scope.source =
150+
Source{.name = "testName",
151+
.path = "/path/to/source",
152+
.sourceReference = 12345,
153+
.presentationHint = Source::eSourcePresentationHintNormal};
154+
155+
llvm::Expected<Scope> deserialized_scope = roundtrip(scope);
156+
ASSERT_THAT_EXPECTED(deserialized_scope, llvm::Succeeded());
157+
EXPECT_EQ(scope.name, deserialized_scope->name);
158+
EXPECT_EQ(scope.presentationHint, deserialized_scope->presentationHint);
159+
EXPECT_EQ(scope.variablesReference, deserialized_scope->variablesReference);
160+
EXPECT_EQ(scope.namedVariables, deserialized_scope->namedVariables);
161+
EXPECT_EQ(scope.indexedVariables, deserialized_scope->indexedVariables);
162+
EXPECT_EQ(scope.expensive, deserialized_scope->expensive);
163+
EXPECT_EQ(scope.line, deserialized_scope->line);
164+
EXPECT_EQ(scope.column, deserialized_scope->column);
165+
EXPECT_EQ(scope.endLine, deserialized_scope->endLine);
166+
EXPECT_EQ(scope.endColumn, deserialized_scope->endColumn);
167+
168+
EXPECT_THAT(deserialized_scope->source.has_value(), true);
169+
const Source &source = scope.source.value();
170+
const Source &deserialized_source = deserialized_scope->source.value();
171+
172+
EXPECT_EQ(source.path, deserialized_source.path);
173+
EXPECT_EQ(source.sourceReference, deserialized_source.sourceReference);
174+
EXPECT_EQ(source.presentationHint, deserialized_source.presentationHint);
175+
}

0 commit comments

Comments
 (0)