Class: Byebug::InfoCommand

Inherits:
Command
  • Object
show all
Includes:
Columnize
Defined in:
lib/byebug/commands/info.rb

Overview

Show info about different aspects of the debugger.

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'],
  ['line', 2, 'Line number and file name of current position in source ' \
              'file.'],
  ['program', 2, 'Execution status of the program']
].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

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

.descriptionObject



247
248
249
250
251
252
253
254
255
# File 'lib/byebug/commands/info.rb', line 247

def description
  <<-EOD.gsub(/^ {8}/, '')

    info[ subcommand]

    Generic command for showing things about the program being debugged.

  EOD
end

.help(subcmds = []) ⇒ Object



257
258
259
260
261
262
263
264
265
266
267
# File 'lib/byebug/commands/info.rb', line 257

def help(subcmds = [])
  return description + format_subcmds if subcmds.empty?

  subcmd = subcmds.first
  return format_subcmd(subcmd) unless 'file' == subcmd && subcmds[2]

  subsubcmd = Command.find(InfoFileSubcommands, subcmds[2])
  return "\nInvalid \"file\" attribute \"#{args[2]}\"." unless subsubcmd

  subsubcmd.short_help
end

.namesObject



243
244
245
# File 'lib/byebug/commands/info.rb', line 243

def names
  %w(info)
end

Instance Method Details

#executeObject



227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/byebug/commands/info.rb', line 227

def execute
  return puts(InfoCommand.help) 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_file(*args) ⇒ Object



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/byebug/commands/info.rb', line 202

def info_file(*args)
  return info_files unless args[0]

  mode = args[1] || 'basic'
  subcmd = Command.find(InfoFileSubcommands, mode)
  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
    puts("File #{args[0]}") if subcmd.name != 'path'
    send("info_file_#{subcmd.name}", args[0])
  end
end

#regexpObject



223
224
225
# File 'lib/byebug/commands/info.rb', line 223

def regexp
  /^\s* i(?:nfo)? (?:\s+(.+))? \s*$/x
end