Permalink
Browse files

Add "set pc" to modify the program counter. Perhaps one day we will

add a "skip" command.
  • Loading branch information...
1 parent d00680a commit 33c2a741ddb98c6b02da4efe11994ad5286efe9b @rocky committed Dec 1, 2012
Showing with 56 additions and 1 deletion.
  1. +1 −1 app/options.rb
  2. +55 −0 processor/command/set_subcmd/pc.rb
View
2 app/options.rb
@@ -8,7 +8,7 @@
class Trepan
require_relative 'default'
- VERSION = '0.1.6'
+ VERSION = '0.2'
PROGRAM = 'trepan'
def self.show_version
View
55 processor/command/set_subcmd/pc.rb
@@ -0,0 +1,55 @@
+# -*- coding: utf-8 -*-
+require_relative '../base/subcmd'
+
+class Trepan::Subcommand::SetPc < Trepan::Subcommand
+ unless defined?(HELP)
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
+ HELP = 'Set VM program counter (PC)'
+ IN_LIST = true
+ MIN_ABBREV = 'pc'.size
+ end
+
+ def run(args)
+ # FIXME handle c-return
+ # unless %w(return c-return).member?(@proc.event)
+ if args.size < 3
+ errmsg "Too few arguments - the 'pc' command requires a value"
+ return
+ end
+ new_val_str = args[2..-1].join(' ')
+ begin
+ new_val = @proc.debug_eval(new_val_str)
+ rescue StandardError, ScriptError => e
+ return
+ end
+ msg("Old value was: %s" % @proc.frame.pc_offset.inspect)
+ @proc.frame.pc_offset = new_val
+ msg("New value is: %s" % new_val.inspect)
+ end
+
+end
+
+if __FILE__ == $0
+ # Demo it.
+ require_relative %w(.. .. mock)
+ require_relative %w(.. .. subcmd)
+ name = File.basename(__FILE__, '.rb')
+
+ # FIXME: DRY the below code
+ dbgr, cmd = MockDebugger::setup('set')
+ subcommand = Debugger::Subcommand::SetPc.new(cmd)
+ testcmdMgr = Debugger::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

0 comments on commit 33c2a74

Please sign in to comment.