Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected stoppage on remote debugging connection #629

Closed
st0012 opened this issue Apr 22, 2022 · 14 comments · Fixed by #688
Closed

Unexpected stoppage on remote debugging connection #629

st0012 opened this issue Apr 22, 2022 · 14 comments · Fixed by #688
Milestone

Comments

@st0012
Copy link
Member

st0012 commented Apr 22, 2022

Recently I mostly use remote debugging and this trap (https://github.com/ruby/debug/blob/master/lib/debug/server.rb#L229) means the program (usually Rails server) will be stopped upon connection, even with the nonstop flag.

And I'll need to manually skip the first few frames every time the connection is established, which is annoying. One example:

❯ ~/projects/debug/exe/rdbg -A
# No sourcefile available for /Users/st0012/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/puma-5.6.2/lib/puma/single.rb
=>#0    [C] Thread#join at ~/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/puma-5.6.2/lib/puma/single.rb:61
  #1    Puma::Single#run at ~/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/puma-5.6.2/lib/puma/single.rb:61
  # and 16 frames (use `bt' command for all frames)

Stop by SIGURG
(rdbg:remote)

So my questions are:

  1. Why does the debugger need to stop for this signal?

  2. If it's needed in some cases, can we skip this behavior when nonstop flag is used?

  3. Why should the debuggee be paused with signal by itself upon activation? The stoppage is triggered by the debugger server itself (pause source)

@ko1
Copy link
Collaborator

ko1 commented Apr 22, 2022

Why does the debugger need to stop for this signal?

This behavior is same as gdb -p.
It is useful to analyze what happens on the program.

If it's needed in some cases, can we skip this behavior when nonstop flag is used?

Now non-stop flag is debuggee's flag.
rdbg -An can be more useful to control the behavior?

@st0012
Copy link
Member Author

st0012 commented Apr 23, 2022

rdbg -An can be more useful to control the behavior?

I used rdbg -A for demonstrating the issue but usually we use it with VSCode. So ideally it should be set from the debuggee along with nonstop too.

It is useful to analyze what happens on the program.

For the use cases I see (mostly attaching to a Rails server), I don't see much need for that. But it stopping at places like puma's internal (as shown above) is confusing and annoying.

Let me also explain how we use the debugger with our development tooling:

  1. Define a server service with debugger enabled:
server: rdbg -O -n --sock-path=$RUBY_DEBUG_SOCK_DIR/ruby-debug-server -- bin/rails s
  1. Start the server service for developer server.
  2. When we want to add breakpoints, we write debug statements (binding.b) in code and restart the server service. (Most people are still used this way to add bps)
  3. Attach to the debuggee from VSCode.

And ideally, the server should run normally until we hit the breakpoint after reloading the page or making a request. But we always end up stopping at this place and then need to click continue multiple times.

截圖 2022-04-23 09 18 30

So IMO, it'd be great to make it optional and also non-default.

@st0012

This comment was marked as outdated.

@st0012

This comment was marked as outdated.

@st0012
Copy link
Member Author

st0012 commented Apr 24, 2022

Ah the signal is always triggered by the debugger server itself (pause source). So which signal it uses doesn't matter for this issue.
This behavior seems to be introduced in bb5e5c3

@st0012 st0012 changed the title Unexpected stoppage by SIGURG signal Unexpected stoppage on remote debugging connection Apr 24, 2022
@bfad
Copy link

bfad commented Apr 29, 2022

For me, it also seems to lose the attached debugger sometimes on subsequent requests. The server would say "wait for debugger connection..." while the client debugger that was attached would be blocked waiting — even ctrl-C would do nothing.

@ko1 ko1 added this to the v1.6.0 milestone May 17, 2022
@ko1
Copy link
Collaborator

ko1 commented Jul 6, 2022

I understand the scenario on #629 (comment).
If we do "nonstop" at attach, we need to show "Enter Ctrl-C to enter REPL mode" or something like that (now it is not clear only hangs or connected without any messages).

I used rdbg -A for demonstrating the issue but usually we use it with VSCode. So ideally it should be set from the debuggee along with nonstop too.

We can consider separately with 'rdbg -A` and attach on VSCode (or not sure it should be same or not). For example, we can add another setting (like "nonstop": true) in launch.json.

But we always end up stopping at this place and then need to click continue multiple times.

At least, it should be one click.


  • Stop on attach:
    • We can see what kind of code are working at attach timing. It will help when the program seems hangs up.
    • We can use REPL immediately.
    • We can set breakpoints on running process with clicking on VSCode (and so on).
    • Other debuggers VS, gdb, lldb does this behavior, because maybe they need to setup breakpoints and so on for debugging.
  • Nonstop on attach:
  • Do not need to enter "c" for continue or continue button on the VSCode, and wait for the breakpoints.
  • This is default behavior of "launch" mode on VSCode (do not stop until breakpoints).

Could you check other debugger's (python, go, ...) attach behavior on VSCode?
(or I'll check)


There are another aspect: breakpoints (set by command or debugger method) should stop or not when the remote debugger client is not connected.
Now (1) it waits for client connection, but it is possible to (2) skip breakpoints if the client is not connected.
If we set debuggee's -n as nonstop at attach, I think (2) can be applied (I don't say it should be).

@ko1
Copy link
Collaborator

ko1 commented Jul 6, 2022

So I prefer:

  • Attach clients should setup nonstop:
    • rdbg -nA
    • "nonstop": true in launch.json on VSCode attach configuration.

I think the same default behavior with other debuggers is good, so it it is my current consideration.

@st0012
Copy link
Member Author

st0012 commented Jul 7, 2022

we need to show "Enter Ctrl-C to enter REPL mode" or something like that

👍 good call

Attach clients should setup nonstop:

I like the client configuration idea, but I think for users it'll be hard to understand the difference between server's nonstop and the client's nonstop. Perhaps a different name will be better, like --wait. It'll mean waiting for breakpoints to stop.

I also hope this behavior can also be configured on the server side, with something like RUBY_DEBUG_CLIENT_CONNECTION_STOP=false.

@ko1
Copy link
Collaborator

ko1 commented Jul 7, 2022

I checked the following GUI tool to attach and all of them do not stop the debuggee:

  • VSCode
    • Go
    • JavaScript
    • Python
    • C
  • Visual Studio with C (asm)
  • (I can not use attach on RubyMine)

So I changed my mind for nonstop on attaching with DAP.

On the CUI attachment, I confirmed that gcc/lldb/dlv (Golang) do stop at attach, so I remain the current behavior.

@ko1
Copy link
Collaborator

ko1 commented Jul 7, 2022

On the JavaScript with nodejs, I found interesting that it doesn't stop at debugger statement when client is not attached.
So NodeJS is one example of:

There are another aspect: breakpoints (set by command or debugger method) should stop or not when the remote debugger client is not connected.

@st0012
Copy link
Member Author

st0012 commented Jul 7, 2022

With nodejs's default debugger, the CUI doesn't stop at connection. It only stops when it hits the breakpoint.

// test.js
i = 0
while (i >= 0) {
  console.log(i);
  i++;
  if (i >= 3000000) {
    debugger;
  }
}

Terminal1

$ node --inspect test.js

Terminal2

Initially it'll be:

$ node inspect -p <pid>
connecting to 127.0.0.1:9229 ... ok
>

And when it hits the breakpoint, the source will be shown and the program will only stop then:

$ node inspect -p <pid>
connecting to 127.0.0.1:9229 ... ok
break in test.js:6
  4   i++;
  5   if (i >= 3000000) {
> 6     debugger;
  7   }
  8 }
