debugger: Do not set exception breakpoints in initialization sequence in certain conditions (#33723)

Piotr Osiewicz created

As pointed out in https://github.com/probe-rs/probe-rs/issues/3333, we
violate the spec by sending setExceptionBreakpoints even when the
adapter does not define any exceptions.


Release Notes:

- N/A

Change summary

crates/project/src/debugger/session.rs | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)

Detailed changes

crates/project/src/debugger/session.rs 🔗

@@ -420,6 +420,15 @@ impl RunningMode {
                     .collect::<Vec<_>>()
             })
             .unwrap_or_default();
+        // From spec (on initialization sequence):
+        // client sends a setExceptionBreakpoints request if one or more exceptionBreakpointFilters have been defined (or if supportsConfigurationDoneRequest is not true)
+        //
+        // Thus we should send setExceptionBreakpoints even if `exceptionFilters` variable is empty (as long as there were some options in the first place).
+        let should_send_exception_breakpoints = capabilities
+            .exception_breakpoint_filters
+            .as_ref()
+            .map_or(false, |filters| !filters.is_empty())
+            || !configuration_done_supported;
         let supports_exception_filters = capabilities
             .supports_exception_filter_options
             .unwrap_or_default();
@@ -461,9 +470,12 @@ impl RunningMode {
                     }
                 })?;
 
-                this.send_exception_breakpoints(exception_filters, supports_exception_filters)
-                    .await
-                    .ok();
+                if should_send_exception_breakpoints {
+                    this.send_exception_breakpoints(exception_filters, supports_exception_filters)
+                        .await
+                        .ok();
+                }
+
                 let ret = if configuration_done_supported {
                     this.request(ConfigurationDone {})
                 } else {