irb 1.5.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 33ff0b70fb3730f087bc24a7a8b63253ba1a4ad0416a0ffcd1e5395f26e5d0b2
4
- data.tar.gz: 9cd418e90733c4cb4658368b2a899b50490ad9dbd7352a1c1df0070c10d9669d
3
+ metadata.gz: e7dc14606c6de90f8f56048a7ec6f8ca2bc83a8d4e0aa50d60dbe84141389601
4
+ data.tar.gz: bca1a92ee2088e483073d48dd9e0b3cdbf9b8d67768ed3fd922bb7e91da68039
5
5
  SHA512:
6
- metadata.gz: ec6102a41d55404aa8e5585243cbe74fcdbe1e1d5bcd88ddae4240adff4281d14200b99c621324515a4e226eff5964644a7e8456d707af2ca7dcf8e5211a0b4b
7
- data.tar.gz: 0ed81d78ce49803706b36f36e173acb1e27f3e217bd3c6e00e46d4875b6be3c7958a2cb3db146703c3cbf7198094561a562e0fd244f6a61501f9ae5196df343a
6
+ metadata.gz: b44c813a4fc0010423d0e7ac189dc264ea92587db1b05e16e6c8ec49ff20bc2b4c18b5cfa454543b7d894be0b6610c96a3bf17b85b31d9083d962665063c8a85
7
+ data.tar.gz: af7f077aa6b2c67ccbe67209a35e622bff087a28615b3086a0511188da1b09d2284b662d659d3b308bf251488547aeaecf9da2b29454c2031d52c0e902ba7889
data/Gemfile CHANGED
@@ -11,4 +11,5 @@ group :development do
11
11
  gem "stackprof" if is_unix && !is_truffleruby
12
12
  gem "test-unit"
13
13
  gem "reline", github: "ruby/reline" if ENV["WITH_LATEST_RELINE"] == "true"
14
+ gem "debug"
14
15
  end
data/README.md CHANGED
@@ -90,6 +90,8 @@ The following commands are available on IRB.
90
90
  * Show the source code around binding.irb again.
91
91
  * `debug`
92
92
  * Start the debugger of debug.gem.
93
+ * `break`, `delete`, `next`, `step`, `continue`, `finish`, `backtrace`, `info`, `catch`
94
+ * Start the debugger of debug.gem and run the command on it.
93
95
 
94
96
  ## Documentation
95
97
 
@@ -105,6 +107,13 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
105
107
 
106
108
  Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/irb.
107
109
 
110
+ ## Releasing
111
+
112
+ ```
113
+ rake release
114
+ gh release create vX.Y.Z --generate-notes
115
+ ```
116
+
108
117
  ## License
109
118
 
