main.py revision 11338
12889Sbinkertn@umich.edu# Copyright (c) 2005 The Regents of The University of Michigan 22889Sbinkertn@umich.edu# All rights reserved. 32889Sbinkertn@umich.edu# 42889Sbinkertn@umich.edu# Redistribution and use in source and binary forms, with or without 52889Sbinkertn@umich.edu# modification, are permitted provided that the following conditions are 62889Sbinkertn@umich.edu# met: redistributions of source code must retain the above copyright 72889Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer; 82889Sbinkertn@umich.edu# redistributions in binary form must reproduce the above copyright 92889Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer in the 102889Sbinkertn@umich.edu# documentation and/or other materials provided with the distribution; 112889Sbinkertn@umich.edu# neither the name of the copyright holders nor the names of its 122889Sbinkertn@umich.edu# contributors may be used to endorse or promote products derived from 132889Sbinkertn@umich.edu# this software without specific prior written permission. 142889Sbinkertn@umich.edu# 152889Sbinkertn@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 162889Sbinkertn@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 172889Sbinkertn@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 182889Sbinkertn@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 192889Sbinkertn@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 202889Sbinkertn@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 212889Sbinkertn@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 222889Sbinkertn@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 232889Sbinkertn@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 242889Sbinkertn@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 252889Sbinkertn@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 262889Sbinkertn@umich.edu# 272889Sbinkertn@umich.edu# Authors: Nathan Binkert 282889Sbinkertn@umich.edu 294850Snate@binkert.orgimport code 304850Snate@binkert.orgimport datetime 314850Snate@binkert.orgimport os 324850Snate@binkert.orgimport socket 334850Snate@binkert.orgimport sys 344850Snate@binkert.org 352889Sbinkertn@umich.edu__all__ = [ 'options', 'arguments', 'main' ] 362889Sbinkertn@umich.edu 378327Sgblack@eecs.umich.eduusage="%prog [gem5 options] script.py [script options]" 385470Snate@binkert.orgversion="%prog 2.0" 398333Snate@binkert.orgbrief_copyright=\ 408333Snate@binkert.org "gem5 is copyrighted software; use the --copyright option for details." 412889Sbinkertn@umich.edu 428234Snate@binkert.orgdef parse_options(): 438234Snate@binkert.org import config 448234Snate@binkert.org from options import OptionParser 452889Sbinkertn@umich.edu 468234Snate@binkert.org options = OptionParser(usage=usage, version=version, 478234Snate@binkert.org description=brief_copyright) 488234Snate@binkert.org option = options.add_option 498234Snate@binkert.org group = options.set_group 502889Sbinkertn@umich.edu 518234Snate@binkert.org # Help options 528234Snate@binkert.org option('-B', "--build-info", action="store_true", default=False, 538234Snate@binkert.org help="Show build information") 548234Snate@binkert.org option('-C', "--copyright", action="store_true", default=False, 558234Snate@binkert.org help="Show full copyright information") 568234Snate@binkert.org option('-R', "--readme", action="store_true", default=False, 578234Snate@binkert.org help="Show the readme") 582889Sbinkertn@umich.edu 598234Snate@binkert.org # Options for configuring the base simulator 608234Snate@binkert.org option('-d', "--outdir", metavar="DIR", default="m5out", 618234Snate@binkert.org help="Set the output directory to DIR [Default: %default]") 628234Snate@binkert.org option('-r', "--redirect-stdout", action="store_true", default=False, 638234Snate@binkert.org help="Redirect stdout (& stderr, without -e) to file") 648234Snate@binkert.org option('-e', "--redirect-stderr", action="store_true", default=False, 658234Snate@binkert.org help="Redirect stderr to file") 668234Snate@binkert.org option("--stdout-file", metavar="FILE", default="simout", 678234Snate@binkert.org help="Filename for -r redirection [Default: %default]") 688234Snate@binkert.org option("--stderr-file", metavar="FILE", default="simerr", 698234Snate@binkert.org help="Filename for -e redirection [Default: %default]") 708234Snate@binkert.org option('-i', "--interactive", action="store_true", default=False, 718234Snate@binkert.org help="Invoke the interactive interpreter after running the script") 728234Snate@binkert.org option("--pdb", action="store_true", default=False, 738234Snate@binkert.org help="Invoke the python debugger before running the script") 748234Snate@binkert.org option('-p', "--path", metavar="PATH[:PATH]", action='append', split=':', 758234Snate@binkert.org help="Prepend PATH to the system path when invoking the script") 768234Snate@binkert.org option('-q', "--quiet", action="count", default=0, 778234Snate@binkert.org help="Reduce verbosity") 788234Snate@binkert.org option('-v', "--verbose", action="count", default=0, 798234Snate@binkert.org help="Increase verbosity") 802889Sbinkertn@umich.edu 818234Snate@binkert.org # Statistics options 828234Snate@binkert.org group("Statistics Options") 838234Snate@binkert.org option("--stats-file", metavar="FILE", default="stats.txt", 848234Snate@binkert.org help="Sets the output file for statistics [Default: %default]") 855773Snate@binkert.org 868234Snate@binkert.org # Configuration Options 878234Snate@binkert.org group("Configuration Options") 888234Snate@binkert.org option("--dump-config", metavar="FILE", default="config.ini", 898234Snate@binkert.org help="Dump configuration output file [Default: %default]") 908664SAli.Saidi@ARM.com option("--json-config", metavar="FILE", default="config.json", 918664SAli.Saidi@ARM.com help="Create JSON output of the configuration [Default: %default]") 928998Suri.wiener@arm.com option("--dot-config", metavar="FILE", default="config.dot", 938998Suri.wiener@arm.com help="Create DOT & pdf outputs of the configuration [Default: %default]") 942889Sbinkertn@umich.edu 958234Snate@binkert.org # Debugging options 968234Snate@binkert.org group("Debugging Options") 9711299Ssteve.reinhardt@amd.com option("--debug-break", metavar="TICK[,TICK]", action='append', split=',', 9811299Ssteve.reinhardt@amd.com help="Create breakpoint(s) at TICK(s) " \ 9911299Ssteve.reinhardt@amd.com "(kills process if no debugger attached)") 1008234Snate@binkert.org option("--debug-help", action='store_true', 1019960Sandreas.hansson@arm.com help="Print help on debug flags") 1028234Snate@binkert.org option("--debug-flags", metavar="FLAG[,FLAG]", action='append', split=',', 1039960Sandreas.hansson@arm.com help="Sets the flags for debug output (-FLAG disables a flag)") 10411299Ssteve.reinhardt@amd.com option("--debug-start", metavar="TICK", type='int', 10511304Ssteve.reinhardt@amd.com help="Start debug output at TICK") 10611338SMichael.Lebeane@amd.com option("--debug-end", metavar="TICK", type='int', 10711338SMichael.Lebeane@amd.com help="End debug output at TICK") 1089960Sandreas.hansson@arm.com option("--debug-file", metavar="FILE", default="cout", 1099960Sandreas.hansson@arm.com help="Sets the output file for debug [Default: %default]") 1109960Sandreas.hansson@arm.com option("--debug-ignore", metavar="EXPR", action='append', split=':', 1119960Sandreas.hansson@arm.com help="Ignore EXPR sim objects") 1128234Snate@binkert.org option("--remote-gdb-port", type='int', default=7000, 1138234Snate@binkert.org help="Remote gdb base port (set to 0 to disable listening)") 1142889Sbinkertn@umich.edu 1158234Snate@binkert.org # Help options 1168234Snate@binkert.org group("Help Options") 1178234Snate@binkert.org option("--list-sim-objects", action='store_true', default=False, 1188234Snate@binkert.org help="List all built-in SimObjects, their params and default values") 1196171Snate@binkert.org 1208234Snate@binkert.org # load the options.py config file to allow people to set their own 1218234Snate@binkert.org # default options 1228234Snate@binkert.org options_file = config.get('options.py') 1238234Snate@binkert.org if options_file: 1248234Snate@binkert.org scope = { 'options' : options } 1258234Snate@binkert.org execfile(options_file, scope) 1268234Snate@binkert.org 1278234Snate@binkert.org arguments = options.parse_args() 1288234Snate@binkert.org return options,arguments 1296171Snate@binkert.org 1308219Snate@binkert.orgdef interact(scope): 1318327Sgblack@eecs.umich.edu banner = "gem5 Interactive Console" 1329512Sandreas@sandberg.pp.se 1339512Sandreas@sandberg.pp.se ipshell = None 1349512Sandreas@sandberg.pp.se prompt_in1 = "gem5 \\#> " 1359512Sandreas@sandberg.pp.se prompt_out = "gem5 \\#: " 1369512Sandreas@sandberg.pp.se 1379512Sandreas@sandberg.pp.se # Is IPython version 0.10 or earlier available? 1388219Snate@binkert.org try: 1398219Snate@binkert.org from IPython.Shell import IPShellEmbed 1409512Sandreas@sandberg.pp.se ipshell = IPShellEmbed(argv=["-prompt_in1", prompt_in1, 1419512Sandreas@sandberg.pp.se "-prompt_out", prompt_out], 1429512Sandreas@sandberg.pp.se banner=banner, user_ns=scope) 1439512Sandreas@sandberg.pp.se except ImportError: 1449512Sandreas@sandberg.pp.se pass 1459512Sandreas@sandberg.pp.se 1469512Sandreas@sandberg.pp.se # Is IPython version 0.11 or later available? 1479512Sandreas@sandberg.pp.se if not ipshell: 1489512Sandreas@sandberg.pp.se try: 1499512Sandreas@sandberg.pp.se import IPython 1509512Sandreas@sandberg.pp.se from IPython.config.loader import Config 1519512Sandreas@sandberg.pp.se from IPython.frontend.terminal.embed import InteractiveShellEmbed 1529512Sandreas@sandberg.pp.se 1539512Sandreas@sandberg.pp.se cfg = Config() 1549512Sandreas@sandberg.pp.se cfg.PromptManager.in_template = prompt_in1 1559512Sandreas@sandberg.pp.se cfg.PromptManager.out_template = prompt_out 1569512Sandreas@sandberg.pp.se ipshell = InteractiveShellEmbed(config=cfg, user_ns=scope, 1579512Sandreas@sandberg.pp.se banner1=banner) 1589512Sandreas@sandberg.pp.se except ImportError: 1599512Sandreas@sandberg.pp.se pass 1609512Sandreas@sandberg.pp.se 1619512Sandreas@sandberg.pp.se if ipshell: 1628219Snate@binkert.org ipshell() 1639512Sandreas@sandberg.pp.se else: 1649512Sandreas@sandberg.pp.se # Use the Python shell in the standard library if IPython 1659512Sandreas@sandberg.pp.se # isn't available. 1668219Snate@binkert.org code.InteractiveConsole(scope).interact(banner) 1678219Snate@binkert.org 1688234Snate@binkert.orgdef main(*args): 1698245Snate@binkert.org import m5 1708245Snate@binkert.org 1715801Snate@binkert.org import core 1725801Snate@binkert.org import debug 1735801Snate@binkert.org import defines 1744167Sbinkertn@umich.edu import event 1754042Sbinkertn@umich.edu import info 1765801Snate@binkert.org import stats 1775799Snate@binkert.org import trace 1785799Snate@binkert.org 1798234Snate@binkert.org from util import fatal 1808234Snate@binkert.org 1818234Snate@binkert.org if len(args) == 0: 1828234Snate@binkert.org options, arguments = parse_options() 1838234Snate@binkert.org elif len(args) == 2: 1848234Snate@binkert.org options, arguments = args 1858234Snate@binkert.org else: 1868234Snate@binkert.org raise TypeError, "main() takes 0 or 2 arguments (%d given)" % len(args) 1878234Snate@binkert.org 1888245Snate@binkert.org m5.options = options 1898245Snate@binkert.org 1905799Snate@binkert.org def check_tracing(): 1915799Snate@binkert.org if defines.TRACING_ON: 1925799Snate@binkert.org return 1935799Snate@binkert.org 1945802Snate@binkert.org fatal("Tracing is not enabled. Compile with TRACING_ON") 1952889Sbinkertn@umich.edu 1969983Sstever@gmail.com # Set the main event queue for the main thread. 1979983Sstever@gmail.com event.mainq = event.getEventQueue(0) 1989983Sstever@gmail.com event.setEventQueue(event.mainq) 1999983Sstever@gmail.com 2005524Sstever@gmail.com if not os.path.isdir(options.outdir): 2015524Sstever@gmail.com os.makedirs(options.outdir) 2025524Sstever@gmail.com 2035524Sstever@gmail.com # These filenames are used only if the redirect_std* options are set 2045524Sstever@gmail.com stdout_file = os.path.join(options.outdir, options.stdout_file) 2055524Sstever@gmail.com stderr_file = os.path.join(options.outdir, options.stderr_file) 2065524Sstever@gmail.com 2075524Sstever@gmail.com # Print redirection notices here before doing any redirection 2085524Sstever@gmail.com if options.redirect_stdout and not options.redirect_stderr: 2095524Sstever@gmail.com print "Redirecting stdout and stderr to", stdout_file 2105524Sstever@gmail.com else: 2115524Sstever@gmail.com if options.redirect_stdout: 2125524Sstever@gmail.com print "Redirecting stdout to", stdout_file 2135524Sstever@gmail.com if options.redirect_stderr: 2145524Sstever@gmail.com print "Redirecting stderr to", stderr_file 2155524Sstever@gmail.com 2165524Sstever@gmail.com # Now redirect stdout/stderr as desired 2175524Sstever@gmail.com if options.redirect_stdout: 2185524Sstever@gmail.com redir_fd = os.open(stdout_file, os. O_WRONLY | os.O_CREAT | os.O_TRUNC) 2195524Sstever@gmail.com os.dup2(redir_fd, sys.stdout.fileno()) 2205524Sstever@gmail.com if not options.redirect_stderr: 2215524Sstever@gmail.com os.dup2(redir_fd, sys.stderr.fileno()) 2225524Sstever@gmail.com 2235524Sstever@gmail.com if options.redirect_stderr: 2245524Sstever@gmail.com redir_fd = os.open(stderr_file, os. O_WRONLY | os.O_CREAT | os.O_TRUNC) 2255524Sstever@gmail.com os.dup2(redir_fd, sys.stderr.fileno()) 2265524Sstever@gmail.com 2272889Sbinkertn@umich.edu done = False 2284850Snate@binkert.org 2294850Snate@binkert.org if options.build_info: 2304850Snate@binkert.org done = True 2314850Snate@binkert.org print 'Build information:' 2324850Snate@binkert.org print 2335801Snate@binkert.org print 'compiled %s' % defines.compileDate; 2344850Snate@binkert.org print 'build options:' 2355801Snate@binkert.org keys = defines.buildEnv.keys() 2364850Snate@binkert.org keys.sort() 2374850Snate@binkert.org for key in keys: 2385801Snate@binkert.org val = defines.buildEnv[key] 2394850Snate@binkert.org print ' %s = %s' % (key, val) 2404850Snate@binkert.org print 2414850Snate@binkert.org 2422889Sbinkertn@umich.edu if options.copyright: 2432889Sbinkertn@umich.edu done = True 2448333Snate@binkert.org print info.COPYING 2452889Sbinkertn@umich.edu print 2462889Sbinkertn@umich.edu 2472889Sbinkertn@umich.edu if options.readme: 2482889Sbinkertn@umich.edu done = True 2492889Sbinkertn@umich.edu print 'Readme:' 2502889Sbinkertn@umich.edu print 2512889Sbinkertn@umich.edu print info.README 2522889Sbinkertn@umich.edu print 2532889Sbinkertn@umich.edu 2548232Snate@binkert.org if options.debug_help: 2554053Sbinkertn@umich.edu done = True 2565799Snate@binkert.org check_tracing() 2578232Snate@binkert.org debug.help() 2584053Sbinkertn@umich.edu 2595473Snate@binkert.org if options.list_sim_objects: 2605473Snate@binkert.org import SimObject 2615473Snate@binkert.org done = True 2625473Snate@binkert.org print "SimObjects:" 2635473Snate@binkert.org objects = SimObject.allClasses.keys() 2645473Snate@binkert.org objects.sort() 2655473Snate@binkert.org for name in objects: 2665473Snate@binkert.org obj = SimObject.allClasses[name] 2675473Snate@binkert.org print " %s" % obj 2685473Snate@binkert.org params = obj._params.keys() 2695473Snate@binkert.org params.sort() 2705473Snate@binkert.org for pname in params: 2715473Snate@binkert.org param = obj._params[pname] 2725473Snate@binkert.org default = getattr(param, 'default', '') 2735473Snate@binkert.org print " %s" % pname 2745473Snate@binkert.org if default: 2755473Snate@binkert.org print " default: %s" % default 2765473Snate@binkert.org print " desc: %s" % param.desc 2775473Snate@binkert.org print 2785473Snate@binkert.org print 2795473Snate@binkert.org 2802889Sbinkertn@umich.edu if done: 2812889Sbinkertn@umich.edu sys.exit(0) 2822889Sbinkertn@umich.edu 2835470Snate@binkert.org # setting verbose and quiet at the same time doesn't make sense 2845470Snate@binkert.org if options.verbose > 0 and options.quiet > 0: 2855470Snate@binkert.org options.usage(2) 2865470Snate@binkert.org 2875470Snate@binkert.org verbose = options.verbose - options.quiet 28810134Sstan.czerniawski@arm.com if verbose >= 0: 2898333Snate@binkert.org print "gem5 Simulator System. http://gem5.org" 2902889Sbinkertn@umich.edu print brief_copyright 2912889Sbinkertn@umich.edu print 2925801Snate@binkert.org 2938327Sgblack@eecs.umich.edu print "gem5 compiled %s" % defines.compileDate; 2945456Ssaidi@eecs.umich.edu 2958327Sgblack@eecs.umich.edu print "gem5 started %s" % \ 2968327Sgblack@eecs.umich.edu datetime.datetime.now().strftime("%b %e %Y %X") 29711161Ssteve.reinhardt@amd.com print "gem5 executing on %s, pid %d" % \ 29811161Ssteve.reinhardt@amd.com (socket.gethostname(), os.getpid()) 2995528Sstever@gmail.com 30010758Ssteve.reinhardt@amd.com # in Python 3 pipes.quote() is moved to shlex.quote() 30110758Ssteve.reinhardt@amd.com import pipes 30210758Ssteve.reinhardt@amd.com print "command line:", " ".join(map(pipes.quote, sys.argv)) 3032967Sktlim@umich.edu print 3042889Sbinkertn@umich.edu 3052889Sbinkertn@umich.edu # check to make sure we can find the listed script 3062889Sbinkertn@umich.edu if not arguments or not os.path.isfile(arguments[0]): 3072922Sktlim@umich.edu if arguments and not os.path.isfile(arguments[0]): 3082922Sktlim@umich.edu print "Script %s not found" % arguments[0] 3094053Sbinkertn@umich.edu 3105470Snate@binkert.org options.usage(2) 3112889Sbinkertn@umich.edu 3122889Sbinkertn@umich.edu # tell C++ about output directory 3135801Snate@binkert.org core.setOutputDir(options.outdir) 3142889Sbinkertn@umich.edu 3152889Sbinkertn@umich.edu # update the system path with elements from the -p option 3162889Sbinkertn@umich.edu sys.path[0:0] = options.path 3172889Sbinkertn@umich.edu 3182889Sbinkertn@umich.edu # set stats options 3195801Snate@binkert.org stats.initText(options.stats_file) 3202889Sbinkertn@umich.edu 3212889Sbinkertn@umich.edu # set debugging options 3225801Snate@binkert.org debug.setRemoteGDBPort(options.remote_gdb_port) 3233645Sbinkertn@umich.edu for when in options.debug_break: 3249960Sandreas.hansson@arm.com debug.schedBreak(int(when)) 3252889Sbinkertn@umich.edu 3268232Snate@binkert.org if options.debug_flags: 3275799Snate@binkert.org check_tracing() 3284053Sbinkertn@umich.edu 3295586Snate@binkert.org on_flags = [] 3305586Snate@binkert.org off_flags = [] 3318232Snate@binkert.org for flag in options.debug_flags: 3325586Snate@binkert.org off = False 3335586Snate@binkert.org if flag.startswith('-'): 3345586Snate@binkert.org flag = flag[1:] 3355586Snate@binkert.org off = True 3368232Snate@binkert.org 3378232Snate@binkert.org if flag not in debug.flags: 3388232Snate@binkert.org print >>sys.stderr, "invalid debug flag '%s'" % flag 3395586Snate@binkert.org sys.exit(1) 3404053Sbinkertn@umich.edu 3415586Snate@binkert.org if off: 3428232Snate@binkert.org debug.flags[flag].disable() 3435586Snate@binkert.org else: 3448232Snate@binkert.org debug.flags[flag].enable() 3454053Sbinkertn@umich.edu 3469960Sandreas.hansson@arm.com if options.debug_start: 3475799Snate@binkert.org check_tracing() 3489960Sandreas.hansson@arm.com e = event.create(trace.enable, event.Event.Debug_Enable_Pri) 3499960Sandreas.hansson@arm.com event.mainq.schedule(e, options.debug_start) 3504074Sbinkertn@umich.edu else: 3515799Snate@binkert.org trace.enable() 3524042Sbinkertn@umich.edu 35311338SMichael.Lebeane@amd.com if options.debug_end: 35411338SMichael.Lebeane@amd.com check_tracing() 35511338SMichael.Lebeane@amd.com e = event.create(trace.disable, event.Event.Debug_Enable_Pri) 35611338SMichael.Lebeane@amd.com event.mainq.schedule(e, options.debug_end) 35711338SMichael.Lebeane@amd.com 3589960Sandreas.hansson@arm.com trace.output(options.debug_file) 3594042Sbinkertn@umich.edu 3609960Sandreas.hansson@arm.com for ignore in options.debug_ignore: 3615799Snate@binkert.org check_tracing() 3625799Snate@binkert.org trace.ignore(ignore) 3632889Sbinkertn@umich.edu 3642889Sbinkertn@umich.edu sys.argv = arguments 3652889Sbinkertn@umich.edu sys.path = [ os.path.dirname(sys.argv[0]) ] + sys.path 3662891Sbinkertn@umich.edu 3675604Snate@binkert.org filename = sys.argv[0] 3685604Snate@binkert.org filedata = file(filename, 'r').read() 3695604Snate@binkert.org filecode = compile(filedata, filename, 'exec') 3705604Snate@binkert.org scope = { '__file__' : filename, 3713887Sbinkertn@umich.edu '__name__' : '__m5_main__' } 3722899Sbinkertn@umich.edu 3732899Sbinkertn@umich.edu # we want readline if we're doing anything interactive 3742899Sbinkertn@umich.edu if options.interactive or options.pdb: 3754042Sbinkertn@umich.edu exec "import readline" in scope 3762899Sbinkertn@umich.edu 3772899Sbinkertn@umich.edu # if pdb was requested, execfile the thing under pdb, otherwise, 3782899Sbinkertn@umich.edu # just do the execfile normally 3792899Sbinkertn@umich.edu if options.pdb: 3805604Snate@binkert.org import pdb 3815604Snate@binkert.org import traceback 3825604Snate@binkert.org 3835604Snate@binkert.org pdb = pdb.Pdb() 3845604Snate@binkert.org try: 3855604Snate@binkert.org pdb.run(filecode, scope) 3865604Snate@binkert.org except SystemExit: 3875604Snate@binkert.org print "The program exited via sys.exit(). Exit status: ", 3885604Snate@binkert.org print sys.exc_info()[1] 3895604Snate@binkert.org except: 3905604Snate@binkert.org traceback.print_exc() 3915604Snate@binkert.org print "Uncaught exception. Entering post mortem debugging" 3925604Snate@binkert.org t = sys.exc_info()[2] 3935604Snate@binkert.org while t.tb_next is not None: 3945604Snate@binkert.org t = t.tb_next 3955604Snate@binkert.org pdb.interaction(t.tb_frame,t) 3962899Sbinkertn@umich.edu else: 3975604Snate@binkert.org exec filecode in scope 3982889Sbinkertn@umich.edu 3992889Sbinkertn@umich.edu # once the script is done 4002889Sbinkertn@umich.edu if options.interactive: 4018219Snate@binkert.org interact(scope) 4022889Sbinkertn@umich.edu 4032889Sbinkertn@umich.eduif __name__ == '__main__': 4042889Sbinkertn@umich.edu from pprint import pprint 4052889Sbinkertn@umich.edu 4068234Snate@binkert.org options, arguments = parse_options() 4078234Snate@binkert.org 4082889Sbinkertn@umich.edu print 'opts:' 4092889Sbinkertn@umich.edu pprint(options, indent=4) 4102889Sbinkertn@umich.edu print 4112889Sbinkertn@umich.edu 4122889Sbinkertn@umich.edu print 'args:' 4132889Sbinkertn@umich.edu pprint(arguments, indent=4) 414