From 14c8a546242a5e88ed8f47607629ffbef7d3315d Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Tue, 15 Jul 2025 11:00:04 +0200 Subject: [PATCH 01/16] Update imemo_mask to match ruby's The imemo mask has been `0xf` since Ruby 2.5 / ccfe37884ab566336380d0f21e15321d6382da8f This hasn't caused problems yet because the only possible conflict is `imemo_type = 15`, but it is not yet used. --- ext/debug/iseq_collector.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/debug/iseq_collector.c b/ext/debug/iseq_collector.c index ae0beb487..6b8d355a9 100644 --- a/ext/debug/iseq_collector.c +++ b/ext/debug/iseq_collector.c @@ -10,7 +10,7 @@ size_t rb_obj_memsize_of(VALUE); // implementation specific. enum imemo_type { imemo_iseq = 7, - imemo_mask = 0x07 + imemo_mask = 0xf }; static inline enum imemo_type From 2791573fd24aef2091cbb30aa8750f3117781752 Mon Sep 17 00:00:00 2001 From: Dave Lamb Date: Sun, 30 Nov 2025 11:38:40 +0100 Subject: [PATCH 02/16] fix(DAP): Return unverified breakpoints instead of unsuccessful response --- lib/debug/server_dap.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/debug/server_dap.rb b/lib/debug/server_dap.rb index 7502182a4..907db2d1f 100644 --- a/lib/debug/server_dap.rb +++ b/lib/debug/server_dap.rb @@ -358,7 +358,7 @@ def process_request req } send_response req, breakpoints: (bps.map do |bp| {verified: true,} end) else - send_response req, success: false, message: "#{req_path} is not available" + send_response req, breakpoints: (args['breakpoints'].map do |bp| {verified: false, message: "#{req_path} could not be located; specify source location in launch.json with \"localfsMap\" or \"localfs\""} end) end when 'setFunctionBreakpoints' From 06342cd77a11af814c91726f7e5bc3f1974be9df Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 5 Dec 2025 17:18:23 +0900 Subject: [PATCH 03/16] catch any exception on `singletonclass` fix https://github.com/ruby/debug/issues/1162 --- lib/debug/frame_info.rb | 2 +- test/console/backtrace_test.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/debug/frame_info.rb b/lib/debug/frame_info.rb index 8fab332de..558f5466b 100644 --- a/lib/debug/frame_info.rb +++ b/lib/debug/frame_info.rb @@ -171,7 +171,7 @@ def parameters_info private def get_singleton_class obj obj.singleton_class # TODO: don't use it - rescue TypeError + rescue Exception nil end diff --git a/test/console/backtrace_test.rb b/test/console/backtrace_test.rb index 570d66c80..8c6056a6a 100644 --- a/test/console/backtrace_test.rb +++ b/test/console/backtrace_test.rb @@ -229,4 +229,31 @@ def test_backtrace_prints_without_hanging end end end + + class BrokenSingletonMethodBacktraceTest < ConsoleTestCase + def program + <<~RUBY + 1| class C + 2| def self.foo + 3| debugger + 4| end + 5| def singleton_class + 6| raise + 7| end + 8| def self.singleton_class + 9| eval(")") # SyntaxError + 10| end + 11| end + 12| C.foo + RUBY + end + + def test_raise_exception + debug_code program do + type 'c' + assert_line_text(/foo/) + type 'c' + end + end + end end From 1139d781ffde33a1ae6de04e718269cf8e4b0d09 Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 19 Dec 2025 03:26:13 +0900 Subject: [PATCH 04/16] support `b path: path_expr` break on each line on `path_expr`. --- lib/debug/breakpoint.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/debug/breakpoint.rb b/lib/debug/breakpoint.rb index 13e9c428b..78c4d2174 100644 --- a/lib/debug/breakpoint.rb +++ b/lib/debug/breakpoint.rb @@ -23,7 +23,7 @@ def safe_eval b, expr b.eval(expr) rescue Exception => e puts "[EVAL ERROR]" - puts " expr: #{expr}" + puts " expr: #{expr.inspect}" puts " err: #{e} (#{e.class})" puts "Error caused by #{self}." nil @@ -352,7 +352,7 @@ def setup next if ThreadClient.current.management? next if skip_path?(tp.path) - if need_suspend? safe_eval(tp.binding, @cond) + if @cond.nil? || need_suspend?(safe_eval(tp.binding, @cond)) suspend end } From bc97d3387deb4357419e9ebc6c40f809d1858527 Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 19 Dec 2025 03:33:06 +0900 Subject: [PATCH 05/16] add a test for `b path: ...` --- test/console/break_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/console/break_test.rb b/test/console/break_test.rb index 2b8f989ce..4733360ff 100644 --- a/test/console/break_test.rb +++ b/test/console/break_test.rb @@ -255,6 +255,17 @@ def test_break_only_stops_when_path_matches end end + def test_break_only_path + with_extra_tempfile "foohtml" do |extra_file| + debug_code(program(extra_file.path)) do + type "break path: #{extra_file.path}" + type 'c' + assert_line_text(/#{extra_file.path}/) + type 'c' + end + end + end + def test_the_path_option_supersede_skip_path_config # skips the extra_file's breakpoint with_extra_tempfile do |extra_file| From 24f95d637d96d92eb249e1ca45f3550832b5307f Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 19 Dec 2025 03:52:38 +0900 Subject: [PATCH 06/16] catch up 4.0.0 backtrace change --- test/protocol/catch_raw_dap_test.rb | 58 ++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/test/protocol/catch_raw_dap_test.rb b/test/protocol/catch_raw_dap_test.rb index 273c3dd10..3e6a3c437 100644 --- a/test/protocol/catch_raw_dap_test.rb +++ b/test/protocol/catch_raw_dap_test.rb @@ -646,7 +646,9 @@ def test_catching_any_exception_works_correctly success: true, message: "Success", body: { - stackFrames: [ + stackFrames: + RUBY_VERSION < "4.0.0" ? [ + ## { name: "[C] Integer#/", line: 4, @@ -690,6 +692,40 @@ def test_catching_any_exception_works_correctly sourceReference: 0 }, id: 5 + }] : [ + ## RUBY_VERSION >= '4.0.0' + { + name: "Foo::Bar.a", + line: 4, + column: 1, + source: { + name: /#{File.basename temp_file_path}/, + path: /#{temp_file_path}/, + sourceReference: 0 + }, + id: 2 + }, + { + name: "", + line: 7, + column: 1, + source: { + name: /#{File.basename temp_file_path}/, + path: /#{temp_file_path}/, + sourceReference: 0 + }, + id: 3 + }, + { + name: "
", + line: 1, + column: 1, + source: { + name: /#{File.basename temp_file_path}/, + path: /#{temp_file_path}/, + sourceReference: 0 + }, + id: 4 } ] } @@ -738,7 +774,7 @@ def test_catching_any_exception_works_correctly }, type: "request" }, - { + RUBY_VERSION < "4.0.0" ? { seq: 19, type: "response", command: "variables", @@ -765,6 +801,24 @@ def test_catching_any_exception_works_correctly } ] } + } : # RUBY_VERSION >= "4.0.0" + { + "type": "response", + "command": "variables", + "request_seq": 16, + "success": true, + "message": "Success", + "body": { + "variables": [ + { + "name": "%self", + "value": "Foo::Bar", + "type": "Class", + "variablesReference": 5, + "indexedVariables": 0, + "namedVariables": 1 + }] + } }, { seq: 17, From c1c1c8e2533096e82d2888170f18d7cc990407fd Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 5 Dec 2025 18:38:11 +0900 Subject: [PATCH 07/16] use `Kernel.__callee__` for BasicObject fix https://github.com/ruby/debug/issues/1152 --- lib/debug/thread_client.rb | 2 +- test/console/record_test.rb | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/debug/thread_client.rb b/lib/debug/thread_client.rb index 0e1fa42a1..0a92fe356 100644 --- a/lib/debug/thread_client.rb +++ b/lib/debug/thread_client.rb @@ -1310,7 +1310,7 @@ def initialize frame._local_variables = b.local_variables.map{|name| [name, b.local_variable_get(name)] }.to_h - frame._callee = b.eval('__callee__') + frame._callee = b.eval('::Kernel.__callee__') end } append(frames) diff --git a/test/console/record_test.rb b/test/console/record_test.rb index 6b6f99798..9cf32756e 100644 --- a/test/console/record_test.rb +++ b/test/console/record_test.rb @@ -315,4 +315,24 @@ def test_1663647719 end end end + + class RecordOnBasicClassTest < ConsoleTestCase + def program + <<~RUBY + 1| class Test < BasicObject + 2| def test + 3| 42 + 4| end + 5| end + 6| Test.new.test + RUBY + end + + def test_issue1152 + debug_code program do + type 'record on' + type 'c' + end + end + end end From 553373a59f655177dabb2cef952ad1fae1d55fa4 Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 19 Dec 2025 05:00:57 +0900 Subject: [PATCH 08/16] omit on older version because it is fragile. --- test/protocol/eval_test.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/protocol/eval_test.rb b/test/protocol/eval_test.rb index 5f32358f2..8f78128f7 100644 --- a/test/protocol/eval_test.rb +++ b/test/protocol/eval_test.rb @@ -49,6 +49,7 @@ class EvaluateOnSomeFramesTest < ProtocolTestCase RUBY def test_eval_evaluates_arithmetic_expressions + omit 'this test is fragile on older versions' if RUBY_VERSION < '3.4.0' run_protocol_scenario PROGRAM do req_add_breakpoint 4 req_continue From 88d762c8c9b157e3a2627ac3de0df1d5cb8dace5 Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 19 Dec 2025 05:11:08 +0900 Subject: [PATCH 09/16] FileUtils is needed --- lib/debug/console.rb | 1 + lib/debug/server.rb | 1 + test/support/test_case.rb | 1 + 3 files changed, 3 insertions(+) diff --git a/lib/debug/console.rb b/lib/debug/console.rb index ec860b423..211af9e49 100644 --- a/lib/debug/console.rb +++ b/lib/debug/console.rb @@ -163,6 +163,7 @@ def history_file path = File.join(File.expand_path(state_dir), 'rdbg', 'history') end + require 'fileutils' FileUtils.mkdir_p(File.dirname(path)) unless File.exist?(path) path end diff --git a/lib/debug/server.rb b/lib/debug/server.rb index 41f3bca13..0a3c7d266 100644 --- a/lib/debug/server.rb +++ b/lib/debug/server.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'socket' +require 'fileutils' require_relative 'config' require_relative 'version' diff --git a/test/support/test_case.rb b/test/support/test_case.rb index 2d1d26f96..8ae965372 100644 --- a/test/support/test_case.rb +++ b/test/support/test_case.rb @@ -7,6 +7,7 @@ require 'timeout' require 'json' require 'rbconfig' +require 'fileutils' require_relative '../../lib/debug/client' require_relative 'assertions' From bad4d38f8330219b62f2b253d59146f5a71fd39a Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 19 Dec 2025 10:54:49 +0900 Subject: [PATCH 10/16] v1.11.1 --- lib/debug/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/debug/version.rb b/lib/debug/version.rb index 0f05aed8e..d5b3811a8 100644 --- a/lib/debug/version.rb +++ b/lib/debug/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module DEBUGGER__ - VERSION = "1.11.0" + VERSION = "1.11.1" end From 2897edad6d2c2eeb49ffe915192c54572dbe6c82 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Mon, 30 Mar 2026 09:44:38 -0700 Subject: [PATCH 11/16] Scrub invalid UTF-8 bytes from debuggee output in tests setup_remote_debuggee reads lines from PTY and matches them against regexps, but Regexp#=== raises ArgumentError when the line contains invalid UTF-8 byte sequences. This has been causing random CI failures: https://github.com/ruby/ruby/actions/runs/23754369209/job/69204936437 Use String#scrub to replace invalid bytes before matching. --- test/support/test_case.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/support/test_case.rb b/test/support/test_case.rb index 8ae965372..9797975f2 100644 --- a/test/support/test_case.rb +++ b/test/support/test_case.rb @@ -173,6 +173,7 @@ def setup_remote_debuggee(cmd) Timeout.timeout(TIMEOUT_SEC) do line = remote_info.r.gets + line = line.scrub if line remote_info.debuggee_backlog << line # wait for two lines (order is unstable) From 1de33e7405bf479b8fc394b90cb92122c6ffe4db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lara?= Date: Sat, 4 Apr 2026 21:30:20 -0300 Subject: [PATCH 12/16] fix: deadlock using IRB integration on Rails applications When using `debugger` in a rails console using IRB integration, the second `continue` causes a fatal deadlock: "No live threads left. Deadlock?" The root cause is that `leave_subsession` pops `@subsession_stack` and sets `@tc = nil` before `thread_stopper.disable` takes full effect. In that window, the thread_stopper TracePoint fires on the main thread (back in IRB's eval loop), and since `@tc` is nil, the guard `tc == @tc` no longer protects it. The main thread is paused via `on_pause`, but the session server is already blocked on `@q_evt.pop` -- neither can wake the other. The fix for this is addiing `next unless in_subsession?` as the first guard in thread_stopper. Once `leave_subsession` has popped the stack, in_subsession? returns false and the TracePoint becomes a no-op even if it hasn't been disabled yet. --- lib/debug/session.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/debug/session.rb b/lib/debug/session.rb index 3a101d6ee..99c78af1d 100644 --- a/lib/debug/session.rb +++ b/lib/debug/session.rb @@ -1678,6 +1678,14 @@ def get_thread_client th = Thread.current private def thread_stopper TracePoint.new(:line) do + # When leave_subsession pops the subsession stack and sets @tc = nil, + # there is a window before the TracePoint is disabled where this block + # can still fire on other threads. Without this guard, the main thread + # (back in IRB's eval loop) would be paused by on_pause, but the + # session server is already waiting on @q_evt.pop -- causing a mutual + # deadlock ("No live threads left. Deadlock?"). + next unless in_subsession? + # run on each thread tc = ThreadClient.current next if tc.management? From 95997c297acd7adc20be81b52d2d1405805671d2 Mon Sep 17 00:00:00 2001 From: Marin Rukavina Date: Tue, 27 Jan 2026 18:07:56 +0100 Subject: [PATCH 13/16] Fix showing help message on wrong options --- exe/rdbg | 2 +- lib/debug/config.rb | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/exe/rdbg b/exe/rdbg index 52b93d8ce..14b5e978c 100755 --- a/exe/rdbg +++ b/exe/rdbg @@ -1,7 +1,7 @@ #!/usr/bin/env ruby require_relative '../lib/debug/config' -config = DEBUGGER__::Config::parse_argv(ARGV) +config, opt = *DEBUGGER__::Config::parse_argv(ARGV) # mode is not an actual configuration option # it's only used to carry the result of parse_argv here diff --git a/lib/debug/config.rb b/lib/debug/config.rb index 5583671c4..a5af775af 100644 --- a/lib/debug/config.rb +++ b/lib/debug/config.rb @@ -74,7 +74,7 @@ def initialize argv raise 'Can not make multiple configurations in one process' end - config = self.class.parse_argv(argv) + config, _ = *self.class.parse_argv(argv) # apply defaults CONFIG_SET.each do |k, config_detail| @@ -277,12 +277,6 @@ def self.parse_argv argv config[key] = parse_config_value(key, val) end } - return config if !argv || argv.empty? - - if argv.kind_of? String - require 'shellwords' - argv = Shellwords.split(argv) - end require 'optparse' require_relative 'version' @@ -433,6 +427,13 @@ def self.parse_argv argv o.separator ' Please use the remote debugging feature carefully.' end + return [config, opt] if !argv || argv.empty? + + if argv.kind_of? String + require 'shellwords' + argv = Shellwords.split(argv) + end + opt.parse!(argv) if argv.empty? @@ -442,7 +443,7 @@ def self.parse_argv argv end end - config + [config, opt] end def self.config_to_env_hash config From 9dc2024a5a05116b3d38afbc5579d9503d8913f3 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 29 Apr 2026 12:35:05 +0000 Subject: [PATCH 14/16] Update color test for IRB struct member name coloring The latest IRB version wraps struct member names in CYAN, so the expected output in test_colored_inspect_color_objects_if_use_colorize needs to wrap `foo` with CYAN/CLEAR escape sequences. --- test/console/color_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/console/color_test.rb b/test/console/color_test.rb index 8f62dce45..cb3fef1cb 100644 --- a/test/console/color_test.rb +++ b/test/console/color_test.rb @@ -33,7 +33,7 @@ def bar end end - { "#{GREEN}##{CLEAR}\n": dummy_class.new('b'), + { "#{GREEN}##{CLEAR}\n": dummy_class.new('b'), "#{RED}#{BOLD}\"#{CLEAR}#{RED}hoge#{CLEAR}#{RED}#{BOLD}\"#{CLEAR}\n": 'hoge'}.each do |k, v| expected = k.to_s obj = v From ce67347fd16bda4873731cdc8f68a99822981091 Mon Sep 17 00:00:00 2001 From: Arpit Jain Date: Fri, 15 May 2026 14:51:22 +0900 Subject: [PATCH 15/16] ci: declare workflow-level contents: read on 5 workflows Pins the default GITHUB_TOKEN to contents: read on the workflows in .github/workflows/ that don't call a GitHub API beyond the initial checkout. The other workflows in this directory are left implicit because they need write scopes that a maintainer is better placed to declare. Motivation: CVE-2025-30066 (March 2025 tj-actions/changed-files compromise) exfiltrated GITHUB_TOKEN from workflow logs. Per-workflow caps bound runtime authority irrespective of repo or org default, give drift protection if the default ever widens, and are credited per-file by the OpenSSF Scorecard Token-Permissions check. YAML validated locally with yaml.safe_load. Signed-off-by: Arpit Jain --- .github/workflows/protocol.yml | 3 +++ .github/workflows/ruby-macos.yaml | 3 +++ .github/workflows/ruby.yml | 3 +++ .github/workflows/test_test.yml | 3 +++ .github/workflows/truffleruby.yml | 3 +++ 5 files changed, 15 insertions(+) diff --git a/.github/workflows/protocol.yml b/.github/workflows/protocol.yml index fb9c3b204..666ab4375 100644 --- a/.github/workflows/protocol.yml +++ b/.github/workflows/protocol.yml @@ -6,6 +6,9 @@ on: pull_request: branches: [ master ] +permissions: + contents: read + jobs: ruby-versions: uses: ruby/actions/.github/workflows/ruby_versions.yml@master diff --git a/.github/workflows/ruby-macos.yaml b/.github/workflows/ruby-macos.yaml index 6e4d6bc06..e48eeb2cf 100644 --- a/.github/workflows/ruby-macos.yaml +++ b/.github/workflows/ruby-macos.yaml @@ -6,6 +6,9 @@ on: pull_request: branches: [ master ] +permissions: + contents: read + jobs: ruby-versions: uses: ruby/actions/.github/workflows/ruby_versions.yml@master diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 2666dc282..f53c61da7 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -6,6 +6,9 @@ on: pull_request: branches: [ master ] +permissions: + contents: read + jobs: ruby-versions: uses: ruby/actions/.github/workflows/ruby_versions.yml@master diff --git a/.github/workflows/test_test.yml b/.github/workflows/test_test.yml index f4339bf35..72e31affb 100644 --- a/.github/workflows/test_test.yml +++ b/.github/workflows/test_test.yml @@ -6,6 +6,9 @@ on: pull_request: branches: [ master ] +permissions: + contents: read + jobs: ruby-versions: uses: ruby/actions/.github/workflows/ruby_versions.yml@master diff --git a/.github/workflows/truffleruby.yml b/.github/workflows/truffleruby.yml index 2d05d2ce7..a3ec885bd 100644 --- a/.github/workflows/truffleruby.yml +++ b/.github/workflows/truffleruby.yml @@ -6,6 +6,9 @@ on: pull_request: branches: [ master ] +permissions: + contents: read + jobs: truffleruby: runs-on: ubuntu-latest From 6510cfbc7496c55ebbefa437a25c17ca58f7c5eb Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Fri, 12 Jun 2026 09:52:14 +0900 Subject: [PATCH 16/16] Add sleep to USE_TMP_HOME check for macOS C.f. https://github.com/ruby/ruby/pull/12691 --- test/support/console_test_case.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/support/console_test_case.rb b/test/support/console_test_case.rb index 187506e99..b174f9f96 100644 --- a/test/support/console_test_case.rb +++ b/test/support/console_test_case.rb @@ -18,7 +18,7 @@ class ConsoleTestCase < TestCase pwd = Dir.pwd ruby = ENV['RUBY'] || RbConfig.ruby home_cannot_change = false - PTY.spawn({ "HOME" => pwd }, ruby, '-e', 'puts ENV["HOME"]') do |r,| + PTY.spawn({ "HOME" => pwd }, ruby, '-e', 'puts ENV["HOME"]; sleep 0.1') do |r,| home_cannot_change = r.gets.chomp != pwd end !home_cannot_change