The debugger command doesn't seem to work when using multiple threads at the same time.

Open
#1,027 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
ruby
Domain
devtools

Research direction

Start by running the reproduced Ruby program with require "debug", two threads, and debugger statements. Trace how the debugger handles simultaneous thread breakpoints and local-variable evaluation; the fix is complete when each breakpoint reports the matching local variable and continue resumes execution without hanging.

Written by the indexing model from the issue text.

Description

bug

Your environment

  • ruby -v: 3.2.2
  • rdbg -v: 1.8.0

Describe the bug

Doesn't seem to work well with multithreaded debugger statements. The program does not print out expected local variables and seems to hang forever after last continue statement.

To Reproduce

Given the following ruby code:

require "debug"

thr1 = Thread.new {
  hello = "world"

  debugger

  puts hello
}


thr2 = Thread.new {
  hello = "hello"

  debugger

  puts hello
}

thr1.join
thr2.join

The first time I reach a breakpoint it shows me in the hello = "hello" block. When I type out hello though it than jumps me to hello = "world" block. After typing out hello a second time, it prints out the string "hello" instead of "world". If I type continue it hangs forever after that. If I run the program without the debugger statements it doesn't hang.

Expected behavior
I would expect debugger to be somewhat threadsafe. Obviously debugger cannot necessarily control the order of these two debuggers. The second debug statement may execute first but I'd expect that the breakpoint would match the local variable and I'd expect typing continue would than make the program keep running and go to the next debugger statement or terminate the program if no more debugger statements.

Dominant language
Ruby
Stars
1.3k
Forks
146
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ruby/debug

All issues in ruby/debug

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.