Skip to content

Commit

Permalink
Add 'info iv' for instance variables. Use better way to suppress warn…
Browse files Browse the repository at this point in the history
…ings.
  • Loading branch information
rocky committed Jun 18, 2011
1 parent d0115a1 commit ceb2745
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 57 deletions.
10 changes: 10 additions & 0 deletions app/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ def extract_expression(text)
end
return text
end

# Suppress warnings. The main one we encounter is "already initialized
# constant" because perhaps another version readline has done that already.
def suppress_warnings
original_verbosity = $VERBOSE
$VERBOSE = nil
result = yield
$VERBOSE = original_verbosity
return result
end
end
end

Expand Down
18 changes: 8 additions & 10 deletions processor/command/disable.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
# Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
require 'rubygems'; require 'require_relative'
require_relative 'base/cmd'
require_relative '../../app/util'
# require_relative '../breakpoint'
# require_relative '../../app/breakpoint'

Expand All @@ -12,21 +13,18 @@
# NOTE: The enable command subclasses this, so beware when changing!
class Trepan::Command::DisableCommand < Trepan::Command

# Silence already initialized constant .. warnings
old_verbose = $VERBOSE
$VERBOSE = nil
NAME = File.basename(__FILE__, '.rb')
HELP = <<-HELP
Trepan::Util.suppress_warnings {
NAME = File.basename(__FILE__, '.rb')
HELP = <<-HELP
#{NAME} bpnumber [bpnumber ...]
Disables the breakpoints given as a space separated list of breakpoint
numbers. See also "info break" to get a list.
HELP

CATEGORY = 'breakpoints'
SHORT_HELP = 'Disable some breakpoints'

$VERBOSE = old_verbose
CATEGORY = 'breakpoints'
SHORT_HELP = 'Disable some breakpoints'
}

def initialize(proc)
super
Expand Down
16 changes: 8 additions & 8 deletions processor/command/down.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
# direction (set by DIRECTION) reversed.
class Trepan::Command::DownCommand < Trepan::Command::UpCommand

# Silence already initialized constant .. warnings
old_verbose = $VERBOSE
$VERBOSE = nil
HELP = <<-HELP
Trepan::Util.suppress_warnings {
old_verbose = $VERBOSE
$VERBOSE = nil
HELP = <<-HELP
#{NAME} [count]
Move the current frame down in the stack trace (to a newer frame). 0
Expand All @@ -19,10 +19,10 @@ class Trepan::Command::DownCommand < Trepan::Command::UpCommand
See also 'up' and 'frame'.
HELP

ALIASES = %w(d)
NAME = File.basename(__FILE__, '.rb')
SHORT_HELP = 'Move frame in the direction of the caller of the last-selected frame'
$VERBOSE = old_verbose
ALIASES = %w(d)
NAME = File.basename(__FILE__, '.rb')
SHORT_HELP = 'Move frame in the direction of the caller of the last-selected frame'
}

def initialize(proc)
super
Expand Down
16 changes: 7 additions & 9 deletions processor/command/enable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,20 @@
# ENABLE_PARM below).
class Trepan::Command::EnableCommand < Trepan::Command::DisableCommand

# Silence already initialized constant .. warnings
old_verbose = $VERBOSE
$VERBOSE = nil
NAME = File.basename(__FILE__, '.rb')
HELP = <<-HELP
Trepan::Util.suppress_warnings {
NAME = File.basename(__FILE__, '.rb')
HELP = <<-HELP
#{NAME} BPNUM1 [BPNUM2 ...]
Enables breakpoints BPNUM1. Breakpoints numbers are given as a space-
separated list numbers.
See also "info break" to get a list of breakpoints.
HELP

ALIASES = %w(en)
SHORT_HELP = 'Enable some breakpoints'
$VERBOSE = old_verbose
ALIASES = %w(en)
SHORT_HELP = 'Enable some breakpoints'
}

def run(args)
if args.size == 1
Expand Down
2 changes: 2 additions & 0 deletions processor/command/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ class Trepan::Command::InfoCommand < Trepan::SubcommandMgr

if __FILE__ == $0
require_relative '../mock'
require 'ruby-debug'; Debugger.start; debugger
dbgr, cmd = MockDebugger::setup
cmd.run(['info', 'iv'])
end
14 changes: 10 additions & 4 deletions processor/command/info_subcmd/globals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ class Trepan::Subcommand::InfoGlobals < Trepan::Subcommand
NEED_STACK = true
end

def get_names
global_variables
end

