Class: Debugger::InfoCommand

### Home Classes Methods

### In Files

- lib/ruby-debug/commands/info.rb

### Parent

Debugger::Command

### Methods

- ::help
- ::help_command
- #execute
- #info_args
- #info_breakpoints
- #info_display
- #info_file
- #info_files
- #info_global_variables
- #info_instance_variables
- #info_line
- #info_locals
- #info_program
- #info_stack
- #info_thread
- #info_threads
- #info_variables
- #regexp

### Class/Module Index

Quicksearch

- Debugger
- Debugger::AddBreakpoint
- Debugger::Breakpoint
- Debugger::Context
- Debugger::ContinueCommand
- Debugger::DeleteBreakpointCommand
- Debugger::FinishCommand
- Debugger::HelpCommand
- Debugger::IRBCommand
- Debugger::InfoCommand
- Debugger::JumpCommand
- Debugger::KillCommand
- Debugger::ListCommand
- Debugger::LocalInterface
- Debugger::LocalInterface::Debugger
- Debugger::MethodCommand
- Debugger::MethodSigCommand
- Debugger::NextCommand
- Debugger::ParseFunctions
- Debugger::Processor
- Debugger::QuitCommand
- Debugger::ReloadCommand
- Debugger::SetCommand
- Debugger::ShowCommand
- Debugger::SkipCommand
- Debugger::SourceCommand
- Debugger::StepCommand
- Debugger::VarClassVarCommand
- Debugger::VarInheritCommand
- Debugger::VarLocalCommand
- Debugger::WhereCommand
- Printers
- Printers::Base
- Printers::Base::MissedArgument
- Printers::Base::MissedPath
- Printers::Plain
- Mocha
- Mocha::Call
- Mocha::Expectation
- Mocha::Mock
- MiniTest
- MiniTest::Assertions
- MiniTest::Expectations
- TestDsl
- TestDsl::ClassMethods
- TestDsl::Shared
- Kernel
- Module
- PrinterHelpers
- TestInterface

No matching classes.

# Debugger::InfoCommand

Implements debugger "info" command.

### Constants

InfoFileSubcommands
InfoThreadSubcommands
Subcommands

### Public Class Methods

help(args) click to toggle source

    # File lib/ruby-debug/commands/info.rb, line 417
    def help(args)
      if args[1]
        s = args[1]
        subcmd = Subcommands.find do |try_subcmd|
          (s.size >= try_subcmd.min) and
            (try_subcmd.name[0..s.size-1] == s)
        end
        if subcmd
          str = subcmd.short_help + '.'
          if 'file' == subcmd.name and args[2]
            s = args[2]
            subsubcmd = InfoFileSubcommands.find do |try_subcmd|
              (s.size >= try_subcmd.min) and
                (try_subcmd.name[0..s.size-1] == s)
            end
            if subsubcmd
              str += "\n" + subsubcmd.short_help + '.'
            else
              str += "\nInvalid file attribute #{args[2]}."
            end
          else
            str += "\n" + subcmd.long_help if subcmd.long_help
          end
          return str
        else
          return "Invalid 'info' subcommand '#{args[1]}'."
        end
      end
      s = %{
        Generic command for showing things about the program being debugged.
        --
        List of info subcommands:
        --
      }
      for subcmd in Subcommands do
        s += "info #{subcmd.name} -- #{subcmd.short_help}\n"
      end
      return s
    end

help_command() click to toggle source

    # File lib/ruby-debug/commands/info.rb, line 413
    def help_command
      'info'
    end

### Public Instance Methods

execute() click to toggle source

    # File lib/ruby-debug/commands/info.rb, line 93
    def execute
      if !@match[1]
        errmsg "\"info\" must be followed by the name of an info command:\n"
        print "List of info subcommands:\n\n"
        for subcmd in Subcommands do
          print "info #{subcmd.name} -- #{subcmd.short_help}\n"
        end
      else
        args = @match[1].split(/[ \t]+/)
        param = args.shift
        subcmd = find(Subcommands, param)
        if subcmd
          send("info_#{subcmd.name}", *args)
        else
          errmsg "Unknown info command #{param}\n"
        end
      end
    end

info_args(*args) click to toggle source

    # File lib/ruby-debug/commands/info.rb, line 112
    def info_args(*args)
      unless @state.context
        print "No frame selected.\n"
        return
      end
      locals = @state.context.frame_locals(@state.frame_pos)
      args = @state.context.frame_args(@state.frame_pos)
      args.each do |name|
        s = "#{name} = #{locals[name].inspect}"
        if s.size > self.class.settings[:width]
          s[self.class.settings[:width]-3 .. -1] = "..."
        end
        print "#{s}\n"
      end
    end

