def test_get_an_int(self): self.assertEqual(0, Mcmdfns.get_an_int(self.errmsg, '0', 'foo', 0)) self.assertEqual(0, len(self.errors)) self.assertEqual(6, Mcmdfns.get_an_int(self.errmsg, '6*1', 'foo', 5)) self.assertEqual(0, len(self.errors)) self.assertEqual( None, Mcmdfns.get_an_int(self.errmsg, '0', '0 is too small', 5)) self.assertEqual(1, len(self.errors)) self.assertEqual( None, Mcmdfns.get_an_int(self.errmsg, '4+a', '4+a is invalid', 5)) self.assertEqual('4+a is invalid', self.errors[-1]) return
def test_get_an_int(self): self.assertEqual(0, Mcmdfns.get_an_int(self.errmsg, '0', 'foo', 0)) self.assertEqual(0, len(self.errors)) self.assertEqual(6, Mcmdfns.get_an_int(self.errmsg, '6*1', 'foo', 5)) self.assertEqual(0, len(self.errors)) self.assertEqual(None, Mcmdfns.get_an_int(self.errmsg, '0', '0 is too small', 5)) self.assertEqual(1, len(self.errors)) self.assertEqual(None, Mcmdfns.get_an_int(self.errmsg, '4+a', '4+a is invalid', 5)) self.assertEqual('4+a is invalid', self.errors[-1]) return
def run(self, args): if self.core.is_running(): proc = self.proc n = len(proc.vm.frame.stack) if n == 0: self.errmsg( "VM evaluation stack is empty - nothing to peek at at") return if len(args) == 0: number = 0 else: print(args) number = get_an_int( self.errmsg, args[0], "The 'peek' command requires an integer greater than 0.", 0, n - 1) if number is None: return # FIXME: vm.peek seems to be 1 origin. It should have been 0 origin I think. result = proc.vm.peek(number + 1) self.msg( f"VM evaluation stack at {number}: {result} {type(result)}") return None
def adjust_relative(proc_obj, name, args, signum): if not proc_obj.stack: proc_obj.errmsg("Program has no stack frame set.") return False if len(args) == 1: count = 1 else: count_str = args[1] low, high = frame_low_high(proc_obj, signum) count = Mcmdfns.get_an_int( proc_obj.errmsg, count_str, ("The '%s' command argument must eval to" + " an integer. Got: %s") % (name, count_str), low, high) if count is None: return pass adjust_frame(proc_obj, name, pos=signum * count, absolute_pos=False) return
def adjust_relative(proc_obj, name, args, signum): if not proc_obj.stack: proc_obj.errmsg("Program has no stack frame set.") return False if len(args) == 1: count = 1 else: count_str = args[1] low, high = frame_low_high(proc_obj, signum) count = Mcmdfns.get_an_int( proc_obj.errmsg, count_str, ("The '%s' command argument must eval to" + " an integer. Got: %s") % (name, count_str), low, high ) if count is None: return pass adjust_frame(proc_obj, name, pos=signum*count, absolute_pos=False) return
def run(self, args): mainfile = self.core.filename(None) if self.core.is_running(): proc = self.proc is_offset = True n = len(args) if n == 2: if args[0] == "=": args[0] = args[1] else: try: opts, args = getopt(args, "hlo", ["help", "line", "offset"]) except GetoptError as err: # print help information and exit: print( str(err) ) # will print something like "option -a not recognized" return for o, a in opts: if o in ("-h", "--help"): proc.commands["help"].run(["help", "set", "pc"]) return elif o in ( "-l", "--line", ): is_offset = False elif o in ("-o", "--offset"): is_offset = True else: self.errmsg("unhandled option '%s'" % o) pass pass pass frame = proc.frame if frame: code = frame.f_code if is_offset: min_value = 0 max_value = len(code.co_code) - 1 elif len(code.co_lnotab) > 0: min_value = code.co_firstlineno # FIXME: put this in a function in xdis somewhere. # Also: won't need ord() in Python 2.x # max_value = min_value + sum([ord(i) for i in code.co_lnotab[1::2]]) max_value = min_value + sum(code.co_lnotab[1::2]) else: min_value = max_value = code.co_firstline offset = get_an_int( self.errmsg, args[0], "The 'pc' command requires an integer offset or a line.", min_value, max_value, ) if offset is None: return None # FIXME: We check that offset points to an # opcode or a valid line as opposed to an operand if not is_offset: self.errmsg("Sorry, line numbers not handled right now.") return None self.list_offset = frame.f_lasti = offset frame.fallthrough = False self.list_lineno = frame.f_lineno = frame.line_number() self.msg("Execution set to resume at offset %d" % offset) self.return_status = "skip" return None else: self.errmsg("Oddly, a frame is not set - nothing done.") pass else: if mainfile: part1 = "Python program '%s'" % mainfile msg = "is not currently running. " self.msg(wrapped_lines(part1, msg, self.settings["width"])) else: self.msg("No Python program is currently running.") pass self.msg(self.core.execution_status) pass return None