Sha256: 5efc52b75a59d3f79b8881860bb7156d045fef62087b769ffdb7a06fe12c0896

Contents?: true

Size: 1.97 KB

Versions: 3

Compression:

Stored size: 1.97 KB

Contents

# -*- coding: utf-8 -*-
# Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
require 'rubygems'; require 'require_relative'
require 'columnize'
require_relative '../base/subcmd'
require_relative '../../../app/frame'

class Trepan::Subcommand::InfoLocals < Trepan::Subcommand
  unless defined?(HELP)
    Trepanning::Subcommand.set_name_prefix(__FILE__, self)
    HELP         = <<-EOH
#{CMD}
#{CMD} [names]

Show local variables including parameters of the current stack frame.
Normally for each which show both the name and value. If you just
want a list of names add parameter 'names'.
EOH
    SHORT_HELP   = 'Show local variables of the current stack frame'
    MIN_ARGS     = 0
    MAX_ARGS     = 1
    MIN_ABBREV   = 'lo'.size 
    NEED_STACK   = true
  end

  def get_local_names
    @proc.frame.local_variables.keys
  end

  def run(args)
    if args.size == 3
      if 0 == 'names'.index(args[-1].downcase)
        local_names = get_local_names()
        if local_names.empty?
            msg "No local variables defined."
        else
          section "Local variable names:"
          width = settings[:maxwidth]
          mess = Columnize::columnize(local_names, 
                                      @proc.settings[:maxwidth], '  ',
                                      false, true, ' ' * 2).chomp
          msg mess
        end
      else
        errmsg("unrecognized argument #{args[2]}")
      end
    elsif args.size == 2
      local_names = get_local_names
      if local_names.empty?
        msg "No local variables defined."
      else
        section "Local variables:"
        @proc.frame.local_variables.each do |var_name, var_value| 
          msg("#{var_name} = #{var_value}")
        end
      end
    else
      errmsg("Wrong number of arguments #{args.size}")
    end
  end
end

if __FILE__ == $0
  # Demo it.
  require_relative '../../mock'
  cmd = MockDebugger::sub_setup(Trepan::Subcommand::InfoLocals, false)
  cmd.run(cmd.prefix)
  cmd.run(cmd.prefix + ['name'])
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rb8-trepanning-0.1.3 processor/command/info_subcmd/locals.rb
rb8-trepanning-0.1.3-universal-ruby-1.9.2 processor/command/info_subcmd/locals.rb
rb8-trepanning-0.1.3-universal-ruby-1.8.7 processor/command/info_subcmd/locals.rb