From 14c8a546242a5e88ed8f47607629ffbef7d3315d Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Tue, 15 Jul 2025 11:00:04 +0200 Subject: [PATCH 01/10] 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/10] 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/10] 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/10] 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/10] 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/10] 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/10] 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/10] 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/10] 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/10] 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