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 how to detect potential_lines #397

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
22 changes: 21 additions & 1 deletion lib/byebug/breakpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,27 @@ def self.remove(id)
#
def self.potential_lines(filename)
name = "#{Time.new.to_i}_#{rand(2**31)}"
lines = {}
iseq = RubyVM::InstructionSequence.compile(File.read(filename), name)

if iseq.respond_to?(:each_child)
potential_lines_with_trace_points(iseq, {})
else
potential_lines_without_trace_points(iseq, {})
end
end

def self.potential_lines_with_trace_points(iseq, lines)
iseq.trace_points.each { |(line, _)| lines[line] = true }
iseq.each_child do |child|
potential_lines_with_trace_points(child, lines)
end

lines.keys.sort
end

private_class_method :potential_lines_with_trace_points

def self.potential_lines_without_trace_points(iseq, lines)
iseq.disasm.each_line do |line|
res = /^\d+ (?<insn>\w+)\s+.+\(\s*(?<lineno>\d+)\)$/.match(line)
next unless res && res[:insn] == 'trace'
Expand All @@ -62,6 +80,8 @@ def self.potential_lines(filename)
lines.keys
end

private_class_method :potential_lines_without_trace_points

#
# Returns true if a breakpoint could be set in line number +lineno+ in file
# name +filename.
Expand Down