Skip to content

Commit b22fca3

Browse files
committed
Extract get_src method
1 parent 0319744 commit b22fca3

File tree

2 files changed

+44
-34
lines changed

2 files changed

+44
-34
lines changed

lib/debug/session.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ def process_event evt
252252
else
253253
tc << [:eval, :display, @displays]
254254
end
255-
256255
when :result
257256
raise "[BUG] not in subsession" if @subsession_stack.empty?
258257

lib/debug/thread_client.rb

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -415,55 +415,66 @@ def frame_eval src, re_raise: false
415415
raise if re_raise
416416
end
417417

418-
def show_src(frame_index: @current_frame_index,
419-
update_line: false,
420-
max_lines: CONFIG[:show_src_lines] || 10,
418+
def get_src(frame:,
419+
max_lines:,
421420
start_line: nil,
422421
end_line: nil,
423422
dir: +1)
424-
if @target_frames && frame = @target_frames[frame_index]
425-
if file_lines = frame.file_lines
426-
frame_line = frame.location.lineno - 1
427-
428-
lines = file_lines.map.with_index do |e, i|
429-
cur = i == frame_line ? '=>' : ' '
430-
line = colorize_dim('%4d|' % (i+1))
431-
"#{cur}#{line} #{e}"
432-
end
423+
if file_lines = frame.file_lines
424+
frame_line = frame.location.lineno - 1
433425

434-
unless start_line
435-
if frame.show_line
436-
if dir > 0
437-
start_line = frame.show_line
438-
else
439-
end_line = frame.show_line - max_lines
440-
start_line = [end_line - max_lines, 0].max
441-
end
426+
lines = file_lines.map.with_index do |e, i|
427+
cur = i == frame_line ? '=>' : ' '
428+
line = colorize_dim('%4d|' % (i+1))
429+
"#{cur}#{line} #{e}"
430+
end
431+
432+
unless start_line
433+
if frame.show_line
434+
if dir > 0
435+
start_line = frame.show_line
442436
else
443-
start_line = [frame_line - max_lines/2, 0].max
437+
end_line = frame.show_line - max_lines
438+
start_line = [end_line - max_lines, 0].max
444439
end
440+
else
441+
start_line = [frame_line - max_lines/2, 0].max
445442
end
443+
end
446444

447-
unless end_line
448-
end_line = [start_line + max_lines, lines.size].min
449-
end
445+
unless end_line
446+
end_line = [start_line + max_lines, lines.size].min
447+
end
450448

449+
if start_line != end_line && max_lines
450+
[start_line, end_line, lines]
451+
else
452+
[]
453+
end
454+
else # no file lines
455+
[]
456+
end
457+
rescue Exception => e
458+
p e
459+
pp e.backtrace
460+
exit!
461+
end
462+
463+
def show_src(frame_index: @current_frame_index, update_line: false, max_lines: CONFIG[:show_src_lines] || 10, **options)
464+
if frame = get_frame(frame_index)
465+
start_line, end_line, lines = get_src(frame: frame, max_lines: max_lines, **options)
466+
467+
if start_line
451468
if update_line
452469
frame.show_line = end_line
453470
end
454471

455-
if start_line != end_line && max_lines
456-
puts "[#{start_line+1}, #{end_line}] in #{frame.pretty_path}" if !update_line && max_lines != 1
457-
puts lines[start_line ... end_line]
458-
end
459-
else # no file lines
472+
puts "[#{start_line+1}, #{end_line}] in #{frame.pretty_path}" if !update_line && max_lines != 1
473+
puts lines[start_line...end_line]
474+
else
460475
puts "# No sourcefile available for #{frame.path}"
461476
end
462477
end
463-
rescue Exception => e
464-
p e
465-
pp e.backtrace
466-
exit!
467478
end
468479

469480
def current_frame

0 commit comments

Comments
 (0)