Skip to content
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

Fix the debug.gem force-loader for Ruby 3.2 #458

Merged
merged 2 commits into from
Nov 28, 2022
Merged
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
12 changes: 10 additions & 2 deletions lib/irb/cmd/debug.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,22 @@ def DEBUGGER__.capture_frames(*args)
# it's a bundled gem. This method tries to activate and load that.
def load_bundled_debug_gem
# Discover latest debug.gem under GEM_PATH
debug_gem = Gem.paths.path.map { |path| Dir.glob("#{path}/gems/debug-*") }.flatten.select do |path|
File.basename(path).match?(/\Adebug-\d+\.\d+\.\d+\z/)
debug_gem = Gem.paths.path.flat_map { |path| Dir.glob("#{path}/gems/debug-*") }.select do |path|
k0kubun marked this conversation as resolved.
Show resolved Hide resolved
File.basename(path).match?(/\Adebug-\d+\.\d+\.\d+(\w+)?\z/)
end.sort_by do |path|
Gem::Version.new(File.basename(path).delete_prefix('debug-'))
end.last
return false unless debug_gem

# Discover debug/debug.so under extensions for Ruby 3.2+
debug_so = Gem.paths.path.flat_map do |path|
k0kubun marked this conversation as resolved.
Show resolved Hide resolved
Dir.glob("#{path}/extensions/**/#{File.basename(debug_gem)}/debug/debug.so")
end.first

# Attempt to forcibly load the bundled gem
if debug_so
$LOAD_PATH << debug_so.delete_suffix('/debug/debug.so')
end
$LOAD_PATH << "#{debug_gem}/lib"
begin
require "debug/session"
Expand Down