Skip to content

Commit ab74900

Browse files
committed
[lldb][lldb-dap] add review changes
1 parent dea97f2 commit ab74900

File tree

8 files changed

+56
-41
lines changed

8 files changed

+56
-41
lines changed

lldb/test/API/tools/lldb-dap/stepInTargets/TestDAP_stepInTargets.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ def test_basic(self):
7979
self.assertIsNotNone(leaf_frame, "expect a leaf frame")
8080
self.assertEqual(step_in_targets[1]["label"], leaf_frame["name"])
8181

82-
def test_supported_capability(self):
82+
@skipIf(archs=no_match(["x86", "x86_64"]))
83+
def test_supported_capability_x86_arch(self):
8384
program = self.getBuildArtifact("a.out")
8485
self.build_and_launch(program)
8586
source = "main.cpp"
@@ -91,18 +92,35 @@ def test_supported_capability(self):
9192
is_supported = self.dap_server.get_initialize_value(
9293
"supportsStepInTargetsRequest"
9394
)
94-
arch: str = self.getArchitecture()
95-
if arch.startswith("x86"):
96-
self.assertTrue(
97-
is_supported,
98-
f"expect capability `stepInTarget` is supported with architecture {arch}",
99-
)
100-
else:
101-
self.assertFalse(
102-
is_supported,
103-
f"expect capability `stepInTarget` is not supported with architecture {arch}",
104-
)
10595

96+
self.assertEqual(
97+
is_supported,
98+
True,
99+
f"expect capability `stepInTarget` is supported with architecture {self.getArchitecture()}",
100+
)
101+
# clear breakpoints.
102+
self.set_source_breakpoints(source, [])
103+
self.continue_to_exit()
104+
105+
@skipIf(archs=["x86", "x86_64"])
106+
def test_supported_capability_other_archs(self):
107+
program = self.getBuildArtifact("a.out")
108+
self.build_and_launch(program)
109+
source = "main.cpp"
110+
bp_lines = [line_number(source, "// set breakpoint here")]
111+
breakpoint_ids = self.set_source_breakpoints(source, bp_lines)
112+
self.assertEqual(
113+
len(breakpoint_ids), len(bp_lines), "expect correct number of breakpoints"
114+
)
115+
is_supported = self.dap_server.get_initialize_value(
116+
"supportsStepInTargetsRequest"
117+
)
118+
119+
self.assertEqual(
120+
is_supported,
121+
False,
122+
f"expect capability `stepInTarget` is not supported with architecture {self.getArchitecture()}",
123+
)
106124
# clear breakpoints.
107125
self.set_source_breakpoints(source, [])
108126
self.continue_to_exit()

lldb/tools/lldb-dap/EventHelper.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,21 @@ static void SendThreadExitedEvent(DAP &dap, lldb::tid_t tid) {
3333
dap.SendJSON(llvm::json::Value(std::move(event)));
3434
}
3535