debug> repl
Press Ctrl+C to leave debug repl
> i
3000000
>

So I changed my mind for nonstop on attaching with DAP.

Does that mean DAP won't stop even without -n specified?

@ko1
Copy link
Collaborator

ko1 commented Jul 7, 2022

Does that mean DAP won't stop even without -n specified?

yes.

st0012 added a commit to st0012/debug that referenced this issue Jul 7, 2022
@st0012
Copy link
Member Author

st0012 commented Jul 7, 2022

@ko1 I've updated my PR to only skip DAP's connection stop.

ko1 added a commit that referenced this issue Jul 8, 2022
@ko1 ko1 closed this as completed in #688 Jul 8, 2022
ko1 added a commit that referenced this issue Jul 8, 2022
st0012 pushed a commit to ruby-tooling/ruby-debugger that referenced this issue Jul 8, 2022
st0012 pushed a commit to ruby-tooling/ruby-debugger that referenced this issue Jul 10, 2022
freesteph added a commit to betagouv/aplypro that referenced this issue Mar 25, 2024
The command needs the `nonstop` (-n) flag for reasons I didn't fully
understand.

ruby/debug#629
freesteph added a commit to betagouv/aplypro that referenced this issue Mar 25, 2024
The command needs the `nonstop` (-n) flag for reasons I didn't fully
understand.

ruby/debug#629
freesteph added a commit to betagouv/aplypro that referenced this issue Mar 25, 2024
The command needs the `nonstop` (-n) flag for reasons I didn't fully
understand.

ruby/debug#629
freesteph added a commit to betagouv/aplypro that referenced this issue Mar 25, 2024
The command needs the `nonstop` (-n) flag for reasons I didn't fully
understand.

ruby/debug#629
freesteph added a commit to betagouv/aplypro that referenced this issue Mar 26, 2024
The command needs the `nonstop` (-n) flag for reasons I didn't fully
understand.

ruby/debug#629
JeSuisUnCaillou pushed a commit to betagouv/aplypro that referenced this issue Mar 26, 2024
The command needs the `nonstop` (-n) flag for reasons I didn't fully
understand.

ruby/debug#629
freesteph added a commit to betagouv/aplypro that referenced this issue Mar 26, 2024
The command needs the `nonstop` (-n) flag for reasons I didn't fully
understand.

ruby/debug#629
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants