Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 17 additions & 3 deletions ext/debase_internals.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ Debase_enable_file_filtering(VALUE self, VALUE value)
return value;
}

#if RUBY_API_VERSION_CODE >= 20500
#if RUBY_API_VERSION_CODE >= 20500 && !(RUBY_RELEASE_YEAR == 2017 && RUBY_RELEASE_MONTH == 10 && RUBY_RELEASE_DAY == 10)
static const rb_iseq_t *
my_iseqw_check(VALUE iseqw)
{
Expand All @@ -654,17 +654,28 @@ Debase_enable_file_filtering(VALUE self, VALUE value)
}

static void
Debase_set_trace_flag_to_iseq(VALUE self, VALUE rb_iseq)
{
Debase_set_trace_flag_to_iseq(VALUE self, VALUE rb_iseq) {
if (!SPECIAL_CONST_P(rb_iseq) && RBASIC_CLASS(rb_iseq) == rb_cISeq) {
rb_iseq_t *iseq = my_iseqw_check(rb_iseq);
rb_iseq_trace_set(iseq, RUBY_EVENT_TRACEPOINT_ALL);
}
}

static void
Debase_unset_trace_flags(VALUE self, VALUE rb_iseq) {
if (!SPECIAL_CONST_P(rb_iseq) && RBASIC_CLASS(rb_iseq) == rb_cISeq) {
rb_iseq_t *iseq = my_iseqw_check(rb_iseq);
rb_iseq_trace_set(iseq, RUBY_EVENT_NONE);
}
}
#else
static void
Debase_set_trace_flag_to_iseq(VALUE self, VALUE rb_iseq) {
}

static void
Debase_unset_trace_flags(VALUE self, VALUE rb_iseq) {
}
#endif

static VALUE
Expand Down Expand Up @@ -712,6 +723,9 @@ Init_debase_internals()
rb_define_module_function(mDebase, "init_variables", Debase_init_variables, 0);
rb_define_module_function(mDebase, "set_trace_flag_to_iseq", Debase_set_trace_flag_to_iseq, 1);

//use only for tests
rb_define_module_function(mDebase, "unset_iseq_flags", Debase_unset_trace_flags, 1);

idAlive = rb_intern("alive?");
idAtLine = rb_intern("at_line");
idAtBreakpoint = rb_intern("at_breakpoint");
Expand Down
4 changes: 2 additions & 2 deletions lib/debase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def monkey_patch_prepend
class << RubyVM::InstructionSequence
def self.prepend(mod, *smth)
super
if mod.to_s.include? 'Bootsnap'
if mod.to_s.include?('Bootsnap') && RUBY_VERSION >= "2.5"
prepend InstructionSequenceMixin
end
end
Expand Down Expand Up @@ -107,7 +107,7 @@ def load_iseq(path)

def do_set_flags(iseq)
Debugger.set_trace_flag_to_iseq(iseq)
iseq.each_child{|child_iseq| do_set_flags(child_iseq)}
iseq.each_child { |child_iseq| do_set_flags(child_iseq) } if iseq.respond_to? :each_child
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions test/example/bootsnap/a.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class A
def foo(a)
puts a
end
end
3 changes: 3 additions & 0 deletions test/example/bootsnap/bootsnap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require_relative 'a.rb'

A.new.foo('hi')
34 changes: 34 additions & 0 deletions test/test_load.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

# Test of Debugger.debug_load in C extension ruby_debug.so
class TestDebugLoad < Test::Unit::TestCase

self.test_order = :defined

class << self
def at_line(file, line)
@@at_line = [File.basename(file), line]
Expand Down Expand Up @@ -41,4 +44,35 @@ def test_debug_load
ensure
Debugger.stop if Debugger.started?
end

module MyBootsnap
def load_iseq(path)
iseq = RubyVM::InstructionSequence.compile_file(path)

Debugger.unset_iseq_flags(iseq)
iseq
end
end

def test_bootsnap
@@at_line = nil
src_dir = File.dirname(__FILE__)
prog_script = File.join(src_dir, 'example', 'bootsnap', 'bootsnap.rb')

class << RubyVM::InstructionSequence
prepend MyBootsnap
end
bt = Debugger.debug_load(prog_script, true)
assert_equal(nil, bt)
assert_not_nil(@@at_line)
if RUBY_VERSION >= '2.5'
assert_equal(['debase.rb', 101], @@at_line)
end

assert(Debugger.started?)
Debugger.stop
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


class << RubyVM::InstructionSequence; self end.class_eval { undef_method :load_iseq }

end
end