def interact(self, banner=None, **parms): """Closely emulate the interactive Python console. The optional banner argument specify the banner to print before the first interaction; by default it prints a banner similar to the one printed by the real Python interpreter, followed by the current class name in parentheses (so as not to confuse this with the real interpreter -- since it's so close!). """ global optdir global rcCmd #sys.stderr.write("#DBX %s: enter InteractiveConsole.interact()\n" % (time.ctime())) # connect to command parser self.parser = parms['parser'] ## # if there are good_trap and/or bad_trap in symbol file, register ## # those as breakpoints ## # TODO by default, no breakpoint for good/bad_trap is set in sam, ## # we need an option to allow setting of those breakpoints. ## if parms['reposit'].symTable and not optdir.has_key('--blaze'): ## trapList = parms['reposit'].symTable.getTraps() ## for (trap,vaddr) in trapList: ## cmd = 'break %#x' % (vaddr) ## if self.parser.parseCmd(cmd, **parms): ## sys.stderr.write('ERROR: un-expected return value from parseCmd()\n') # if there are command(s) specified in config, execute those first _configRC = None if parms.has_key('confRC'): _configRC = parms['confRC'] tmp = '.rs_config_cmd' fdtmp = open(tmp, 'w') if _configRC: if _configRC.getObjData(ReadConfigDiag.TYPE_SYS_CONFIG, RC_SYS_CONFIG_OBJ, RC_COMMAND, silent=1): #sys.stderr.write("# %s: process config/init cmd\n" % (time.ctime())) for cmd in _configRC.getObjData(ReadConfigDiag.TYPE_SYS_CONFIG, RC_SYS_CONFIG_OBJ, RC_COMMAND): cmd = cmd.strip() # if get_addr() is part of the command, better resolve # that here, so we don't need to worry about that later # when execute the command index = cmd.find('get_addr') if index > -1: lop = cmd[:index] rop = cmd[index:] try: cmd = '%s%s' % (lop, eval(rop)) except: pass fdtmp.write('%s\n' % (cmd)) for cmd in rcCmd: fdtmp.write('%s\n' % (cmd)) fdtmp.close() # execute the commands specified in config file, if a command # cannot be run, just ignore it. self.parseExecfile('execfile("%s")' % (tmp), ignore=1, **parms) #sys.stderr.write("# %s: DBX: done config/init cmd\n" % (time.ctime())) # set prompt symbol if _configRC: prompt = _configRC.getObjData(ReadConfigDiag.TYPE_SYS_CONFIG, RC_SYS_CONFIG_OBJ, RC_PROMPT) else: prompt = 'sam' parms['reposit'].prompt = prompt try: sys.ps1 except AttributeError: sys.ps1 = "%s>>> " % (prompt) try: sys.ps2 except AttributeError: sys.ps2 = "%s... " % (prompt) try: sys.ps3 except AttributeError: sys.ps3 = "%s!!! " % (prompt) cprt = 'Type "copyright", "credits" or "license" for more information.' if banner is None: self.write("Python %s on %s\n%s\n(%s)\n" % (sys.version, sys.platform, cprt, self.__class__.__name__)) else: #self.write("# %s: %s\n" % (time.ctime(), str(banner))) pass more = 0 while 1: try: if more: prompt = sys.ps2 elif no_sam == 1: prompt = sys.ps1 elif (no_sam == 0) and sam.is_stopped(): prompt = sys.ps1 else: prompt = sys.ps3 try: line = self.raw_input(prompt) except EOFError: self.write("\n") break else: line = self.parser.parseCmd(line, **parms) if line != None: # most excepts are handled by push() and its inner # methods, so we won't see them here. if re.match(execfileRE, line): try: more = self.parseExecfile(line, **parms) except SystemExit: raise except: more = self.push(line) else: more = self.push(line) else: # to play it safe, flush out buffer when parser returns # None self.resetbuffer() more = 0 except KeyboardInterrupt: self.write("\nKeyboardInterrupt\n") self.resetbuffer() more = 0
def issueCmd (self, cmd, output, riesReposit): """ """ tokens = cmd.split() if tokens[0] in self.cmdMap: if tokens[0] == 'file': # process the file line-by-line return 'execfile("%s")' % (tokens[1]) else: if ((tokens[0] == 'ssi') or (tokens[0] == 'runfast')): sys.stderr.write('ERROR: command %s is not supported in SAM, use "stepi N" or "run N" instead\n' % (tokens[0])) return None elif (tokens[0] == 'run'): if (len(tokens) > 1): # 'run' is a non-blocking call, if we see 'run N', # convert that to 'stepi N' cmd = 'stepi ' + ' '.join(tokens[1:]) else: # 'run' alone becomes a non-blocking call, we should # get UI prompt back right the way cmd = tokens[0] elif (tokens[0] == 'pmask'): if len(tokens) == 1: # query current pmask sys.stderr.write('%#x\n' % riesReposit.pmask) return None else: if not sam.is_stopped(): sys.stderr.write('Simulator is running, issue "stop" before changing pmask\n') return None # set blaze penable accordingly newMask = long(tokens[1], 16) toDisable = riesReposit.pmask & (~newMask & 0xffffffffffffffffL) toEnable = (~riesReposit.pmask & 0xffffffffffffffffL) & newMask #sys.stderr.write('DBX: newMask=%#x toDisable=%#x toEnable=%#x\n' % (newMask, toDisable, toEnable)) # disable currently enabled, but to be disabled strands for i in range(riesReposit.blazeNumcpu): if ((toDisable >> i) &0x1) == 0x1: cmd = 'pdisable th%d' % i #sys.stderr.write('DBX: cmd=%s\n' % cmd) #self.blaze.command(cmd) sam.ui_exec(cmd); # disable currently disabled, but to be enabled strands for i in range(riesReposit.blazeNumcpu): if ((toEnable >> i) &0x1) == 0x1: cmd = 'penable th%d' % i #sys.stderr.write('DBX: cmd=%s\n' % cmd) #self.blaze.command(cmd) sam.ui_exec(cmd); # update to the new mask riesReposit.pmask = newMask return None if type(output) is types.ListType: #output = output.append(self.blaze.command(cmd)) sam.ui_exec(cmd); else: #self.blaze.command(cmd) sam.ui_exec(cmd); if cmd == 'run': riesReposit.running = 1 #print "start running...." #sys.ps1 = 'run>' #elif (cmd == 'stop') or (cmd.startswith('stepi ')): elif cmd == 'stop': # don't check 'stepi' here. If we first do 'run', then # enter either 'run N' or 'stepi N', blaze will issue # 'is running' and return without doing anything, at this # time blaze is still in the first 'run', so we cannot # set running to 0 for 'run N' or 'stepi N', as they may # not be executed at all. riesReposit.running = 0 #print "stop command was issued." #sys.ps1 = 'stop>' if len(tokens) > 2 and (tokens[0] == 'mod' and tokens[1] == 'load'): # mod load xxx yyy, register 'xxx' as a command prefix, as all # module 'yyy' related commands will use that prefix if not tokens[2] in self.cmdMap: self.cmdMap.append(tokens[2]) return None else: return cmd