110
119
  The gem is available as open source under the terms of the [2-Clause BSD License](https://opensource.org/licenses/BSD-2-Clause).
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "debug"
4
+
5
+ module IRB
6
+ # :stopdoc:
7
+
8
+ module ExtendCommand
9
+ class Backtrace < Debug
10
+ def self.transform_args(args)
11
+ args&.dump
12
+ end
13
+
14
+ def execute(*args)
15
+ super(pre_cmds: ["backtrace", *args].join(" "))
16
+ end
17
+ end
18
+ end
19
+
20
+ # :startdoc:
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "debug"
4
+
5
+ module IRB
6
+ # :stopdoc:
7
+
8
+ module ExtendCommand
9
+ class Break < Debug
10
+ def self.transform_args(args)
11
+ args&.dump
12
+ end
13
+
14
+ def execute(args = nil)
15
+ super(pre_cmds: "break #{args}")
16
+ end
17
+ end
18
+ end
19
+
20
+ # :startdoc:
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "debug"
4
+
5
+ module IRB
6
+ # :stopdoc:
7
+
8
+ module ExtendCommand
9
+ class Catch < Debug
10
+ def self.transform_args(args)
11
+ args&.dump
12
+ end
13
+
14
+ def execute(*args)
15
+ super(pre_cmds: ["catch", *args].join(" "))
16
+ end
17
+ end
18
+ end
19
+
20
+ # :startdoc:
21
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "debug"
4
+
5
+ module IRB
6
+ # :stopdoc:
7
+
8
+ module ExtendCommand
9
+ class Continue < Debug
10
+ def execute(*args)
11
+ super(do_cmds: ["continue", *args].join(" "))
12
+ end
13
+ end
14
+ end
15
+
16
+ # :startdoc:
17
+ end
data/lib/irb/cmd/debug.rb CHANGED
@@ -11,7 +11,7 @@ module IRB
11
11
  ].map { |file| /\A#{Regexp.escape(file)}:\d+:in `irb'\z/ }
12
12
  IRB_DIR = File.expand_path('..', __dir__)
13
13
 
14
- def execute(*args)
14
+ def execute(pre_cmds: nil, do_cmds: nil)
15
15
  unless binding_irb?
16
16
  puts "`debug` command is only available when IRB is started with binding.irb"
17
17
  return
@@ -25,11 +25,19 @@ module IRB
25
25
  return
26
26
  end
27
27
 
28
+ options = { oneshot: true, hook_call: false }
29
+ if pre_cmds || do_cmds
30
+ options[:command] = ['irb', pre_cmds, do_cmds]
31
+ end
32
+ if DEBUGGER__::LineBreakpoint.instance_method(:initialize).parameters.include?([:key, :skip_src])
33
+ options[:skip_src] = true
34
+ end
35
+
28
36
  # To make debugger commands like `next` or `continue` work without asking
29
37
  # the user to quit IRB after that, we need to exit IRB first and then hit
30
38
  # a TracePoint on #debug_break.
31
39
  file, lineno = IRB::Irb.instance_method(:debug_break).source_location
32
- DEBUGGER__::SESSION.add_line_breakpoint(file, lineno + 1, oneshot: true, hook_call: false)
40
+ DEBUGGER__::SESSION.add_line_breakpoint(file, lineno + 1, **options)
33
41
  # exit current Irb#run call
34
42
  throw :IRB_EXIT
35
43
  end
@@ -74,14 +82,22 @@ module IRB
74
82
  # it's a bundled gem. This method tries to activate and load that.
75
83
  def load_bundled_debug_gem
76
84
  # Discover latest debug.gem under GEM_PATH
77
- debug_gem = Gem.paths.path.map { |path| Dir.glob("#{path}/gems/debug-*") }.flatten.select do |path|
78
- File.basename(path).match?(/\Adebug-\d+\.\d+\.\d+\z/)
85
+ debug_gem = Gem.paths.path.flat_map { |path| Dir.glob("#{path}/gems/debug-*") }.select do |path|
86
+ File.basename(path).match?(/\Adebug-\d+\.\d+\.\d+(\w+)?\z/)
79
87
  end.sort_by do |path|
80
88
  Gem::Version.new(File.basename(path).delete_prefix('debug-'))
81
89
  end.last
82
90
  return false unless debug_gem
83
91
 
92
+ # Discover debug/debug.so under extensions for Ruby 3.2+
93
+ debug_so = Gem.paths.path.flat_map do |path|
94
+ Dir.glob("#{path}/extensions/**/#{File.basename(debug_gem)}/debug/debug.so")
95
+ end.first
96
+
84
97
  # Attempt to forcibly load the bundled gem
98
+ if debug_so
99
+ $LOAD_PATH << debug_so.delete_suffix('/debug/debug.so')
100
+ end
85
101
  $LOAD_PATH << "#{debug_gem}/lib"
86
102
  begin
87
103
  require "debug/session"
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "debug"
4
+
5
+ module IRB
6
+ # :stopdoc:
7
+
8
+ module ExtendCommand
9
+ class Delete < Debug
10
+ def execute(*args)
11
+ super(pre_cmds: ["delete", *args].join(" "))
12
+ end
13
+ end
14
+ end
15
+
16
+ # :startdoc:
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "debug"
4
+
5
+ module IRB
6
+ # :stopdoc:
7
+
8
+ module ExtendCommand
9
+ class Finish < Debug
10
+ def execute(*args)
11
+ super(do_cmds: ["finish", *args].join(" "))
12
+ end
13
+ end
14
+ end
15
+
16
+ # :startdoc:
17
+ end
data/lib/irb/cmd/info.rb CHANGED
@@ -1,31 +1,18 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
 
3
- require_relative "nop"
3
+ require_relative "debug"
4
4
 
5
5
  module IRB
6
6
  # :stopdoc:
7
7
 
8
8
  module ExtendCommand
9
- class Info < Nop
10
- def execute
11
- Class.new {
12
- def inspect
13
- str = "Ruby version: #{RUBY_VERSION}\n"
14
- str += "IRB version: #{IRB.version}\n"
15
- str += "InputMethod: #{IRB.CurrentContext.io.inspect}\n"
16
- str += ".irbrc path: #{IRB.rc_file}\n" if File.exist?(IRB.rc_file)
17
- str += "RUBY_PLATFORM: #{RUBY_PLATFORM}\n"
18
- str += "LANG env: #{ENV["LANG"]}\n" if ENV["LANG"] && !ENV["LANG"].empty?
19
- str += "LC_ALL env: #{ENV["LC_ALL"]}\n" if ENV["LC_ALL"] && !ENV["LC_ALL"].empty?
20
- str += "East Asian Ambiguous Width: #{Reline.ambiguous_width.inspect}\n"
21
- if RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/
22
- codepage = `chcp`.b.sub(/.*: (\d+)\n/, '\1')
23
- str += "Code page: #{codepage}\n"
24
- end
25
- str
26
- end
27
- alias_method :to_s, :inspect
28
- }.new
9
+ class Info < Debug
10
+ def self.transform_args(args)
11
+ args&.dump
12
+ end
13
+
14
+ def execute(*args)
15
+ super(pre_cmds: ["info", *args].join(" "))
29
16
  end
30
17
  end
31
18
  end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: false
2
+
3
+ require_relative "nop"
4
+
5
+ module IRB
6
+ # :stopdoc:
7
+
8
+ module ExtendCommand
9
+ class IrbInfo < Nop
10
+ def execute
11
+ Class.new {
12
+ def inspect
13
+ str = "Ruby version: #{RUBY_VERSION}\n"
14
+ str += "IRB version: #{IRB.version}\n"
15
+ str += "InputMethod: #{IRB.CurrentContext.io.inspect}\n"
16
+ str += ".irbrc path: #{IRB.rc_file}\n" if File.exist?(IRB.rc_file)
17
+ str += "RUBY_PLATFORM: #{RUBY_PLATFORM}\n"
18
+ str += "LANG env: #{ENV["LANG"]}\n" if ENV["LANG"] && !ENV["LANG"].empty?
19
+ str += "LC_ALL env: #{ENV["LC_ALL"]}\n" if ENV["LC_ALL"] && !ENV["LC_ALL"].empty?
20
+ str += "East Asian Ambiguous Width: #{Reline.ambiguous_width.inspect}\n"
21
+ if RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/
22
+ codepage = `chcp`.b.sub(/.*: (\d+)\n/, '\1')
23
+ str += "Code page: #{codepage}\n"
24
+ end
25
+ str
26
+ end
27
+ alias_method :to_s, :inspect
28
+ }.new
29
+ end
30
+ end
31
+ end
32
+
33
+ # :startdoc:
34
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "debug"
4
+
5
+ module IRB
6
+ # :stopdoc:
7
+
8
+ module ExtendCommand
9
+ class Next < Debug
10
+ def execute(*args)
11
+ super(do_cmds: ["next", *args].join(" "))
12
+ end
13
+ end
14
+ end
15
+
16
+ # :startdoc:
17
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "debug"
4
+
5
+ module IRB
6
+ # :stopdoc:
7
+
8
+ module ExtendCommand
9
+ class Step < Debug
10
+ def execute(*args)
11
+ # Run `next` first to move out of binding.irb
12
+ super(pre_cmds: "next", do_cmds: ["step", *args].join(" "))
13
+ end
14
+ end
15
+ end
16
+
17
+ # :startdoc:
18
+ end
data/lib/irb/context.rb CHANGED
@@ -486,9 +486,9 @@ module IRB
486
486
  @workspace.local_variable_set(:_, exception)
487
487
  end
488
488
 
489
- # Transform a non-identifier alias (ex: @, $)
489
+ # Transform a non-identifier alias (@, $) or keywords (next, break)
490
490
  command, args = line.split(/\s/, 2)
491
- if original = symbol_alias(command)
491
+ if original = command_aliases[command.to_sym]
492
492
  line = line.gsub(/\A#{Regexp.escape(command)}/, original.to_s)
493
493
  command = original
494
494
  end
@@ -545,10 +545,16 @@ module IRB
545
545
  workspace.binding.local_variables
546
546
  end
547
547
 
548
- # Return a command name if it's aliased from the argument and it's not an identifier.
549
- def symbol_alias(command)
548
+ # Return true if it's aliased from the argument and it's not an identifier.
549
+ def symbol_alias?(command)
550
550
  return nil if command.match?(/\A\w+\z/)
551
- command_aliases[command.to_sym]
551
+ command_aliases.key?(command.to_sym)
552
+ end
553
+
554
+ # Return true if the command supports transforming args
555
+ def transform_args?(command)
556
+ command = command_aliases.fetch(command.to_sym, command)
557
+ ExtendCommandBundle.load_command(command)&.respond_to?(:transform_args)
552
558
  end
553
559
  end
554
560
  end
@@ -124,13 +124,48 @@ module IRB # :nodoc:
124
124
  :irb_edit, :Edit, "cmd/edit",
125
125
  [:edit, NO_OVERRIDE],
126
126
  ],
127
+ [
128
+ :irb_break, :Break, "cmd/break",
129
+ ],
130
+ [
131
+ :irb_catch, :Catch, "cmd/catch",
132
+ ],
133
+ [
134
+ :irb_next, :Next, "cmd/next",
135
+ ],
136
+ [
137
+ :irb_delete, :Delete, "cmd/delete",
138
+ [:delete, NO_OVERRIDE],
139
+ ],
140
+ [
141
+ :irb_step, :Step, "cmd/step",
142
+ [:step, NO_OVERRIDE],
143
+ ],
144
+ [
145
+ :irb_continue, :Continue, "cmd/continue",
146
+ [:continue, NO_OVERRIDE],
147
+ ],
148
+ [
149
+ :irb_finish, :Finish, "cmd/finish",
150
+ [:finish, NO_OVERRIDE],
151
+ ],
152
+ [
153
+ :irb_backtrace, :Backtrace, "cmd/backtrace",
154
+ [:backtrace, NO_OVERRIDE],
155
+ [:bt, NO_OVERRIDE],
156
+ ],
157
+ [
158
+ :irb_debug_info, :Info, "cmd/info",
159
+ [:info, NO_OVERRIDE],
160
+ ],
161
+
127
162
  [
128
163
  :irb_help, :Help, "cmd/help",
129
164
  [:help, NO_OVERRIDE],
130
165
  ],
131
166
 
132
167
  [
133
- :irb_info, :Info, "cmd/info"
168
+ :irb_info, :IrbInfo, "cmd/irb_info"
134
169
  ],
135
170
 
136
171
  [
data/lib/irb/init.rb CHANGED
@@ -160,8 +160,13 @@ module IRB # :nodoc:
160
160
  @CONF[:AT_EXIT] = []
161
161
 
162
162
  @CONF[:COMMAND_ALIASES] = {
163
+ # Symbol aliases
163
164
  :'$' => :show_source,
164
165
  :'@' => :whereami,
166
+ # Keyword aliases
167
+ :break => :irb_break,
168
+ :catch => :irb_catch,
169
+ :next => :irb_next,
165
170
  }
166
171
  end
167
172
 
data/lib/irb/ruby-lex.rb CHANGED
@@ -65,9 +65,9 @@ class RubyLex
65
65
  false
66
66
  end
67
67
  else
68
- # Accept any single-line input starting with a non-identifier alias (ex: @, $)
68
+ # Accept any single-line input for symbol aliases or commands that transform args
69
69
  command = code.split(/\s/, 2).first
70
- if context.symbol_alias(command)
70
+ if context.symbol_alias?(command) || context.transform_args?(command)
71
71
  next true
72
72
  end
73
73
 
data/lib/irb/version.rb CHANGED
@@ -11,7 +11,7 @@
11
11
  #
12
12
 
13
13
  module IRB # :nodoc:
14
- VERSION = "1.5.0"
14
+ VERSION = "1.5.1"
15
15
  @RELEASE_VERSION = VERSION
16
- @LAST_UPDATE_DATE = "2022-11-20"
16
+ @LAST_UPDATE_DATE = "2022-11-28"
17
17
  end
data/lib/irb.rb CHANGED
@@ -96,6 +96,8 @@ require_relative "irb/easter-egg"
96
96
  # * Show the source code around binding.irb again.
97
97
  # * debug
98
98
  # * Start the debugger of debug.gem.
99
+ # * break, delete, next, step, continue, finish, backtrace, info, catch
100
+ # * Start the debugger of debug.gem and run the command on it.
99
101
  #
100
102
  # == Configuration
101
103
  #
@@ -470,10 +472,6 @@ module IRB
470
472
  def initialize(workspace = nil, input_method = nil)
471
473
  @context = Context.new(self, workspace, input_method)
472
474
  @context.main.extend ExtendCommandBundle
473
- @context.command_aliases.each do |alias_name, cmd_name|
474
- next if @context.symbol_alias(alias_name)
475
- @context.main.install_alias_method(alias_name, cmd_name)
476
- end
477
475
  @signal_status = :IN_IRB
478
476
  @scanner = RubyLex.new
479
477
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - aycabta
8
8
  - Keiju ISHITSUKA
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-11-21 00:00:00.000000000 Z
12
+ date: 2022-11-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: reline
@@ -46,18 +46,27 @@ files:
46
46
  - exe/irb
47
47
  - irb.gemspec
48
48
  - lib/irb.rb
49
+ - lib/irb/cmd/backtrace.rb
50
+ - lib/irb/cmd/break.rb
51
+ - lib/irb/cmd/catch.rb
49
52
  - lib/irb/cmd/chws.rb
53
+ - lib/irb/cmd/continue.rb
50
54
  - lib/irb/cmd/debug.rb
55
+ - lib/irb/cmd/delete.rb
51
56
  - lib/irb/cmd/edit.rb
57
+ - lib/irb/cmd/finish.rb
52
58
  - lib/irb/cmd/fork.rb
53
59
  - lib/irb/cmd/help.rb
54
60
  - lib/irb/cmd/info.rb
61
+ - lib/irb/cmd/irb_info.rb
55
62
  - lib/irb/cmd/load.rb
56
63
  - lib/irb/cmd/ls.rb
57
64
  - lib/irb/cmd/measure.rb
65
+ - lib/irb/cmd/next.rb
58
66
  - lib/irb/cmd/nop.rb
59
67
  - lib/irb/cmd/pushws.rb
60
68
  - lib/irb/cmd/show_source.rb
69
+ - lib/irb/cmd/step.rb
61
70
  - lib/irb/cmd/subirb.rb
62
71
  - lib/irb/cmd/whereami.rb
63
72
  - lib/irb/color.rb
@@ -101,7 +110,7 @@ licenses:
101
110
  - Ruby
102
111
  - BSD-2-Clause
103
112
  metadata: {}
104
- post_install_message:
113
+ post_install_message:
105
114
  rdoc_options: []
106
115
  require_paths:
107
116
  - lib
@@ -116,8 +125,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
125
  - !ruby/object:Gem::Version
117
126
  version: '0'
118
127
  requirements: []
119
- rubygems_version: 3.3.7
120
- signing_key:
128
+ rubygems_version: 3.3.26
129
+ signing_key:
121
130
  specification_version: 4
122
131
  summary: Interactive Ruby command-line tool for REPL (Read Eval Print Loop).
123
132
  test_files: []