Skip to content

Commit 961bd58

Browse files
committed
Reverting some of the changes to the stopped event, I'll follow up with a new PR for that and improving the error reporting for the 'DisassembledInstruction' type.
1 parent a0d09e8 commit 961bd58

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

lldb/test/API/tools/lldb-dap/threads/TestDAP_threads.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_correct_thread(self):
3333
self.dap_server.request_continue()
3434
stopped_event = self.dap_server.wait_for_stopped()
3535
# Verify that the description is the relevant breakpoint,
36-
# preserveFocusHint is False.
36+
# preserveFocusHint is False and threadCausedFocus is True
3737
self.assertTrue(
3838
stopped_event[0]["body"]["description"].startswith(
3939
"breakpoint %s." % breakpoint_ids[0]

lldb/tools/lldb-dap/EventHelper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ llvm::Error SendThreadStoppedEvent(DAP &dap, bool on_entry) {
151151

152152
llvm::DenseSet<lldb::tid_t> old_thread_ids;
153153
old_thread_ids.swap(dap.thread_ids);
154-
uint32_t stop_id = on_entry ? 0 : process.GetStopID();
154+
uint32_t stop_id = process.GetStopID();
155155
const uint32_t num_threads = process.GetNumThreads();
156156

157157
// First make a pass through the threads to see if the focused thread

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -852,22 +852,20 @@ llvm::json::Value toJSON(const DisassembledInstruction::PresentationHint &PH) {
852852

853853
bool fromJSON(const llvm::json::Value &Params, DisassembledInstruction &DI,
854854
llvm::json::Path P) {
855-
std::optional<llvm::StringRef> raw_address =
856-
Params.getAsObject()->getString("address");
857-
if (!raw_address) {
858-
P.report("missing 'address' field");
855+
llvm::json::ObjectMapper O(Params, P);
856+
std::string raw_address;
857+
if (!O || !O.map("address", raw_address))
859858
return false;
860-
}
861859

862-
std::optional<lldb::addr_t> address = DecodeMemoryReference(*raw_address);
860+
std::optional<lldb::addr_t> address = DecodeMemoryReference(raw_address);
863861
if (!address) {
864-
P.report("invalid 'address'");
862+
P.field("address").report("expected string encoded uint64_t");
865863
return false;
866864
}
867865

868866
DI.address = *address;
869-
llvm::json::ObjectMapper O(Params, P);
870-
return O && O.map("instruction", DI.instruction) &&
867+
868+
return O.map("instruction", DI.instruction) &&
871869
O.mapOptional("instructionBytes", DI.instructionBytes) &&
872870
O.mapOptional("symbol", DI.symbol) &&
873871
O.mapOptional("location", DI.location) &&

lldb/tools/lldb-dap/ProtocolUtils.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ std::vector<protocol::Thread> GetThreads(lldb::SBProcess process,
152152
std::lock_guard<lldb::SBMutex> guard(lock);
153153

154154
std::vector<protocol::Thread> threads;
155+
155156
const uint32_t num_threads = process.GetNumThreads();
157+
threads.reserve(num_threads);
156158
for (uint32_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {
157159
lldb::SBThread thread = process.GetThreadAtIndex(thread_idx);
158160
threads.emplace_back(CreateThread(thread, format));

lldb/unittests/DAP/ProtocolTypesTest.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,16 @@ TEST(ProtocolTypesTest, DisassembledInstruction) {
618618
EXPECT_THAT_EXPECTED(
619619
parse<DisassembledInstruction>(R"({"address":1})",
620620
"disassemblyInstruction"),
621-
FailedWithMessage(
622-
"missing 'address' field when parsing disassemblyInstruction"));
621+
FailedWithMessage("expected string at disassemblyInstruction.address"));
622+
EXPECT_THAT_EXPECTED(parse<DisassembledInstruction>(R"({"address":"-1"})",
623+
"disassemblyInstruction"),
624+
FailedWithMessage("expected string encoded uint64_t at "
625+
"disassemblyInstruction.address"));
626+
EXPECT_THAT_EXPECTED(parse<DisassembledInstruction>(
627+
R"({"address":"0xfffffffffffffffffffffffffff"})",
628+
"disassemblyInstruction"),
629+
FailedWithMessage("expected string encoded uint64_t at "
630+
"disassemblyInstruction.address"));
623631
}
624632

625633
TEST(ProtocolTypesTest, Thread) {
@@ -643,8 +651,7 @@ TEST(ProtocolTypesTest, Thread) {
643651

644652
TEST(ProtocolTypesTest, ThreadResponseBody) {
645653
const ThreadsResponseBody body{{{1, "thr1"}, {2, "thr2"}}};
646-
const StringRef json =
647-
R"({
654+
const StringRef json = R"({
648655
"threads": [
649656
{
650657
"id": 1,

0 commit comments

Comments
 (0)