Skip to content

Capture block label with regexp #91

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

Merged
merged 2 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ Attach mode:

Other options:
-h, --help Print help
-c, --command Command mode (first argument is command name)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added these in a separated commit.

--util=NAME Utility mode (used by tools)

NOTE
All messages communicated between a debugger and a debuggee are *NOT* encrypted.
Expand Down
6 changes: 4 additions & 2 deletions lib/debug/frame_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/debug/thread_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
34 changes: 34 additions & 0 deletions test/debug/backtrace_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <main> 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 <main> \(2 levels\) at/)
type 'q!'
end
end
end
end