Class: Byebug::InfoCommand
- Includes:
- Columnize
- Defined in:
- lib/byebug/commands/info.rb
Overview
Implements byebug “info” command.
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 of the 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'], ['stack', 2, 'Backtrace of the stack'], ['variables', 1, 'Local and instance variables of the current stack frame'] ].map do |name, min, short_help, long_help| Subcmd.new(name, min, short_help, long_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, short_help, long_help| Subcmd.new(name, min, short_help, long_help) end
Constants inherited from Command
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_stack(*args) ⇒ Object
- #info_variables(*args) ⇒ Object
- #regexp ⇒ Object
Methods inherited from Command
command_exists?, commands, find, format_subcmd, format_subcmds, inherited, #initialize, load_commands, #match, method_missing, options, register_setting_get, register_setting_set, register_setting_var, settings, settings_map, terminal_width
Constructor Details
This class inherits a constructor from Byebug::Command
Class Method Details
.description ⇒ Object
273 274 275 276 277 |
# File 'lib/byebug/commands/info.rb', line 273 def description %{info[ subcommand] Generic command for showing things about the program being debugged.} end |
.help(args) ⇒ Object
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/byebug/commands/info.rb', line 279 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
269 270 271 |
# File 'lib/byebug/commands/info.rb', line 269 def names %w(info) end |
Instance Method Details
#execute ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/byebug/commands/info.rb', line 69 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
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/byebug/commands/info.rb', line 84 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}" pad_with_dots(s) print "#{s}\n" end end |
#info_breakpoints(*args) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/byebug/commands/info.rb', line 108 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
122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/byebug/commands/info.rb', line 122 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
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/byebug/commands/info.rb', line 168 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
188 189 190 191 192 193 194 |
# File 'lib/byebug/commands/info.rb', line 188 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
254 255 256 |
# File 'lib/byebug/commands/info.rb', line 254 def info_global_variables(*args) var_global end |
#info_instance_variables(*args) ⇒ Object
196 197 198 199 |
# File 'lib/byebug/commands/info.rb', line 196 def info_instance_variables(*args) obj = debug_eval('self') var_list(obj.instance_variables) end |
#info_line(*args) ⇒ Object
201 202 203 |
# File 'lib/byebug/commands/info.rb', line 201 def info_line(*args) print "Line #{@state.line} of \"#{@state.file}\"\n" end |
#info_locals(*args) ⇒ Object
205 206 207 208 |
# File 'lib/byebug/commands/info.rb', line 205 def info_locals(*args) locals = @state.context.frame_locals print_hash(locals) end |
#info_program(*args) ⇒ Object
241 242 243 244 245 246 247 248 |
# File 'lib/byebug/commands/info.rb', line 241 def info_program(*args) return print "The program crashed.\n" + Byebug.last_exception ? "Exception: #{Byebug.last_exception.inspect}" : "" + "\n" if @state.context.dead? print "Program stopped. " info_stop_reason @state.context.stop_reason end |
#info_stack(*args) ⇒ Object
250 251 252 |
# File 'lib/byebug/commands/info.rb', line 250 def info_stack(*args) print_backtrace end |
#info_variables(*args) ⇒ Object
258 259 260 261 262 263 264 265 266 |
# File 'lib/byebug/commands/info.rb', line 258 def info_variables(*args) locals = @state.context.frame_locals locals[:self] = @state.context.frame_self(@state.frame_pos) print_hash(locals) obj = debug_eval('self') var_list(obj.instance_variables, obj.instance_eval{binding()}) var_class_self end |
#regexp ⇒ Object
65 66 67 |
# File 'lib/byebug/commands/info.rb', line 65 def regexp /^\s* i(?:nfo)? (?:\s+(.+))? \s*$/x end |