info_breakpoints(*args) click to toggle source

    # File lib/ruby-debug/commands/info.rb, line 128
    def info_breakpoints(*args)
      unless @state.context
        print "info breakpoints not available here.\n"
        return
      end
      unless Debugger.breakpoints.empty?
        brkpts = Debugger.breakpoints.sort_by{|b| b.id}
        unless args.empty?
          indices = args.map{|a| a.to_i}
          brkpts = brkpts.select{|b| indices.member?(b.id)}
          if brkpts.empty?
            errmsg "No breakpoints found among list given.\n"
            return
          end
        end
        print "Num Enb What\n"
        brkpts.each do |b|
          if b.expr.nil?
            print("%3d %s   at %s:%s\n" % [b.id, (b.enabled? ? 'y' : 'n'), b.source, b.pos])
          else
            print("%3d %s   at %s:%s if %s\n" % [b.id, (b.enabled? ? 'y' : 'n'), b.source, b.pos, b.expr])
          end
          hits = b.hit_count
          if hits > 0
            s = (hits > 1) ? 's' : ''
            print "\tbreakpoint already hit #{hits} time#{s}\n"
          end
        end
      else
        print "No breakpoints.\n"
      end
    end

info_display(*args) click to toggle source

    # File lib/ruby-debug/commands/info.rb, line 161
    def info_display(*args)
      unless @state.context
        print "info display not available here.\n"
        return
      end
      if @state.display.find{|d| d[0]}
        print "Auto-display expressions now in effect:\n"
        print "Num Enb Expression\n"
        n = 1
        for d in @state.display
          print("%3d: %s  %s\n" % [n, (d[0] ? 'y' : 'n'), d[1]]) if d[0] != nil
          n += 1
        end
      else
        print "There are no auto-display expressions now.\n"
      end
    end

info_file(*args) click to toggle source

    # File lib/ruby-debug/commands/info.rb, line 179
    def info_file(*args)
      unless args[0]
        info_files
        return
      end
      file = args[0]
      param =  args[1]

      param = 'basic' unless param
      subcmd = find(InfoFileSubcommands, param)
      unless subcmd
        errmsg "Invalid parameter #{param}\n"
        return
      end

      unless LineCache::cached?(file)
        unless LineCache::cached_script?(file)
          print "File #{file} is not cached\n"
          return
        end
        LineCache::cache(file, Command.settings[:reload_source_on_change])
      end

      print("File #{file}")
      path = LineCache.path(file)
      if %(all basic path).member?(subcmd.name) and path != file
        print(" - #{path}\n")
      else
        print "\n"
      end

      if %(all basic lines).member?(subcmd.name)
        lines = LineCache.size(file)
        print("\t #{lines} lines\n") if lines
      end

      if %(all breakpoints).member?(subcmd.name)
        breakpoints = LineCache.trace_line_numbers(file)
        if breakpoints
          print "\tbreakpoint line numbers:\n"
          print columnize(breakpoints.to_a.sort, self.class.settings[:width])
        end
      end

      if %(all mtime).member?(subcmd.name)
        stat = LineCache.stat(file)
        print("\t#{stat.mtime}\n") if stat
      end
      if %(all sha1).member?(subcmd.name)
        print("\t#{LineCache.sha1(file)}\n")
      end
    end

info_files(*args) click to toggle source

    # File lib/ruby-debug/commands/info.rb, line 232
    def info_files(*args)
      files = LineCache::cached_files
      files += SCRIPT_LINES__.keys unless 'stat' == args[0]
      files.uniq.sort.each do |file|
        stat = LineCache::stat(file)
        path = LineCache::path(file)
        print("File #{file}")
        if path and path != file
          print " - #{path}\n"
        else
          print "\n"
        end
        print "\t#{stat.mtime}\n" if stat
      end
    end

info_global_variables(*args) click to toggle source

    # File lib/ruby-debug/commands/info.rb, line 374
    def info_global_variables(*args)
      unless @state.context
        errmsg "info global_variables not available here.\n"
        return
      end
      var_global
    end

info_instance_variables(*args) click to toggle source

    # File lib/ruby-debug/commands/info.rb, line 248
    def info_instance_variables(*args)
      unless @state.context
        print "info instance_variables not available here.\n"
        return
      end
      obj = debug_eval('self')
      var_list(obj.instance_variables.map(&:to_s))
    end

