diff --git a/README.md b/README.md index 56c3e9f36..bde57edd5 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ The following commands are available on IRB. * Show the source code around binding.irb again. * `debug` * Start the debugger of debug.gem. -* `break`, `delete`, `next`, `step`, `continue`, `finish` +* `break`, `delete`, `next`, `step`, `continue`, `finish`, `backtrace`, `info`, `catch` * Start the debugger of debug.gem and run the command on it. ## Documentation diff --git a/lib/irb.rb b/lib/irb.rb index 6ed7887d2..2db99bcd4 100644 --- a/lib/irb.rb +++ b/lib/irb.rb @@ -96,7 +96,7 @@ # * Show the source code around binding.irb again. # * debug # * Start the debugger of debug.gem. -# * `break`, `delete`, `next`, `step`, `continue`, `finish` +# * break, delete, next, step, continue, finish, backtrace, info, catch # * Start the debugger of debug.gem and run the command on it. # # == Configuration @@ -472,10 +472,6 @@ class Irb def initialize(workspace = nil, input_method = nil) @context = Context.new(self, workspace, input_method) @context.main.extend ExtendCommandBundle - @context.command_aliases.each do |alias_name, cmd_name| - next if @context.symbol_alias?(alias_name) || @context.main.respond_to?(alias_name) - @context.main.install_alias_method(alias_name, cmd_name) - end @signal_status = :IN_IRB @scanner = RubyLex.new end diff --git a/lib/irb/cmd/backtrace.rb b/lib/irb/cmd/backtrace.rb new file mode 100644 index 000000000..ac4f0e0e7 --- /dev/null +++ b/lib/irb/cmd/backtrace.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require_relative "debug" + +module IRB + # :stopdoc: + + module ExtendCommand + class Backtrace < Debug + def self.transform_args(args) + args&.dump + end + + def execute(*args) + super(pre_cmds: ["backtrace", *args].join(" ")) + end + end + end + + # :startdoc: +end diff --git a/lib/irb/cmd/catch.rb b/lib/irb/cmd/catch.rb new file mode 100644 index 000000000..8c9e086a9 --- /dev/null +++ b/lib/irb/cmd/catch.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require_relative "debug" + +module IRB + # :stopdoc: + + module ExtendCommand + class Catch < Debug + def self.transform_args(args) + args&.dump + end + + def execute(*args) + super(pre_cmds: ["catch", *args].join(" ")) + end + end + end + + # :startdoc: +end diff --git a/lib/irb/cmd/info.rb b/lib/irb/cmd/info.rb index 37ecd762f..413c28642 100644 --- a/lib/irb/cmd/info.rb +++ b/lib/irb/cmd/info.rb @@ -1,31 +1,18 @@ -# frozen_string_literal: false +# frozen_string_literal: true -require_relative "nop" +require_relative "debug" module IRB # :stopdoc: module ExtendCommand - class Info < Nop - def execute - Class.new { - def inspect - str = "Ruby version: #{RUBY_VERSION}\n" - str += "IRB version: #{IRB.version}\n" - str += "InputMethod: #{IRB.CurrentContext.io.inspect}\n" - str += ".irbrc path: #{IRB.rc_file}\n" if File.exist?(IRB.rc_file) - str += "RUBY_PLATFORM: #{RUBY_PLATFORM}\n" - str += "LANG env: #{ENV["LANG"]}\n" if ENV["LANG"] && !ENV["LANG"].empty? - str += "LC_ALL env: #{ENV["LC_ALL"]}\n" if ENV["LC_ALL"] && !ENV["LC_ALL"].empty? - str += "East Asian Ambiguous Width: #{Reline.ambiguous_width.inspect}\n" - if RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/ - codepage = `chcp`.b.sub(/.*: (\d+)\n/, '\1') - str += "Code page: #{codepage}\n" - end - str - end - alias_method :to_s, :inspect - }.new + class Info < Debug + def self.transform_args(args) + args&.dump + end + + def execute(*args) + super(pre_cmds: ["info", *args].join(" ")) end end end diff --git a/lib/irb/cmd/irb_info.rb b/lib/irb/cmd/irb_info.rb new file mode 100644 index 000000000..8a4e1bd60 --- /dev/null +++ b/lib/irb/cmd/irb_info.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: false + +require_relative "nop" + +module IRB + # :stopdoc: + + module ExtendCommand + class IrbInfo < Nop + def execute + Class.new { + def inspect + str = "Ruby version: #{RUBY_VERSION}\n" + str += "IRB version: #{IRB.version}\n" + str += "InputMethod: #{IRB.CurrentContext.io.inspect}\n" + str += ".irbrc path: #{IRB.rc_file}\n" if File.exist?(IRB.rc_file) + str += "RUBY_PLATFORM: #{RUBY_PLATFORM}\n" + str += "LANG env: #{ENV["LANG"]}\n" if ENV["LANG"] && !ENV["LANG"].empty? + str += "LC_ALL env: #{ENV["LC_ALL"]}\n" if ENV["LC_ALL"] && !ENV["LC_ALL"].empty? + str += "East Asian Ambiguous Width: #{Reline.ambiguous_width.inspect}\n" + if RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/ + codepage = `chcp`.b.sub(/.*: (\d+)\n/, '\1') + str += "Code page: #{codepage}\n" + end + str + end + alias_method :to_s, :inspect + }.new + end + end + end + + # :startdoc: +end diff --git a/lib/irb/extend-command.rb b/lib/irb/extend-command.rb index f80c060d8..665e05a97 100644 --- a/lib/irb/extend-command.rb +++ b/lib/irb/extend-command.rb @@ -123,6 +123,9 @@ def irb_context [ :irb_break, :Break, "cmd/break", ], + [ + :irb_catch, :Catch, "cmd/catch", + ], [ :irb_next, :Next, "cmd/next", ], @@ -142,6 +145,15 @@ def irb_context :irb_finish, :Finish, "cmd/finish", [:finish, NO_OVERRIDE], ], + [ + :irb_backtrace, :Backtrace, "cmd/backtrace", + [:backtrace, NO_OVERRIDE], + [:bt, NO_OVERRIDE], + ], + [ + :irb_debug_info, :Info, "cmd/info", + [:info, NO_OVERRIDE], + ], [ :irb_help, :Help, "cmd/help", @@ -149,7 +161,7 @@ def irb_context ], [ - :irb_info, :Info, "cmd/info" + :irb_info, :IrbInfo, "cmd/irb_info" ], [ diff --git a/lib/irb/init.rb b/lib/irb/init.rb index 4ca06ba8e..dd888f372 100644 --- a/lib/irb/init.rb +++ b/lib/irb/init.rb @@ -165,6 +165,7 @@ def IRB.init_config(ap_path) :'@' => :whereami, # Keyword aliases :break => :irb_break, + :catch => :irb_catch, :next => :irb_next, } end diff --git a/test/irb/yamatanooroti/test_rendering.rb b/test/irb/yamatanooroti/test_rendering.rb index fe501574d..485fa47c2 100644 --- a/test/irb/yamatanooroti/test_rendering.rb +++ b/test/irb/yamatanooroti/test_rendering.rb @@ -399,6 +399,55 @@ def foo EOC end + def test_backtrace + write_ruby <<~'RUBY' + puts "start IRB" + def foo + binding.irb + end + foo + RUBY + start_terminal(25, 80, %W{ruby -I#{@pwd}/lib #{@ruby_file}}, startup_message: 'start IRB') + write("backtrace\n") + close + assert_include_screen(<<~EOC) + (rdbg:irb) backtrace + =>#0 Object#foo at #{@ruby_file}:3 + #1
at #{@ruby_file}:5 + EOC + end + + def test_info + write_ruby <<~'RUBY' + puts "start IRB" + a = 1 + binding.irb + RUBY + start_terminal(25, 80, %W{ruby -I#{@pwd}/lib #{@ruby_file}}, startup_message: 'start IRB') + write("info\n") + close + assert_include_screen(<<~EOC) + (rdbg:irb) info + %self = main + a = 1 + EOC + end + + def test_catch + write_ruby <<~'RUBY' + puts "start IRB" + binding.irb + raise NotImplementedError + RUBY + start_terminal(25, 80, %W{ruby -I#{@pwd}/lib #{@ruby_file}}, startup_message: 'start IRB') + write("catch NotImplementedError\n") + write("continue\n") + close + assert_include_screen(<<~EOC) + Stop by #0 BP - Catch "NotImplementedError" + EOC + end + private def assert_include_screen(expected)