From 69bafe4392ddfe73e43049136626eae488aa1bd1 Mon Sep 17 00:00:00 2001 From: st0012 Date: Tue, 15 Jun 2021 11:29:18 +0800 Subject: [PATCH 1/2] Update readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 3ff8cac16..d8a9c5c47 100644 --- a/README.md +++ b/README.md @@ -469,6 +469,8 @@ Attach mode: Other options: -h, --help Print help + -c, --command Command mode (first argument is command name) + --util=NAME Utility mode (used by tools) NOTE All messages communicated between a debugger and a debuggee are *NOT* encrypted. From eeb432a01f351f45156aaa9bdec1b2495a37c806 Mon Sep 17 00:00:00 2001 From: st0012 Date: Tue, 15 Jun 2021 12:07:01 +0800 Subject: [PATCH 2/2] Use regexp for more elegant block label capturing This takes block level info into consideration and avoids the issue mentioned in #90. --- lib/debug/frame_info.rb | 6 ++++-- lib/debug/thread_client.rb | 4 ++-- test/debug/backtrace_test.rb | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/lib/debug/frame_info.rb b/lib/debug/frame_info.rb index 0a9dac1eb..fcfa9fa52 100644 --- a/lib/debug/frame_info.rb +++ b/lib/debug/frame_info.rb @@ -57,11 +57,13 @@ def frame_type end end + BLOCK_LABL_REGEXP = /\Ablock( \(\d+ levels\))* in (.+)\z/ + def block_identifier return unless frame_type == :block args = parameters_info(iseq.argc) - _, _, block_loc = location.label.split(" ") - [block_loc, args] + _, level, block_loc = location.label.match(BLOCK_LABL_REGEXP).to_a + [level || "", block_loc, args] end def method_identifier diff --git a/lib/debug/thread_client.rb b/lib/debug/thread_client.rb index b5330ea9b..9e826c2af 100644 --- a/lib/debug/thread_client.rb +++ b/lib/debug/thread_client.rb @@ -27,13 +27,13 @@ def default_frame_formatter frame call_identifier_str = case frame.frame_type when :block - block_loc, args = frame.block_identifier + level, block_loc, args = frame.block_identifier if !args.empty? args_str = " {|#{assemble_arguments(args)}|}" end - "#{colorize_blue("block")}#{args_str} in #{colorize_blue(block_loc)}" + "#{colorize_blue("block")}#{args_str} in #{colorize_blue(block_loc + level)}" when :method ci, args = frame.method_identifier diff --git a/test/debug/backtrace_test.rb b/test/debug/backtrace_test.rb index caf98347a..6fc668bd5 100644 --- a/test/debug/backtrace_test.rb +++ b/test/debug/backtrace_test.rb @@ -68,4 +68,38 @@ def test_backtrace_prints_block_arguments end end end + + class BlockTraceTest < TestCase + def program + <<~RUBY + 1| tap do + 2| tap do + 3| p 1 + 4| end + 5| end + 6| + 7| __END__ + RUBY + end + + def test_backtrace_prints_block_label_correctly + debug_code(program) do + type 'b 2' + type 'c' + type 'bt' + assert_line_text(/block in
at/) + type 'q!' + end + end + + def test_backtrace_prints_nested_block_label_correctly + debug_code(program) do + type 'b 3' + type 'c' + type 'bt' + assert_line_text(/block in
\(2 levels\) at/) + type 'q!' + end + end + end end