Module: Byebug::InfoFunctions
- Defined in:
- lib/byebug/commands/info.rb
Overview
Utility methods to assist the info command
Instance Method Summary collapse
- #info_args(*args) ⇒ Object
- #info_breakpoint(brkpt) ⇒ Object
- #info_breakpoints(*args) ⇒ Object
- #info_catch(*_args) ⇒ Object
- #info_display(*_args) ⇒ Object
- #info_file_breakpoints(file) ⇒ Object
- #info_file_lines(file) ⇒ Object
- #info_file_mtime(file) ⇒ Object
- #info_file_path(file) ⇒ Object
- #info_file_sha1(file) ⇒ Object
- #info_files(*_args) ⇒ Object
- #info_line(*_args) ⇒ Object
- #info_program(*_args) ⇒ Object
- #info_stop_reason(stop_reason) ⇒ Object
- #info_variables(*_args) ⇒ Object
- #print_hash(vars) ⇒ Object
Instance Method Details
#info_args(*args) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/byebug/commands/info.rb', line 18 def info_args(*args) locals = @state.context.frame_locals args = @state.context.frame_args return if args == [[:rest]] args.map do |_, name| s = "#{name} = #{locals[name].inspect}" s[Setting[:width] - 3..-1] = '...' if s.size > Setting[:width] puts s end end |
#info_breakpoint(brkpt) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/byebug/commands/info.rb', line 30 def info_breakpoint(brkpt) expr = brkpt.expr.nil? ? '' : " if #{brkpt.expr}" y_n = brkpt.enabled? ? 'y' : 'n' interp = format('%-3d %-3s at %s:%s%s', brkpt.id, y_n, brkpt.source, brkpt.pos, expr) puts interp hits = brkpt.hit_count return unless hits > 0 s = (hits > 1) ? 's' : '' puts "\tbreakpoint already hit #{hits} time#{s}" end |
#info_breakpoints(*args) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/byebug/commands/info.rb', line 43 def info_breakpoints(*args) return puts('No breakpoints.') if Byebug.breakpoints.empty? brkpts = Byebug.breakpoints.sort_by { |b| b.id } unless args.empty? indices = args.map { |a| a.to_i } brkpts = brkpts.select { |b| indices.member?(b.id) } return errmsg('No breakpoints found among list given') if brkpts.empty? end puts 'Num Enb What' brkpts.each { |b| info_breakpoint(b) } end |
#info_catch(*_args) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/byebug/commands/info.rb', line 6 def info_catch(*_args) return puts('No frame selected.') unless @state.context if Byebug.catchpoints && !Byebug.catchpoints.empty? Byebug.catchpoints.each do |exception, _hits| puts("#{exception}: #{exception.is_a?(Class)}") end else puts 'No exceptions set to be caught.' end end |
#info_display(*_args) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/byebug/commands/info.rb', line 57 def info_display(*_args) return puts('There are no auto-display expressions now.') unless @state.display.find { |d| d[0] } puts 'Auto-display expressions now in effect:' puts 'Num Enb Expression' n = 1 @state.display.each do |d| puts(format('%3d: %s %s', n, d[0] ? 'y' : 'n', d[1])) n += 1 end end |
#info_file_breakpoints(file) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/byebug/commands/info.rb', line 82 def info_file_breakpoints(file) breakpoints = LineCache.trace_line_numbers(file) return unless breakpoints puts "\tbreakpoint line numbers:" puts columnize(breakpoints.to_a.sort, Setting[:width]) end |
#info_file_lines(file) ⇒ Object
77 78 79 80 |
# File 'lib/byebug/commands/info.rb', line 77 def info_file_lines(file) lines = File.foreach(file) puts "\t#{lines.count} lines" if lines end |
#info_file_mtime(file) ⇒ Object
90 91 92 93 |
# File 'lib/byebug/commands/info.rb', line 90 def info_file_mtime(file) stat = File.stat(file) puts "\t#{stat.mtime}" if stat end |
#info_file_path(file) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/byebug/commands/info.rb', line 70 def info_file_path(file) s = "File #{file}" path = File.(file) s = "#{s} - #{path}" if path && path != file puts s end |
#info_file_sha1(file) ⇒ Object
95 96 97 |
# File 'lib/byebug/commands/info.rb', line 95 def info_file_sha1(file) puts "\t#{Digest::SHA1.hexdigest(file)}" end |
#info_files(*_args) ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/byebug/commands/info.rb', line 99 def info_files(*_args) files = SCRIPT_LINES__.keys files.uniq.sort.each do |file| info_file_path(file) info_file_mtime(file) end end |
#info_line(*_args) ⇒ Object
107 108 109 |
# File 'lib/byebug/commands/info.rb', line 107 def info_line(*_args) puts "Line #{@state.line} of \"#{@state.file}\"" end |
#info_program(*_args) ⇒ Object
140 141 142 143 144 145 146 147 148 149 |
# File 'lib/byebug/commands/info.rb', line 140 def info_program(*_args) if @state.context.dead? puts 'The program crashed.' excpt = Byebug.last_exception return puts("Exception: #{excpt.inspect}") if excpt end puts 'Program stopped. ' info_stop_reason @state.context.stop_reason end |
#info_stop_reason(stop_reason) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/byebug/commands/info.rb', line 127 def info_stop_reason(stop_reason) case stop_reason when :step puts "It stopped after stepping, next'ing or initial start." when :breakpoint puts 'It stopped at a breakpoint.' when :catchpoint puts 'It stopped at a catchpoint.' else puts "Unknown reason: #{@state.context.stop_reason}" end end |
#info_variables(*_args) ⇒ Object
151 152 153 154 155 156 157 158 159 |
# File 'lib/byebug/commands/info.rb', line 151 def info_variables(*_args) locals = @state.context.frame_locals locals[:self] = @state.context.frame_self(@state.frame_pos) print_hash(locals) obj = bb_eval('self') var_list(obj.instance_variables, obj.instance_eval { binding }) var_class_self end |
#print_hash(vars) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/byebug/commands/info.rb', line 111 def print_hash(vars) vars.keys.sort.each do |name| begin s = "#{name} = #{vars[name].inspect}" rescue begin s = "#{name} = #{vars[name]}" rescue s = "#{name} = *Error in evaluation*" end end s[Setting[:width] - 3..-1] = '...' if s.size > Setting[:width] puts s end end |