Repository: ruby/debug (Ruby)

Issue:
First breakpoint is skipped on a remote development environment
**Describe the bug**

Breakpoint skipped when running on a remote development environment

**To Reproduce**

1. Go to https://github.com/github/codespaces-rails to start with a new Rails app.
2. Choose Use This Template -> Open in a Codespace
3. Create the following in `.vscode/launch.json`
    ```json
       {
        // Use IntelliSense to learn about possible attributes.
        // Hover to view descriptions of existing attributes.
        // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
          {
            "type": "rdbg",
            "name": "Run the current file with rdbg",
            "useBundler": true,
            "request": "launch",
            "command": "ruby",
            "script": "${file}",
          },
        ]
    }
    ```

4. Create the following in `test.rb`.

    ```rb
    a=1
    binding.b
    binding.b
    ```
5. Ensure v0.1.0 of the vscode-rdbg extension is installed.
6. Switch to `test.rb` and choose "Run the current file with rdbg". Observe that it correctly stops at the first breakpoint.
7. Stop the debugger.
8. Add `sleep 1` on a new line after `a=1`
9. Choose "Run the current file with rdbg" again.
10. Observe that it incorrectly skips the first breakpoint and stops at the second.

**Your environment**

* `ruby -v`: ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [x86_64-linux]
* `rdbg -v`: rdbg 1.7.1

**Expected behavior**

It should stop at the first breakpoint.


Discussion: Some further findings on this:

It seems like a race condition. If I add `sleep 0.1` before this line:
 https://github.com/ruby/debug/blob/d7bf3b2e4502eb0f07a67f00e5fce5a0d661189e/lib/debug/server.rb#L350

then it stops at the first breakpoint.

I'm wondering if could relate to https://github.com/ruby/debug/pull/131

Also:

* It doesn't occur when `useTerminal` is enabled.

(cc @st0012)
Additionally, if I set [this](https://github.com/ruby/debug/blob/d7bf3b2e4502eb0f07a67f00e5fce5a0d661189e/lib/debug/server_dap.rb#L478) to `false`, it seems to illustrate that it does stop on the first breakpoint, but immediately continues.

```
[1, 4] in /workspaces/codespaces-rails/test.rb
     1| a = 1
     2| sleep 1
=>   3| binding.b
     4| binding.b
=>#0	<main> at /workspaces/codespaces-rails/test.rb:3
(rdbg:#debugger) eval $stdout.sync=true
[1, 4] in /workspaces/codespaces-rails/test.rb
     1| a = 1
     2| sleep 1
     3| binding.b
=>   4| binding.b
```



Fix (patch):
diff --git a/lib/debug/server_dap.rb b/lib/debug/server_dap.rb
index 8dedcdc7a..b32be9dfd 100644
--- a/lib/debug/server_dap.rb
+++ b/lib/debug/server_dap.rb
@@ -437,10 +437,11 @@ def process
           expr = req.dig('arguments', 'expression')
           if /\A\s*,(.+)\z/ =~ expr
             dbg_expr = $1
+            dbg_expr.split(';;') { |cmd| @q_msg << cmd }
+
             send_response req,
                           result: "",
                           variablesReference: 0
-            debugger do: dbg_expr
           else
             @q_msg << req
           end