Skip to content

Commit

Permalink
Merge pull request #847 from marshall-lee/tracepoint-allow-reentry
Browse files Browse the repository at this point in the history
 Use TracePoint.allow_reentry to support TracePoint events while eval
  • Loading branch information
deivid-rodriguez authored Aug 1, 2024
2 parents ddad523 + ba2240c commit 7e73848
Show file tree
Hide file tree
Showing 20 changed files with 215 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
fail-fast: false

matrix:
version: [2.5.8, 2.6.6, 2.7.2]
version: [2.5.9, 2.6.10, 2.7.8, 3.0.6, 3.1.4, 3.2.2]
line_editor: [libedit, readline]
compiler: [clang, gcc]

Expand Down
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require:
AllCops:
Exclude:
- tmp/**/*
- bin/*

DisplayCopNames: true
DisplayStyleGuide: true
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ DEPENDENCIES
yard (= 0.9.26)

BUNDLED WITH
2.2.0.rc.2
2.3.26
94 changes: 83 additions & 11 deletions bin/bundle
Original file line number Diff line number Diff line change
@@ -1,42 +1,114 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'bundle' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "rubygems"

m = Module.new do
extend self
module_function

def invoked_as_script?
File.expand_path($0) == File.expand_path(__FILE__)
end

def env_var_version
ENV["BUNDLER_VERSION"]
end

def cli_arg_version
return unless invoked_as_script? # don't want to hijack other binstubs
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
bundler_version = nil
update_index = nil
ARGV.each_with_index do |a, i|
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
bundler_version = a
end
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
bundler_version = $1
update_index = i
end
bundler_version
end

def gemfile
gemfile = ENV["BUNDLE_GEMFILE"]
return gemfile if gemfile && !gemfile.empty?

File.expand_path("../Gemfile", __dir__)
end

def lockfile
"#{gemfile}.lock"
lockfile =
case File.basename(gemfile)
when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
else "#{gemfile}.lock"
end
File.expand_path(lockfile)
end

def lockfile_version
return unless File.file?(lockfile)

lockfile_contents = File.read(lockfile)
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
Regexp.last_match(1)
end

regexp = /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/

regexp.match(lockfile_contents)[1]
def bundler_requirement
@bundler_requirement ||=
env_var_version || cli_arg_version ||
bundler_requirement_for(lockfile_version)
end

def bundler_version
@bundler_version ||= lockfile_version
def bundler_requirement_for(version)
return "#{Gem::Requirement.default}.a" unless version

bundler_gem_version = Gem::Version.new(version)

requirement = bundler_gem_version.approximate_recommendation

return requirement unless Gem.rubygems_version < Gem::Version.new("2.7.0")

requirement += ".a" if bundler_gem_version.prerelease?

requirement
end

def load_bundler!
ENV["BUNDLE_GEMFILE"] ||= gemfile

activate_bundler(bundler_version)
activate_bundler
end

def activate_bundler
gem_error = activation_error_handling do
gem "bundler", bundler_requirement
end
return if gem_error.nil?
require_error = activation_error_handling do
require "bundler/version"
end
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
exit 42
end

def activate_bundler(bundler_version)
gem "bundler", bundler_version
def activation_error_handling
yield
nil
rescue StandardError, LoadError => e
e
end
end

m.load_bundler!

if m.invoked_as_script?
load Gem.bin_path("bundler", "bundle")
end
5 changes: 2 additions & 3 deletions bin/mdl
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

ENV["BUNDLE_GEMFILE"] = File.expand_path("gemfiles/lint/Gemfile")

load File.expand_path("bundle", __dir__)
ENV["BUNDLE_GEMFILE"] = File.expand_path("../gemfiles/lint/Gemfile", __dir__)

require "rubygems"
require "bundler/setup"

load Gem.bin_path("mdl", "mdl")
5 changes: 3 additions & 2 deletions bin/minitest
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

load File.expand_path("bundle", __dir__)
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

require "rubygems"
require "bundler/setup"

require_relative "../test/minitest_runner"

Byebug::MinitestRunner.new.run
exit Byebug::MinitestRunner.new.run
3 changes: 2 additions & 1 deletion bin/rake
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

load File.expand_path("bundle", __dir__)
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rake", "rake")
5 changes: 2 additions & 3 deletions bin/rubocop
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

ENV["BUNDLE_GEMFILE"] = File.expand_path("gemfiles/lint/Gemfile")

load File.expand_path("bundle", __dir__)
ENV["BUNDLE_GEMFILE"] = File.expand_path("../gemfiles/lint/Gemfile", __dir__)

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rubocop", "rubocop")
4 changes: 2 additions & 2 deletions bin/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ set -eo pipefail

set +x

gem update --system 3.1.2
gem install bundler --version 2.2.0.rc.2 --force
gem update --system 3.4.20
gem install bundler --version 2.3.26 --force

bundle install

Expand Down
9 changes: 6 additions & 3 deletions docker/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ module Docker
#
class Manager
VERSIONS = %w[
2.5.8
2.6.6
2.7.2
2.5.9
2.6.10
2.7.8
3.0.6
3.1.4
3.2.2
].freeze

LINE_EDITORS = %w[
Expand Down
9 changes: 3 additions & 6 deletions ext/byebug/breakpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,20 +370,17 @@ check_breakpoint_by_hit_condition(VALUE rb_breakpoint)
{
case HIT_COND_NONE:
return 1;
case HIT_COND_GE:
{
case HIT_COND_GE: {
if (breakpoint->hit_count >= breakpoint->hit_value)
return 1;
break;
}
case HIT_COND_EQ:
{
case HIT_COND_EQ: {
if (breakpoint->hit_count == breakpoint->hit_value)
return 1;
break;
}
case HIT_COND_MOD:
{
case HIT_COND_MOD: {
if (breakpoint->hit_count % breakpoint->hit_value == 0)
return 1;
break;
Expand Down
1 change: 1 addition & 0 deletions ext/byebug/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ void
Init_byebug_context(VALUE mByebug)
{
cContext = rb_define_class_under(mByebug, "Context", rb_cObject);
rb_undef_alloc_func(cContext);

rb_define_method(cContext, "backtrace", Context_backtrace, 0);
rb_define_method(cContext, "dead?", Context_dead, 0);
Expand Down
11 changes: 11 additions & 0 deletions ext/byebug/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,16 @@ release_lock(void)
static VALUE
Unlock(VALUE self)
{
debug_context_t *dc;
VALUE context;

UNUSED(self);

thread_context_lookup(rb_thread_current(), &context);
Data_Get_Struct(context, debug_context_t, dc);

CTX_FL_SET(dc, CTX_FL_IGNORE);

release_lock();

return locker;
Expand Down Expand Up @@ -209,6 +217,8 @@ Lock(VALUE self)

acquire_lock(dc);

CTX_FL_UNSET(dc, CTX_FL_IGNORE);

return locker;
}

Expand All @@ -224,6 +234,7 @@ void
Init_threads_table(VALUE mByebug)
{
cThreadsTable = rb_define_class_under(mByebug, "ThreadsTable", rb_cObject);
rb_undef_alloc_func(cThreadsTable);

rb_define_module_function(mByebug, "unlock", Unlock, 0);
rb_define_module_function(mByebug, "lock", Lock, 0);
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/lint/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source "https://rubygems.org"

group :development do
gem "mdl", "0.11.0"
gem "rubocop", "1.3.1"
gem "rubocop", "1.28.2"
gem "rubocop-packaging", "~> 0.5"
gem "rubocop-performance", "~> 1.3"
gem "yard", "0.9.26"
Expand Down
32 changes: 17 additions & 15 deletions gemfiles/lint/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,33 @@ GEM
tomlrb
mixlib-shellout (3.1.7)
chef-utils
parallel (1.20.1)
parser (3.0.0.0)
parallel (1.23.0)
parser (3.2.2.4)
ast (~> 2.4.1)
rainbow (3.0.0)
regexp_parser (2.1.1)
racc
racc (1.7.1)
rainbow (3.1.1)
regexp_parser (2.8.2)
rexml (3.2.4)
rubocop (1.3.1)
rubocop (1.28.2)
parallel (~> 1.10)
parser (>= 2.7.1.5)
parser (>= 3.1.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.1.1)
rubocop-ast (>= 1.17.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (1.4.1)
parser (>= 2.7.1.5)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.17.0)
parser (>= 3.1.1.0)
rubocop-packaging (0.5.1)
rubocop (>= 0.89, < 2.0)
rubocop-performance (1.10.2)
rubocop (>= 0.90.0, < 2.0)
rubocop-ast (>= 0.4.0)
ruby-progressbar (1.11.0)
ruby-progressbar (1.13.0)
tomlrb (1.3.0)
unicode-display_width (1.7.0)
unicode-display_width (2.5.0)
yard (0.9.26)

PLATFORMS
Expand All @@ -51,10 +53,10 @@ PLATFORMS

DEPENDENCIES
mdl (= 0.11.0)
rubocop (= 1.3.1)
rubocop (= 1.28.2)
rubocop-packaging (~> 0.5)
rubocop-performance (~> 1.3)
yard (= 0.9.26)

BUNDLED WITH
2.2.0.rc.2
2.3.26
18 changes: 13 additions & 5 deletions lib/byebug/helpers/eval.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,12 @@ def warning_msg(exception)
# creating new threads won't be properly evaluated because new threads
# will get blocked by byebug's main thread.
#
def allowing_other_threads
def allowing_other_threads(&block)
Byebug.unlock

res = yield

tracepoint_allow_reentry(&block)
ensure
Byebug.lock

res
end

#
Expand All @@ -121,6 +119,16 @@ def safe_to_s(var)
rescue StandardError
"*Error in evaluation*"
end

if TracePoint.respond_to?(:allow_reentry)
def tracepoint_allow_reentry(&block)
TracePoint.allow_reentry(&block)
end
else
def tracepoint_allow_reentry
yield
end
end
end
end
end
Loading

0 comments on commit 7e73848

Please sign in to comment.