Class: Byebug::InfoCommand
- Includes:
- Columnize
- Defined in:
- lib/byebug/commands/info.rb
Constant Summary collapse
- Subcommands =
[ ['args' , 1, 'Argument variables of current stack frame' ], ['breakpoints' , 1, 'Status of user-settable breakpoints', 'Without argument, list info about all ' \ 'breakpoints. With an integer argument, ' \ 'list info on that breakpoint.' ], ['catch' , 3, 'Exceptions that can be caught in the ' \ 'current stack frame' ], ['display' , 2, 'Expressions to display when program stops' ], ['file' , 4, 'Info about a particular file read in', 'After the file name is supplied, you can' \ 'list file attributes that you wish to ' \ 'see. Attributes include: "all", "basic",' \ ' "breakpoint", "lines", "mtime", "path" ' \ 'and "sha1".' ], ['files' , 5, 'File names and timestamps of files read in' ], ['global_variables' , 2, 'Global variables' ], ['instance_variables', 2, 'Instance variables in current stack frame' ], ['line' , 2, 'Line number and file name of current ' \ 'position in source file' ], ['locals' , 2, 'Local variables of the current stack frame' ], ['program' , 2, 'Execution status of the program' ], ['variables' , 1, 'Local and instance variables of the ' \ 'current stack frame' ] ].map do |name, min, help| Subcmd.new(name, min, help) end
- InfoFileSubcommands =
[ ['all' , 1, 'All file information available - breakpoints, ' \ 'lines, mtime, path and sha1' ], ['basic' , 2, 'basic information - path, number of lines' ], ['breakpoints', 2, 'Show trace line numbers', 'These are the line number where a breakpoint ' \ 'can be set.' ], ['lines' , 1, 'Show number of lines in the file' ], ['mtime' , 1, 'Show modification time of file' ], ['path' , 4, 'Show full file path name for file' ], ['sha1' , 1, 'Show SHA1 hash of contents of the file' ] ].map do |name, min, help| Subcmd.new(name, min, help) end
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
- #info_args(*args) ⇒ Object
- #info_breakpoints(*args) ⇒ Object
- #info_display(*args) ⇒ Object
- #info_file(*args) ⇒ Object
- #info_files(*args) ⇒ Object
- #info_global_variables(*args) ⇒ Object
- #info_instance_variables(*args) ⇒ Object
- #info_line(*args) ⇒ Object
- #info_locals(*args) ⇒ Object
- #info_program(*args) ⇒ Object
- #info_variables(*args) ⇒ Object
- #regexp ⇒ Object
Methods inherited from Command
commands, find, format_subcmd, format_subcmds, inherited, #initialize, load_commands, #match
Constructor Details
This class inherits a constructor from Byebug::Command
Class Method Details
.description ⇒ Object
269 270 271 272 273 |
# File 'lib/byebug/commands/info.rb', line 269 def description %{info[ subcommand] Generic command for showing things about the program being debugged.} end |
.help(args) ⇒ Object
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/byebug/commands/info.rb', line 275 def help(args) return description + format_subcmds unless args and args[1] return format_subcmd(args[1]) unless 'file' == args[1] and args[2] str = subcmd.short_help + '.' subsubcmd = Command.find(InfoFileSubcommands, args[2]) if subsubcmd str += "\nInvalid \"file\" attribute \"#{args[2]}\"." else str += "\n" + subsubcmd.short_help + '.' end return str end |
.names ⇒ Object
265 266 267 |
# File 'lib/byebug/commands/info.rb', line 265 def names %w(info) end |
Instance Method Details
#execute ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/byebug/commands/info.rb', line 67 def execute return print InfoCommand.help(nil) unless @match[1] args = @match[1].split(/[ \t]+/) param = args.shift subcmd = Command.find(Subcommands, param) return errmsg "Unknown info command #{param}\n" unless subcmd if @state.context send("info_#{subcmd.name}", *args) else errmsg "info_#{subcmd.name} not available without a context.\n" end end |
#info_args(*args) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/byebug/commands/info.rb', line 82 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] print "#{s}\n" end end |
#info_breakpoints(*args) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/byebug/commands/info.rb', line 106 def info_breakpoints(*args) return print "No breakpoints.\n" 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.\n" if brkpts.empty? end print "Num Enb What\n" brkpts.each { |b| info_breakpoint(b) } end |
#info_display(*args) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/byebug/commands/info.rb', line 120 def info_display(*args) return print "There are no auto-display expressions now.\n" unless @state.display.find{|d| d[0]} print "Auto-display expressions now in effect:\n" \ "Num Enb Expression\n" n = 1 for d in @state.display print "%3d: %s %s\n" % [n, (d[0] ? 'y' : 'n'), d[1]] n += 1 end end |
#info_file(*args) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/byebug/commands/info.rb', line 166 def info_file(*args) return info_files unless args[0] subcmd = Command.find(InfoFileSubcommands, args[1] || 'basic') return errmsg "Invalid parameter #{args[1]}\n" unless subcmd if %w(all basic).member?(subcmd.name) info_file_path(args[0]) info_file_lines(args[0]) if subcmd.name == 'all' info_file_breakpoints(args[0]) info_file_mtime(args[0]) info_file_sha1(args[0]) end else print "File #{args[0]}\n" if subcmd.name != 'path' send("info_file_#{subcmd.name}", args[0]) end end |
#info_files(*args) ⇒ Object
186 187 188 189 190 191 192 |
# File 'lib/byebug/commands/info.rb', line 186 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_global_variables(*args) ⇒ Object
250 251 252 |
# File 'lib/byebug/commands/info.rb', line 250 def info_global_variables(*args) var_global end |
#info_instance_variables(*args) ⇒ Object
194 195 196 197 |
# File 'lib/byebug/commands/info.rb', line 194 def info_instance_variables(*args) obj = bb_eval('self') var_list(obj.instance_variables) end |
#info_line(*args) ⇒ Object
199 200 201 |
# File 'lib/byebug/commands/info.rb', line 199 def info_line(*args) print "Line #{@state.line} of \"#{@state.file}\"\n" end |
#info_locals(*args) ⇒ Object
203 204 205 206 |
# File 'lib/byebug/commands/info.rb', line 203 def info_locals(*args) locals = @state.context.frame_locals print_hash(locals) end |
#info_program(*args) ⇒ Object
239 240 241 242 243 244 245 246 247 248 |
# File 'lib/byebug/commands/info.rb', line 239 def info_program(*args) if @state.context.dead? print "The program crashed.\n" print "Exception: #{Byebug.last_exception.inspect}\n" if Byebug.last_exception return end print "Program stopped. " info_stop_reason @state.context.stop_reason end |
#info_variables(*args) ⇒ Object
254 255 256 257 258 259 260 261 262 |
# File 'lib/byebug/commands/info.rb', line 254 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 |
#regexp ⇒ Object
63 64 65 |
# File 'lib/byebug/commands/info.rb', line 63 def regexp /^\s* i(?:nfo)? (?:\s+(.+))? \s*$/x end |