Skip to content

Commit 47b5695

Browse files
committed
Support changed event too
1 parent 681beb0 commit 47b5695

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

lldb/test/API/tools/lldb-dap/module/TestDAP_module.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,25 @@ def checkSymbolsLoadedWithSize():
5858
self.assertIn("addressRange", program_module)
5959

6060
# Collect all the module names we saw as events.
61-
module_event_names = set()
61+
module_new_names = []
62+
module_changed_names = []
6263
for module_event in self.dap_server.module_events:
63-
module_event_names.add(module_event["body"]["module"]["name"])
64-
self.assertNotEqual(len(module_event_names), 0)
64+
module_name = module_event["body"]["module"]["name"]
65+
reason = module_event["body"]["reason"]
66+
if reason == "new":
67+
module_new_names.append(module_name)
68+
elif reason == "changed":
69+
module_changed_names.append(module_name)
6570

6671
# Make sure we got an event for every active module.
72+
self.assertNotEqual(len(module_new_names), 0)
6773
for module in active_modules:
68-
# assertIn doesn't work with set.
69-
self.assertTrue(module in module_event_names)
74+
self.assertIn(module, module_new_names)
75+
76+
# Make sure we got an update event for the program module when the
77+
# symbols got added.
78+
self.assertNotEqual(len(module_changed_names), 0)
79+
self.assertIn(program_module["name"], module_changed_names)
7080

7181
@skipIfWindows
7282
def test_modules(self):

lldb/tools/lldb-dap/DAP.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,9 @@ void DAP::SetTarget(const lldb::SBTarget target) {
694694
this->target.GetBroadcaster(),
695695
lldb::SBTarget::eBroadcastBitBreakpointChanged |
696696
lldb::SBTarget::eBroadcastBitModulesLoaded |
697-
lldb::SBTarget::eBroadcastBitModulesUnloaded);
697+
lldb::SBTarget::eBroadcastBitModulesUnloaded |
698+
lldb::SBTarget::eBroadcastBitSymbolsLoaded |
699+
lldb::SBTarget::eBroadcastBitSymbolsChanged);
698700
listener.StartListeningForEvents(this->broadcaster,
699701
eBroadcastBitStopEventThread);
700702
}

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ void ProgressEventThreadFunction(DAP &dap) {
110110
}
111111
}
112112

113+
static llvm::StringRef GetModuleEventReason(uint32_t event_mask) {
114+
if (event_mask & lldb::SBTarget::eBroadcastBitModulesLoaded)
115+
return "new";
116+
if (event_mask & lldb::SBTarget::eBroadcastBitModulesUnloaded)
117+
return "removed";
118+
assert(event_mask & lldb::SBTarget::eBroadcastBitSymbolsLoaded ||
119+
event_mask & lldb::SBTarget::eBroadcastBitSymbolsChanged);
120+
return "changed";
121+
}
122+
113123
// All events from the debugger, target, process, thread and frames are
114124
// received in this function that runs in its own thread. We are using a
115125
// "FILE *" to output packets back to VS Code and they have mutexes in them
@@ -197,11 +207,10 @@ static void EventThreadFunction(DAP &dap) {
197207
}
198208
} else if (lldb::SBTarget::EventIsTargetEvent(event)) {
199209
if (event_mask & lldb::SBTarget::eBroadcastBitModulesLoaded ||
200-
event_mask & lldb::SBTarget::eBroadcastBitModulesUnloaded) {
201-
const llvm::StringRef reason =
202-
event_mask & lldb::SBTarget::eBroadcastBitModulesLoaded
203-
? "new"
204-
: "removed";
210+
event_mask & lldb::SBTarget::eBroadcastBitModulesUnloaded ||
211+
event_mask & lldb::SBTarget::eBroadcastBitSymbolsLoaded ||
212+
event_mask & lldb::SBTarget::eBroadcastBitSymbolsChanged) {
213+
llvm::StringRef reason = GetModuleEventReason(event_mask);
205214
const uint32_t num_modules = SBTarget::GetNumModulesFromEvent(event);
206215
for (uint32_t i = 0; i < num_modules; ++i) {
207216
lldb::SBModule module =

0 commit comments

Comments
 (0)