Skip to content

Commit a23cbd6

Browse files
committed
[lldb/test] Update lldbutil.fetch_next_event to match broadcaster class
This patch updates the `lldbutil.fetch_next_event` helper function to either match a specific broadcaster or match a whole broadcaster class. This is very handy when testing process events for interactive scripted process debugging. This also fixes a bug in the failing case, where `SBEvent.GetDescription` expects a `SBStream` argument. We never took that code path in the original implementation so we didn't hit that bug. Differential Revision: https://reviews.llvm.org/D149175 Signed-off-by: Med Ismail Bennani <[email protected]>
1 parent 8b05c0b commit a23cbd6

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lldb/packages/Python/lldbsuite/test/lldbutil.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,18 +1217,25 @@ def start_listening_from(broadcaster, event_mask):
12171217
broadcaster.AddListener(listener, event_mask)
12181218
return listener
12191219

1220-
def fetch_next_event(test, listener, broadcaster, timeout=10):
1220+
def fetch_next_event(test, listener, broadcaster, match_class=False, timeout=10):
12211221
"""Fetch one event from the listener and return it if it matches the provided broadcaster.
1222+
If `match_class` is set to True, this will match an event with an entire broadcaster class.
12221223
Fails otherwise."""
12231224

12241225
event = lldb.SBEvent()
12251226

12261227
if listener.WaitForEvent(timeout, event):
1227-
if event.BroadcasterMatchesRef(broadcaster):
1228-
return event
1228+
if match_class:
1229+
if event.GetBroadcasterClass() == broadcaster:
1230+
return event
1231+
else:
1232+
if event.BroadcasterMatchesRef(broadcaster):
1233+
return event
12291234

1235+
stream = lldb.SBStream()
1236+
event.GetDescription(stream)
12301237
test.fail("received event '%s' from unexpected broadcaster '%s'." %
1231-
(event.GetDescription(), event.GetBroadcaster().GetName()))
1238+
(stream.GetData(), event.GetBroadcaster().GetName()))
12321239

12331240
test.fail("couldn't fetch an event before reaching the timeout.")
12341241

0 commit comments

Comments
 (0)