36-
void SendAdditionalCapabilities(DAP &dap) {
37-
if (dap.target.IsValid()) {
38-
// FIXME: stepInTargets request is only supported by the x86 architecture
39-
// remove when `lldb::InstructionControlFlowKind` is supported by other
40-
// architectures
41-
const llvm::StringRef target_triple = dap.target.GetTriple();
42-
if (!target_triple.starts_with("x86")) {
43-
llvm::json::Object event(CreateEventObject("capabilities"));
44-
llvm::json::Object capabilities{{"supportsStepInTargetsRequest", false}};
36+
void SendTargetBasedCapabilities(DAP &dap) {
37+
if (!dap.target.IsValid())
38+
return;
4539

46-
llvm::json::Object body;
47-
body.try_emplace("capabilities", std::move(capabilities));
48-
event.try_emplace("body", std::move(body));
49-
dap.SendJSON(llvm::json::Value(std::move(event)));
50-
}
51-
}
40+
// FIXME: stepInTargets request is only supported by the x86
41+
// architecture remove when `lldb::InstructionControlFlowKind` is
42+
// supported by other architectures
43+
const llvm::StringRef target_triple = dap.target.GetTriple();
44+
if (target_triple.starts_with("x86"))
45+
return;
46+
47+
protocol::Event event;
48+
event.event = "capabilities";
49+
event.body = llvm::json::Object{{"supportsStepInTargetsRequest", false}};
50+
dap.Send(event);
5251
}
5352
// "ProcessEvent": {
5453
// "allOf": [

lldb/tools/lldb-dap/EventHelper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct DAP;
1616

1717
enum LaunchMethod { Launch, Attach, AttachForSuspendedLaunch };
1818

19-
void SendAdditionalCapabilities(DAP &dap);
19+
void SendTargetBasedCapabilities(DAP &dap);
2020

2121
void SendProcessEvent(DAP &dap, LaunchMethod launch_method);
2222

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ Error AttachRequestHandler::Run(const AttachRequestArguments &args) const {
141141

142142
void AttachRequestHandler::PostRun() const {
143143
dap.SendJSON(CreateEventObject("initialized"));
144-
SendAdditionalCapabilities(dap);
145144
}
146145

147146
} // namespace lldb_dap

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ llvm::Error
3030
ConfigurationDoneRequestHandler::Run(const ConfigurationDoneArguments &) const {
3131
dap.configuration_done = true;
3232

33+
SendTargetBasedCapabilities(dap);
3334
// Ensure any command scripts did not leave us in an unexpected state.
3435
lldb::SBProcess process = dap.target.GetProcess();
3536
if (!process.IsValid() ||

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ Error LaunchRequestHandler::Run(const LaunchRequestArguments &arguments) const {
6868

6969
void LaunchRequestHandler::PostRun() const {
7070
dap.SendJSON(CreateEventObject("initialized"));
71-
SendAdditionalCapabilities(dap);
7271
}
7372

7473
} // namespace lldb_dap

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,7 @@ llvm::json::Value toJSON(const SteppingGranularity &SG) {
582582
llvm_unreachable("unhandled stepping granularity.");
583583
}
584584

585-
bool fromJSON(const llvm::json::Value &Params, StepInTarget &SIT,
586-
llvm::json::Path P) {
585+
bool fromJSON(const json::Value &Params, StepInTarget &SIT, json::Path P) {
587586
json::ObjectMapper O(Params, P);
588587
return O && O.map("id", SIT.id) && O.map("label", SIT.label) &&
589588
O.mapOptional("line", SIT.line) &&
@@ -595,13 +594,13 @@ bool fromJSON(const llvm::json::Value &Params, StepInTarget &SIT,
595594
llvm::json::Value toJSON(const StepInTarget &SIT) {
596595
json::Object target{{"id", SIT.id}, {"label", SIT.label}};
597596

598-
if (SIT.line)
597+
if (SIT.line && *SIT.line != LLDB_INVALID_LINE_NUMBER)
599598
target.insert({"line", SIT.line});
600-
if (SIT.column)
599+
if (SIT.column && *SIT.column != LLDB_INVALID_COLUMN_NUMBER)
601600
target.insert({"column", SIT.column});
602-
if (SIT.endLine)
601+
if (SIT.endLine && *SIT.endLine != LLDB_INVALID_LINE_NUMBER)
603602
target.insert({"endLine", SIT.endLine});
604-
if (SIT.endColumn)
603+
if (SIT.endColumn && *SIT.endLine != LLDB_INVALID_COLUMN_NUMBER)
605604
target.insert({"endColumn", SIT.endColumn});
606605

607606
return target;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -419,26 +419,26 @@ llvm::json::Value toJSON(const SteppingGranularity &);
419419
/// which single target the `stepIn` request should step.
420420
struct StepInTarget {
421421
/// Unique identifier for a step-in target.
422-
uint64_t id = LLDB_INVALID_ADDRESS;
422+
lldb::addr_t id = LLDB_INVALID_ADDRESS;
423423

424424
/// The name of the step-in target (shown in the UI).
425425
std::string label;
426426

427427
/// The line of the step-in target.
428-
std::optional<uint64_t> line;
428+
std::optional<uint32_t> line = LLDB_INVALID_LINE_NUMBER;
429429

430430
/// Start position of the range covered by the step in target. It is measured
431431
/// in UTF-16 code units and the client capability `columnsStartAt1`
432432
/// determines whether it is 0- or 1-based.
433-
std::optional<uint64_t> column;
433+
std::optional<uint32_t> column = LLDB_INVALID_COLUMN_NUMBER;
434434

435435
/// The end line of the range covered by the step-in target.
436-
std::optional<uint64_t> endLine;
436+
std::optional<uint32_t> endLine = LLDB_INVALID_LINE_NUMBER;
437437

438438
/// End position of the range covered by the step in target. It is measured in
439439
/// UTF-16 code units and the client capability `columnsStartAt1` determines
440440
/// whether it is 0- or 1-based.
441-
std::optional<uint64_t> endColumn;
441+
std::optional<uint32_t> endColumn = LLDB_INVALID_COLUMN_NUMBER;
442442
};
443443
bool fromJSON(const llvm::json::Value &, StepInTarget &, llvm::json::Path);
444444
llvm::json::Value toJSON(const StepInTarget &);

0 commit comments

Comments
 (0)