def run(args)
if args.size == 3
if 0 == 'names'.index(args[-1].downcase)
if global_variables.empty?
names = get_names()
if names.empty?
msg "No global variables defined."
else
section "Global variable names:"
Expand All @@ -40,12 +45,13 @@ def run(args)
errmsg("unrecognized argument #{args[2]}")
end
elsif args.size == 2
if global_variables.empty?
names = get_names
if names.empty?
msg "No global variables defined."
else
section "Global variables:"
global_variables.sort.each do |var_name|
s = @proc.debug_eval(var_name)
name.sort.each do |var_name|
s = @proc.debug_eval(var_name.to_s)
msg("#{var_name} = #{s.inspect}")
end
end
Expand Down
38 changes: 38 additions & 0 deletions processor/command/info_subcmd/iv.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
require_relative 'locals'

class Trepan::Subcommand::InfoIv < Trepan::Subcommand::InfoLocals
Trepan::Util.suppress_warnings {
Trepanning::Subcommand.set_name_prefix(__FILE__, self)
HELP = <<-EOH
#{CMD}
#{CMD} [names]
Show instance variables 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 instance variables of the current stack frame'
MIN_ARGS = 0
MAX_ARGS = 1
MIN_ABBREV = 'iv'.size
NEED_STACK = true
}

def get_names
@proc.debug_eval('self.instance_variables')
end

def run(args)
run_for_type(args, 'instance')
end
end

if __FILE__ == $0
# Demo it.
require_relative '../../mock'
cmd = MockDebugger::sub_setup(Trepan::Subcommand::InfoIv, false)
cmd.run(cmd.prefix)
cmd.run(cmd.prefix + ['name'])
end
34 changes: 20 additions & 14 deletions processor/command/info_subcmd/locals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
require 'columnize'
require_relative '../base/subcmd'
require_relative '../../../app/frame'
require_relative '../../../app/util'

class Trepan::Subcommand::InfoLocals < Trepan::Subcommand
unless defined?(HELP)
Trepan::Util.suppress_warnings {
Trepanning::Subcommand.set_name_prefix(__FILE__, self)
HELP = <<-EOH
#{CMD}
Expand All @@ -21,22 +22,22 @@ class Trepan::Subcommand::InfoLocals < Trepan::Subcommand
MAX_ARGS = 1
MIN_ABBREV = 'lo'.size
NEED_STACK = true
end
}

def get_local_names
def get_names
@proc.frame.local_variables.keys
end

def run(args)
def run_for_type(args, type)
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."
names = get_names()
if names.empty?
msg "No #{type} variables defined."
else
section "Local variable names:"
section "#{type.capitalize} variable names:"
width = settings[:maxwidth]
mess = Columnize::columnize(local_names,
mess = Columnize::columnize(names,
@proc.settings[:maxwidth], ' ',
false, true, ' ' * 2).chomp
msg mess
Expand All @@ -45,19 +46,24 @@ def run(args)
errmsg("unrecognized argument #{args[2]}")
end
elsif args.size == 2
local_names = get_local_names
if local_names.empty?
msg "No local variables defined."
names = get_names
if names.empty?
msg "No #{type} variables defined."
else
section "Local variables:"
@proc.frame.local_variables.each do |var_name, var_value|
section "#{type.capitalize} variables:"
get_names.each do |var_name|
var_value = @proc.safe_rep(@proc.debug_eval_no_errmsg(var_name).inspect)
msg("#{var_name} = #{var_value}")
end
end
else
errmsg("Wrong number of arguments #{args.size}")
end
end

def run(args)
run_for_type(args, 'local')
end
end

if __FILE__ == $0
Expand Down
23 changes: 11 additions & 12 deletions processor/command/up.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
require 'rubygems'; require 'require_relative'
require_relative 'base/cmd'
require_relative '../../app/util'

# up command. Like 'down' butthe direction (set by DIRECTION) is different.
# up command. Like 'down' but the direction (set by DIRECTION) is different.
#
# NOTE: The down command subclasses this, so beware when changing!
class Trepan::Command::UpCommand < Trepan::Command

# Silence already initialized constant .. warnings
old_verbose = $VERBOSE
$VERBOSE = nil
NAME = File.basename(__FILE__, '.rb')
HELP = <<-HELP
Trepan::Util.suppress_warnings {
NAME = File.basename(__FILE__, '.rb')
HELP = <<-HELP
#{NAME} [count]
Move the current frame up in the stack trace (to an older frame). 0 is
Expand All @@ -20,12 +19,12 @@ class Trepan::Command::UpCommand < Trepan::Command
See also 'down' and 'frame'.
HELP

ALIASES = %w(u)
CATEGORY = 'stack'
MAX_ARGS = 1 # Need at most this many
NEED_STACK = true
SHORT_HELP = 'Move frame in the direction of the caller of the last-selected frame'
$VERBOSE = old_verbose
ALIASES = %w(u)
CATEGORY = 'stack'
MAX_ARGS = 1 # Need at most this many
NEED_STACK = true
SHORT_HELP = 'Move frame in the direction of the caller of the last-selected frame'
}

def complete(prefix)
@proc.frame_complete(prefix, @direction)
Expand Down

0 comments on commit ceb2745

Please sign in to comment.