pass $name
}
-# A helper for dap_read_event that reads events, looking for one
+# A helper for dap_wait_for_event_and_check that reads events, looking for one
# matching TYPE.
-proc _dap_wait_for_event {type} {
+#
+# Return a list of two items:
+#
+# - the matched event
+# - a list of any JSON objects (events or others) seen before the matched
+# event.
+proc _dap_wait_for_event { {type ""} } {
+ set preceding [list]
+
while 1 {
# We don't do any extra error checking here for the time
# being; we'll just get a timeout thrown instead.
set d [_dap_read_json]
if {[dict get $d type] == "event"
- && [dict get $d event] == $type} {
- return $d
+ && ($type == "" || [dict get $d event] == $type)} {
+ return [list $d $preceding]
}
+
+ lappend preceding $d
}
}
# are used to check fields of the event; the arguments alternate
# between a field name (in "dict get" form) and its expected value.
#
-# Returns the dict for the chosen event, or empty string on error.
+# Return a list of two items:
+#
+# - the matched event (regardless of whether it passed the field validation or
+# not)
+# - a list of any JSON objects (events or others) seen before the matched
+# event.
proc dap_wait_for_event_and_check {name type args} {
if {$name == ""} {
set name $type
}
set result [_dap_wait_for_event $type]
- eval dap_match_values [list $name $result] $args
+ set event [lindex $result 0]
+ eval dap_match_values [list $name $event] $args
return $result
}