Sha256: 29c0bf53a03f38f9c9ee83c35071e7c316c3d8b1c78d8deeae02c7b32488c0dc

Contents?: true

Size: 1.66 KB

Versions: 6

Compression:

Stored size: 1.66 KB

Contents

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

class Trepan::Subcommand::SetSp < Trepan::Subcommand
  unless defined?(HELP)
    Trepanning::Subcommand.set_name_prefix(__FILE__, self)
    HELP         = 'Set a stack pointer register'
    IN_LIST      = true
    MIN_ABBREV   = 'sp'.size
  end

  def run(args)
    # FIXME handle c-return
    # unless %w(return c-return).member?(@proc.event)
    if args.size < 4
      errmsg "Too few arguments - the 'sp' command requires number and a value"
      return
    end
    msg_on_error = "set SP requires an integer index"
    index = @proc.get_an_int(args[2], 
                             :msg_on_error => msg_on_error
                             )
    return unless index
    new_val_str = args[3..-1].join(' ')
    begin
      new_val = @proc.debug_eval(new_val_str)
    rescue StandardError, ScriptError => e
      return
    end
    msg("Old value was: %s" % @proc.frame.sp(index).inspect)
    @proc.frame.sp_set(index, new_val).inspect
    msg("New value is: %s" % new_val.inspect)
  end

end

if __FILE__ == $0
  # Demo it.
  require_relative '../../mock'
  require_relative '../../subcmd'
  name = File.basename(__FILE__, '.rb')

  # FIXME: DRY the below code
  dbgr, cmd = MockTrepan::setup('set')
  subcommand = Trepan::Subcommand::SetSp.new(cmd)
  testcmdMgr = Trepan::Subcmd.new(subcommand)

  def subcommand.msg(message)
    puts message
  end
  def subcommand.msg_nocr(message)
    print message
  end
  def subcommand.errmsg(message)
    puts message
  end
  subcommand.run(%w(20))
  name = File.basename(__FILE__, '.rb')
  subcommand.summary_help(name)
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
trepanning-0.1.6 processor/command/set_subcmd/sp.rb
trepanning-0.1.4 processor/command/set_subcmd/sp.rb
trepanning-0.1.3 processor/command/set_subcmd/sp.rb
trepanning-0.1.2 processor/command/set_subcmd/sp.rb
trepanning-0.1.1 processor/command/set_subcmd/sp.rb
trepanning-0.1.0 processor/command/set_subcmd/sp.rb