From 23cb4aeb8356faa31d4f99c350cddd23b167b350 Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Wed, 2 Nov 2022 03:40:57 +0900 Subject: [PATCH] `step into ` `step into ` stops at the beggining of the method ``. `into` is added because there are alreay `step back` and `step reset` commands. fix https://github.com/ruby/debug/issues/655 --- lib/debug/session.rb | 10 ++++++++++ lib/debug/thread_client.rb | 11 +++++++++-- test/console/control_flow_commands_test.rb | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/debug/session.rb b/lib/debug/session.rb index d65e528b0..516859a86 100644 --- a/lib/debug/session.rb +++ b/lib/debug/session.rb @@ -426,6 +426,8 @@ def process_command line # * Step in. Resume the program until next breakable point. # * `s[tep] ` # * Step in, resume the program at ``th breakable point. + # * `s[tep] into ` or `s[tep] into /regexp/` + # * Stop at the beggining of method `` or the name matched to `/regexp/` when 's', 'step' cancel_auto_continue check_postmortem @@ -1077,6 +1079,14 @@ def step_command type, arg iter = $2&.to_i request_tc [:step, type, iter] end + when /\Ainto\s+(\S+)(\s+(\d+))?\z/ + pat = $1 + iter = $3&.to_i + if /\A\/(.+)\/\z/ =~ pat + pat = Regexp.new($1) + end + + request_tc [:step, :into, pat, iter] else @ui.puts "Unknown option: #{arg}" :retry diff --git a/lib/debug/thread_client.rb b/lib/debug/thread_client.rb index 21885cd3d..7f365356d 100644 --- a/lib/debug/thread_client.rb +++ b/lib/debug/thread_client.rb @@ -336,7 +336,7 @@ def step_tp iter, events = [:line, :b_return, :return] tp.disable next end - next if !yield(tp.event) + next if !yield(tp) next if tp.path.start_with?(__dir__) next if tp.path.start_with?('') next unless File.exist?(tp.path) if CONFIG[:skip_nosrc] @@ -355,7 +355,7 @@ def step_tp iter, events = [:line, :b_return, :return] tp.disable next end - next if !yield(tp.event) + next if !yield(tp) next if tp.path.start_with?(__dir__) next if tp.path.start_with?('') next unless File.exist?(tp.path) if CONFIG[:skip_nosrc] @@ -859,6 +859,13 @@ def wait_next_action_ break end + when :into + pat, iter = args[1], args[2] + step_tp iter, [:call, :c_call] do |tp| + pat === tp.callee_id.to_s + end + break + when :next frame = @target_frames.first path = frame.location.absolute_path || "!eval:#{frame.path}" diff --git a/test/console/control_flow_commands_test.rb b/test/console/control_flow_commands_test.rb index 12a3ae3e9..497c59432 100644 --- a/test/console/control_flow_commands_test.rb +++ b/test/console/control_flow_commands_test.rb @@ -63,6 +63,20 @@ def test_step_with_number_goes_to_the_next_nth_statement end end + def test_step_into + debug_code program do + type 'step into name' + assert_line_num 7 + type 'step into xyzzy' # doesn't match + end + + debug_code program do + type 'step into /.ame/' + assert_line_num 7 + type 'step into xyzzy' # doesn't match + end + end + def test_next_goes_to_the_next_line debug_code(program) do type 'b 11'