info_line(*args) click to toggle source

    # File lib/ruby-debug/commands/info.rb, line 257
    def info_line(*args)
      unless @state.context
        errmsg "info line not available here.\n"
        return
      end
      print "Line #{@state.line} of \"#{@state.file}\"\n"
    end

info_locals(*args) click to toggle source

    # File lib/ruby-debug/commands/info.rb, line 265
    def info_locals(*args)
      unless @state.context
        errmsg "info line not available here.\n"
        return
      end
      locals = @state.context.frame_locals(@state.frame_pos)
      locals.keys.sort.each do |name|
        ### FIXME: make a common routine
        begin
          s = "#{name} = #{locals[name].inspect}"
        rescue
          begin
          s = "#{name} = #{locals[name].to_s}"
          rescue
            s = "*Error in evaluation*"
          end
        end
        if s.size > self.class.settings[:width]
          s[self.class.settings[:width]-3 .. -1] = "..."
        end
        print "#{s}\n"
      end
    end

info_program(*args) click to toggle source

    # File lib/ruby-debug/commands/info.rb, line 289
    def info_program(*args)
      if not @state.context
        print "The program being debugged is not being run.\n"
        return
      elsif @state.context.dead?
        print "The program crashed.\n"
        if Debugger.last_exception
          print("Exception: #{Debugger.last_exception.inspect}\n")
        end
        return
      end

      print "Program stopped. "
      case @state.context.stop_reason
      when :step
        print "It stopped after stepping, next'ing or initial start.\n"
      when :breakpoint
        print("It stopped at a breakpoint.\n")
      when :catchpoint
        print("It stopped at a catchpoint.\n")
      else
        print "unknown reason: #{@state.context.stop_reason.to_s}\n"
      end
    end

info_stack(*args) click to toggle source

    # File lib/ruby-debug/commands/info.rb, line 314
    def info_stack(*args)
      if not @state.context
        errmsg "info stack not available here.\n"
        return
      end
      print(prc("frame.line", (0...@state.context.stack_size)) do |item, _|
        mark = item == @state.frame_pos ? "--> " : "    "
        get_pr_arguments(mark, item, @state.context)
      end)
    end

info_thread(*args) click to toggle source

    # File lib/ruby-debug/commands/info.rb, line 357
    def info_thread(*args)
      unless args[0]
        info_threads(args[0])
        return
      end
      ok, verbose = info_thread_preamble(args[1])
      return unless ok
      c = parse_thread_num("info thread" , args[0])
      return unless c
      display_context(c, !verbose)
      if verbose and not c.ignored?
        (0...c.stack_size).each do |idx|
          print_frame("\t", idx, false, c)
        end
      end
    end

info_threads(*args) click to toggle source

    # File lib/ruby-debug/commands/info.rb, line 344
    def info_threads(*args)
      ok, verbose = info_thread_preamble(args[0])
      return unless ok
      Debugger.contexts.sort_by{|c| c.thnum}.each do |c|
        display_context(c, !verbose)
        if verbose and not c.ignored?
          (0...c.stack_size).each do |idx|
            print_frame("\t", idx, false, c)
          end
        end
      end
    end

info_variables(*args) click to toggle source

    # File lib/ruby-debug/commands/info.rb, line 382
    def info_variables(*args)
      if not @state.context
        errmsg "info variables not available here.\n"
        return
      end
      obj = debug_eval('self')
      locals = @state.context.frame_locals(@state.frame_pos)
      locals['self'] = @state.context.frame_self(@state.frame_pos)
      locals.keys.sort.each do |name|
        next if name =~ /^__dbg_/ # skip debugger pollution
        ### FIXME: make a common routine
        begin
          s = "#{name} = #{locals[name].inspect}"
        rescue
          begin
            s = "#{name} = #{locals[name].to_s}"
          rescue
            s = "#{name} = *Error in evaluation*"
          end
        end
        if s.size > self.class.settings[:width]
          s[self.class.settings[:width]-3 .. -1] = "..."
        end
        s.gsub!('%', '%%')  # protect against printf format strings
        print "#{s}\n"
      end
      var_list(obj.instance_variables, obj.instance_eval{binding()})
      var_class_self
    end

regexp() click to toggle source

    # File lib/ruby-debug/commands/info.rb, line 89
    def regexp
      /^\s* i(?:nfo)? (?:\s+(.*))?$/x
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.