main.py revision 12012
111923Sandreas.sandberg@arm.com# Copyright (c) 2016 ARM Limited 211923Sandreas.sandberg@arm.com# All rights reserved. 311923Sandreas.sandberg@arm.com# 411923Sandreas.sandberg@arm.com# The license below extends only to copyright in the software and shall 511923Sandreas.sandberg@arm.com# not be construed as granting a license to any other intellectual 611923Sandreas.sandberg@arm.com# property including but not limited to intellectual property relating 711923Sandreas.sandberg@arm.com# to a hardware implementation of the functionality of the software 811923Sandreas.sandberg@arm.com# licensed hereunder. You may use the software subject to the license 911923Sandreas.sandberg@arm.com# terms below provided that you ensure that this notice is replicated 1011923Sandreas.sandberg@arm.com# unmodified and in its entirety in all distributions of the software, 1111923Sandreas.sandberg@arm.com# modified or unmodified, in source code or in binary form. 1211923Sandreas.sandberg@arm.com# 132889Sbinkertn@umich.edu# Copyright (c) 2005 The Regents of The University of Michigan 142889Sbinkertn@umich.edu# All rights reserved. 152889Sbinkertn@umich.edu# 162889Sbinkertn@umich.edu# Redistribution and use in source and binary forms, with or without 172889Sbinkertn@umich.edu# modification, are permitted provided that the following conditions are 182889Sbinkertn@umich.edu# met: redistributions of source code must retain the above copyright 192889Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer; 202889Sbinkertn@umich.edu# redistributions in binary form must reproduce the above copyright 212889Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer in the 222889Sbinkertn@umich.edu# documentation and/or other materials provided with the distribution; 232889Sbinkertn@umich.edu# neither the name of the copyright holders nor the names of its 242889Sbinkertn@umich.edu# contributors may be used to endorse or promote products derived from 252889Sbinkertn@umich.edu# this software without specific prior written permission. 262889Sbinkertn@umich.edu# 272889Sbinkertn@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 282889Sbinkertn@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 292889Sbinkertn@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 302889Sbinkertn@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 312889Sbinkertn@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 322889Sbinkertn@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 332889Sbinkertn@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 342889Sbinkertn@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 352889Sbinkertn@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 362889Sbinkertn@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 372889Sbinkertn@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 382889Sbinkertn@umich.edu# 392889Sbinkertn@umich.edu# Authors: Nathan Binkert 402889Sbinkertn@umich.edu 414850Snate@binkert.orgimport code 424850Snate@binkert.orgimport datetime 434850Snate@binkert.orgimport os 444850Snate@binkert.orgimport socket 454850Snate@binkert.orgimport sys 464850Snate@binkert.org 472889Sbinkertn@umich.edu__all__ = [ 'options', 'arguments', 'main' ] 482889Sbinkertn@umich.edu 498327Sgblack@eecs.umich.eduusage="%prog [gem5 options] script.py [script options]" 505470Snate@binkert.orgversion="%prog 2.0" 518333Snate@binkert.orgbrief_copyright=\ 528333Snate@binkert.org "gem5 is copyrighted software; use the --copyright option for details." 532889Sbinkertn@umich.edu 548234Snate@binkert.orgdef parse_options(): 558234Snate@binkert.org import config 568234Snate@binkert.org from options import OptionParser 572889Sbinkertn@umich.edu 588234Snate@binkert.org options = OptionParser(usage=usage, version=version, 598234Snate@binkert.org description=brief_copyright) 608234Snate@binkert.org option = options.add_option 618234Snate@binkert.org group = options.set_group 622889Sbinkertn@umich.edu 6311923Sandreas.sandberg@arm.com listener_modes = ( "on", "off", "auto" ) 6411923Sandreas.sandberg@arm.com 658234Snate@binkert.org # Help options 668234Snate@binkert.org option('-B', "--build-info", action="store_true", default=False, 678234Snate@binkert.org help="Show build information") 688234Snate@binkert.org option('-C', "--copyright", action="store_true", default=False, 698234Snate@binkert.org help="Show full copyright information") 708234Snate@binkert.org option('-R', "--readme", action="store_true", default=False, 718234Snate@binkert.org help="Show the readme") 722889Sbinkertn@umich.edu 738234Snate@binkert.org # Options for configuring the base simulator 748234Snate@binkert.org option('-d', "--outdir", metavar="DIR", default="m5out", 758234Snate@binkert.org help="Set the output directory to DIR [Default: %default]") 768234Snate@binkert.org option('-r', "--redirect-stdout", action="store_true", default=False, 778234Snate@binkert.org help="Redirect stdout (& stderr, without -e) to file") 788234Snate@binkert.org option('-e', "--redirect-stderr", action="store_true", default=False, 798234Snate@binkert.org help="Redirect stderr to file") 808234Snate@binkert.org option("--stdout-file", metavar="FILE", default="simout", 818234Snate@binkert.org help="Filename for -r redirection [Default: %default]") 828234Snate@binkert.org option("--stderr-file", metavar="FILE", default="simerr", 838234Snate@binkert.org help="Filename for -e redirection [Default: %default]") 8411923Sandreas.sandberg@arm.com option("--listener-mode", metavar="{on,off,auto}", 8511923Sandreas.sandberg@arm.com choices=listener_modes, default="auto", 8611923Sandreas.sandberg@arm.com help="Port (e.g., gdb) listener mode (auto: Enable if running " \ 8711923Sandreas.sandberg@arm.com "interactively) [Default: %default]") 8812012Sgabeblack@google.com option("--listener-loopback-only", action="store_true", default=False, 8912012Sgabeblack@google.com help="Port listeners will only accept connections over the " \ 9012012Sgabeblack@google.com "loopback device") 918234Snate@binkert.org option('-i', "--interactive", action="store_true", default=False, 928234Snate@binkert.org help="Invoke the interactive interpreter after running the script") 938234Snate@binkert.org option("--pdb", action="store_true", default=False, 948234Snate@binkert.org help="Invoke the python debugger before running the script") 958234Snate@binkert.org option('-p', "--path", metavar="PATH[:PATH]", action='append', split=':', 968234Snate@binkert.org help="Prepend PATH to the system path when invoking the script") 978234Snate@binkert.org option('-q', "--quiet", action="count", default=0, 988234Snate@binkert.org help="Reduce verbosity") 998234Snate@binkert.org option('-v', "--verbose", action="count", default=0, 1008234Snate@binkert.org help="Increase verbosity") 1012889Sbinkertn@umich.edu 1028234Snate@binkert.org # Statistics options 1038234Snate@binkert.org group("Statistics Options") 1048234Snate@binkert.org option("--stats-file", metavar="FILE", default="stats.txt", 1058234Snate@binkert.org help="Sets the output file for statistics [Default: %default]") 1065773Snate@binkert.org 1078234Snate@binkert.org # Configuration Options 1088234Snate@binkert.org group("Configuration Options") 1098234Snate@binkert.org option("--dump-config", metavar="FILE", default="config.ini", 1108234Snate@binkert.org help="Dump configuration output file [Default: %default]") 1118664SAli.Saidi@ARM.com option("--json-config", metavar="FILE", default="config.json", 1128664SAli.Saidi@ARM.com help="Create JSON output of the configuration [Default: %default]") 1138998Suri.wiener@arm.com option("--dot-config", metavar="FILE", default="config.dot", 1148998Suri.wiener@arm.com help="Create DOT & pdf outputs of the configuration [Default: %default]") 11511431Ssascha.bischoff@arm.com option("--dot-dvfs-config", metavar="FILE", default=None, 11611418Ssascha.bischoff@arm.com help="Create DOT & pdf outputs of the DVFS configuration" + \ 11711418Ssascha.bischoff@arm.com " [Default: %default]") 1182889Sbinkertn@umich.edu 1198234Snate@binkert.org # Debugging options 1208234Snate@binkert.org group("Debugging Options") 12111299Ssteve.reinhardt@amd.com option("--debug-break", metavar="TICK[,TICK]", action='append', split=',', 12211299Ssteve.reinhardt@amd.com help="Create breakpoint(s) at TICK(s) " \ 12311299Ssteve.reinhardt@amd.com "(kills process if no debugger attached)") 1248234Snate@binkert.org option("--debug-help", action='store_true', 1259960Sandreas.hansson@arm.com help="Print help on debug flags") 1268234Snate@binkert.org option("--debug-flags", metavar="FLAG[,FLAG]", action='append', split=',', 1279960Sandreas.hansson@arm.com help="Sets the flags for debug output (-FLAG disables a flag)") 12811299Ssteve.reinhardt@amd.com option("--debug-start", metavar="TICK", type='int', 12911304Ssteve.reinhardt@amd.com help="Start debug output at TICK") 13011338SMichael.Lebeane@amd.com option("--debug-end", metavar="TICK", type='int', 13111338SMichael.Lebeane@amd.com help="End debug output at TICK") 1329960Sandreas.hansson@arm.com option("--debug-file", metavar="FILE", default="cout", 1339960Sandreas.hansson@arm.com help="Sets the output file for debug [Default: %default]") 1349960Sandreas.hansson@arm.com option("--debug-ignore", metavar="EXPR", action='append', split=':', 1359960Sandreas.hansson@arm.com help="Ignore EXPR sim objects") 1368234Snate@binkert.org option("--remote-gdb-port", type='int', default=7000, 1378234Snate@binkert.org help="Remote gdb base port (set to 0 to disable listening)") 1382889Sbinkertn@umich.edu 1398234Snate@binkert.org # Help options 1408234Snate@binkert.org group("Help Options") 1418234Snate@binkert.org option("--list-sim-objects", action='store_true', default=False, 1428234Snate@binkert.org help="List all built-in SimObjects, their params and default values") 1436171Snate@binkert.org 1448234Snate@binkert.org # load the options.py config file to allow people to set their own 1458234Snate@binkert.org # default options 1468234Snate@binkert.org options_file = config.get('options.py') 1478234Snate@binkert.org if options_file: 1488234Snate@binkert.org scope = { 'options' : options } 1498234Snate@binkert.org execfile(options_file, scope) 1508234Snate@binkert.org 1518234Snate@binkert.org arguments = options.parse_args() 1528234Snate@binkert.org return options,arguments 1536171Snate@binkert.org 1548219Snate@binkert.orgdef interact(scope): 1558327Sgblack@eecs.umich.edu banner = "gem5 Interactive Console" 1569512Sandreas@sandberg.pp.se 1579512Sandreas@sandberg.pp.se ipshell = None 1589512Sandreas@sandberg.pp.se prompt_in1 = "gem5 \\#> " 1599512Sandreas@sandberg.pp.se prompt_out = "gem5 \\#: " 1609512Sandreas@sandberg.pp.se 1619512Sandreas@sandberg.pp.se # Is IPython version 0.10 or earlier available? 1628219Snate@binkert.org try: 1638219Snate@binkert.org from IPython.Shell import IPShellEmbed 1649512Sandreas@sandberg.pp.se ipshell = IPShellEmbed(argv=["-prompt_in1", prompt_in1, 1659512Sandreas@sandberg.pp.se "-prompt_out", prompt_out], 1669512Sandreas@sandberg.pp.se banner=banner, user_ns=scope) 1679512Sandreas@sandberg.pp.se except ImportError: 1689512Sandreas@sandberg.pp.se pass 1699512Sandreas@sandberg.pp.se 1709512Sandreas@sandberg.pp.se # Is IPython version 0.11 or later available? 1719512Sandreas@sandberg.pp.se if not ipshell: 1729512Sandreas@sandberg.pp.se try: 1739512Sandreas@sandberg.pp.se import IPython 1749512Sandreas@sandberg.pp.se from IPython.config.loader import Config 17511635SCurtis.Dunham@arm.com from IPython.terminal.embed import InteractiveShellEmbed 1769512Sandreas@sandberg.pp.se 1779512Sandreas@sandberg.pp.se cfg = Config() 1789512Sandreas@sandberg.pp.se cfg.PromptManager.in_template = prompt_in1 1799512Sandreas@sandberg.pp.se cfg.PromptManager.out_template = prompt_out 1809512Sandreas@sandberg.pp.se ipshell = InteractiveShellEmbed(config=cfg, user_ns=scope, 1819512Sandreas@sandberg.pp.se banner1=banner) 1829512Sandreas@sandberg.pp.se except ImportError: 1839512Sandreas@sandberg.pp.se pass 1849512Sandreas@sandberg.pp.se 1859512Sandreas@sandberg.pp.se if ipshell: 1868219Snate@binkert.org ipshell() 1879512Sandreas@sandberg.pp.se else: 1889512Sandreas@sandberg.pp.se # Use the Python shell in the standard library if IPython 1899512Sandreas@sandberg.pp.se # isn't available. 1908219Snate@binkert.org code.InteractiveConsole(scope).interact(banner) 1918219Snate@binkert.org 1928234Snate@binkert.orgdef main(*args): 1938245Snate@binkert.org import m5 1948245Snate@binkert.org 1955801Snate@binkert.org import core 1965801Snate@binkert.org import debug 1975801Snate@binkert.org import defines 1984167Sbinkertn@umich.edu import event 1994042Sbinkertn@umich.edu import info 2005801Snate@binkert.org import stats 2015799Snate@binkert.org import trace 2025799Snate@binkert.org 20311923Sandreas.sandberg@arm.com from util import inform, fatal, panic, isInteractive 2048234Snate@binkert.org 2058234Snate@binkert.org if len(args) == 0: 2068234Snate@binkert.org options, arguments = parse_options() 2078234Snate@binkert.org elif len(args) == 2: 2088234Snate@binkert.org options, arguments = args 2098234Snate@binkert.org else: 2108234Snate@binkert.org raise TypeError, "main() takes 0 or 2 arguments (%d given)" % len(args) 2118234Snate@binkert.org 2128245Snate@binkert.org m5.options = options 2138245Snate@binkert.org 2145799Snate@binkert.org def check_tracing(): 2155799Snate@binkert.org if defines.TRACING_ON: 2165799Snate@binkert.org return 2175799Snate@binkert.org 2185802Snate@binkert.org fatal("Tracing is not enabled. Compile with TRACING_ON") 2192889Sbinkertn@umich.edu 2209983Sstever@gmail.com # Set the main event queue for the main thread. 2219983Sstever@gmail.com event.mainq = event.getEventQueue(0) 2229983Sstever@gmail.com event.setEventQueue(event.mainq) 2239983Sstever@gmail.com 2245524Sstever@gmail.com if not os.path.isdir(options.outdir): 2255524Sstever@gmail.com os.makedirs(options.outdir) 2265524Sstever@gmail.com 2275524Sstever@gmail.com # These filenames are used only if the redirect_std* options are set 2285524Sstever@gmail.com stdout_file = os.path.join(options.outdir, options.stdout_file) 2295524Sstever@gmail.com stderr_file = os.path.join(options.outdir, options.stderr_file) 2305524Sstever@gmail.com 2315524Sstever@gmail.com # Print redirection notices here before doing any redirection 2325524Sstever@gmail.com if options.redirect_stdout and not options.redirect_stderr: 2335524Sstever@gmail.com print "Redirecting stdout and stderr to", stdout_file 2345524Sstever@gmail.com else: 2355524Sstever@gmail.com if options.redirect_stdout: 2365524Sstever@gmail.com print "Redirecting stdout to", stdout_file 2375524Sstever@gmail.com if options.redirect_stderr: 2385524Sstever@gmail.com print "Redirecting stderr to", stderr_file 2395524Sstever@gmail.com 2405524Sstever@gmail.com # Now redirect stdout/stderr as desired 2415524Sstever@gmail.com if options.redirect_stdout: 2425524Sstever@gmail.com redir_fd = os.open(stdout_file, os. O_WRONLY | os.O_CREAT | os.O_TRUNC) 2435524Sstever@gmail.com os.dup2(redir_fd, sys.stdout.fileno()) 2445524Sstever@gmail.com if not options.redirect_stderr: 2455524Sstever@gmail.com os.dup2(redir_fd, sys.stderr.fileno()) 2465524Sstever@gmail.com 2475524Sstever@gmail.com if options.redirect_stderr: 2485524Sstever@gmail.com redir_fd = os.open(stderr_file, os. O_WRONLY | os.O_CREAT | os.O_TRUNC) 2495524Sstever@gmail.com os.dup2(redir_fd, sys.stderr.fileno()) 2505524Sstever@gmail.com 2512889Sbinkertn@umich.edu done = False 2524850Snate@binkert.org 2534850Snate@binkert.org if options.build_info: 2544850Snate@binkert.org done = True 2554850Snate@binkert.org print 'Build information:' 2564850Snate@binkert.org print 2575801Snate@binkert.org print 'compiled %s' % defines.compileDate; 2584850Snate@binkert.org print 'build options:' 2595801Snate@binkert.org keys = defines.buildEnv.keys() 2604850Snate@binkert.org keys.sort() 2614850Snate@binkert.org for key in keys: 2625801Snate@binkert.org val = defines.buildEnv[key] 2634850Snate@binkert.org print ' %s = %s' % (key, val) 2644850Snate@binkert.org print 2654850Snate@binkert.org 2662889Sbinkertn@umich.edu if options.copyright: 2672889Sbinkertn@umich.edu done = True 2688333Snate@binkert.org print info.COPYING 2692889Sbinkertn@umich.edu print 2702889Sbinkertn@umich.edu 2712889Sbinkertn@umich.edu if options.readme: 2722889Sbinkertn@umich.edu done = True 2732889Sbinkertn@umich.edu print 'Readme:' 2742889Sbinkertn@umich.edu print 2752889Sbinkertn@umich.edu print info.README 2762889Sbinkertn@umich.edu print 2772889Sbinkertn@umich.edu 2788232Snate@binkert.org if options.debug_help: 2794053Sbinkertn@umich.edu done = True 2805799Snate@binkert.org check_tracing() 2818232Snate@binkert.org debug.help() 2824053Sbinkertn@umich.edu 2835473Snate@binkert.org if options.list_sim_objects: 2845473Snate@binkert.org import SimObject 2855473Snate@binkert.org done = True 2865473Snate@binkert.org print "SimObjects:" 2875473Snate@binkert.org objects = SimObject.allClasses.keys() 2885473Snate@binkert.org objects.sort() 2895473Snate@binkert.org for name in objects: 2905473Snate@binkert.org obj = SimObject.allClasses[name] 2915473Snate@binkert.org print " %s" % obj 2925473Snate@binkert.org params = obj._params.keys() 2935473Snate@binkert.org params.sort() 2945473Snate@binkert.org for pname in params: 2955473Snate@binkert.org param = obj._params[pname] 2965473Snate@binkert.org default = getattr(param, 'default', '') 2975473Snate@binkert.org print " %s" % pname 2985473Snate@binkert.org if default: 2995473Snate@binkert.org print " default: %s" % default 3005473Snate@binkert.org print " desc: %s" % param.desc 3015473Snate@binkert.org print 3025473Snate@binkert.org print 3035473Snate@binkert.org 3042889Sbinkertn@umich.edu if done: 3052889Sbinkertn@umich.edu sys.exit(0) 3062889Sbinkertn@umich.edu 3075470Snate@binkert.org # setting verbose and quiet at the same time doesn't make sense 3085470Snate@binkert.org if options.verbose > 0 and options.quiet > 0: 3095470Snate@binkert.org options.usage(2) 3105470Snate@binkert.org 3115470Snate@binkert.org verbose = options.verbose - options.quiet 31210134Sstan.czerniawski@arm.com if verbose >= 0: 3138333Snate@binkert.org print "gem5 Simulator System. http://gem5.org" 3142889Sbinkertn@umich.edu print brief_copyright 3152889Sbinkertn@umich.edu print 3165801Snate@binkert.org 3178327Sgblack@eecs.umich.edu print "gem5 compiled %s" % defines.compileDate; 3185456Ssaidi@eecs.umich.edu 3198327Sgblack@eecs.umich.edu print "gem5 started %s" % \ 3208327Sgblack@eecs.umich.edu datetime.datetime.now().strftime("%b %e %Y %X") 32111161Ssteve.reinhardt@amd.com print "gem5 executing on %s, pid %d" % \ 32211161Ssteve.reinhardt@amd.com (socket.gethostname(), os.getpid()) 3235528Sstever@gmail.com 32410758Ssteve.reinhardt@amd.com # in Python 3 pipes.quote() is moved to shlex.quote() 32510758Ssteve.reinhardt@amd.com import pipes 32610758Ssteve.reinhardt@amd.com print "command line:", " ".join(map(pipes.quote, sys.argv)) 3272967Sktlim@umich.edu print 3282889Sbinkertn@umich.edu 3292889Sbinkertn@umich.edu # check to make sure we can find the listed script 3302889Sbinkertn@umich.edu if not arguments or not os.path.isfile(arguments[0]): 3312922Sktlim@umich.edu if arguments and not os.path.isfile(arguments[0]): 3322922Sktlim@umich.edu print "Script %s not found" % arguments[0] 3334053Sbinkertn@umich.edu 3345470Snate@binkert.org options.usage(2) 3352889Sbinkertn@umich.edu 3362889Sbinkertn@umich.edu # tell C++ about output directory 3375801Snate@binkert.org core.setOutputDir(options.outdir) 3382889Sbinkertn@umich.edu 3392889Sbinkertn@umich.edu # update the system path with elements from the -p option 3402889Sbinkertn@umich.edu sys.path[0:0] = options.path 3412889Sbinkertn@umich.edu 3422889Sbinkertn@umich.edu # set stats options 34311878Sandreas.sandberg@arm.com stats.addStatVisitor(options.stats_file) 3442889Sbinkertn@umich.edu 34511923Sandreas.sandberg@arm.com # Disable listeners unless running interactively or explicitly 34611923Sandreas.sandberg@arm.com # enabled 34711923Sandreas.sandberg@arm.com if options.listener_mode == "off": 34811923Sandreas.sandberg@arm.com m5.disableAllListeners() 34911923Sandreas.sandberg@arm.com elif options.listener_mode == "auto": 35011923Sandreas.sandberg@arm.com if not isInteractive(): 35111923Sandreas.sandberg@arm.com inform("Standard input is not a terminal, disabling listeners.") 35211923Sandreas.sandberg@arm.com m5.disableAllListeners() 35311923Sandreas.sandberg@arm.com elif options.listener_mode == "on": 35411923Sandreas.sandberg@arm.com pass 35511923Sandreas.sandberg@arm.com else: 35611923Sandreas.sandberg@arm.com panic("Unhandled listener mode: %s" % options.listener_mode) 35711923Sandreas.sandberg@arm.com 35812012Sgabeblack@google.com if options.listener_loopback_only: 35912012Sgabeblack@google.com m5.listenersLoopbackOnly() 36012012Sgabeblack@google.com 3612889Sbinkertn@umich.edu # set debugging options 3625801Snate@binkert.org debug.setRemoteGDBPort(options.remote_gdb_port) 3633645Sbinkertn@umich.edu for when in options.debug_break: 3649960Sandreas.hansson@arm.com debug.schedBreak(int(when)) 3652889Sbinkertn@umich.edu 3668232Snate@binkert.org if options.debug_flags: 3675799Snate@binkert.org check_tracing() 3684053Sbinkertn@umich.edu 3695586Snate@binkert.org on_flags = [] 3705586Snate@binkert.org off_flags = [] 3718232Snate@binkert.org for flag in options.debug_flags: 3725586Snate@binkert.org off = False 3735586Snate@binkert.org if flag.startswith('-'): 3745586Snate@binkert.org flag = flag[1:] 3755586Snate@binkert.org off = True 3768232Snate@binkert.org 3778232Snate@binkert.org if flag not in debug.flags: 3788232Snate@binkert.org print >>sys.stderr, "invalid debug flag '%s'" % flag 3795586Snate@binkert.org sys.exit(1) 3804053Sbinkertn@umich.edu 3815586Snate@binkert.org if off: 3828232Snate@binkert.org debug.flags[flag].disable() 3835586Snate@binkert.org else: 3848232Snate@binkert.org debug.flags[flag].enable() 3854053Sbinkertn@umich.edu 3869960Sandreas.hansson@arm.com if options.debug_start: 3875799Snate@binkert.org check_tracing() 3889960Sandreas.hansson@arm.com e = event.create(trace.enable, event.Event.Debug_Enable_Pri) 3899960Sandreas.hansson@arm.com event.mainq.schedule(e, options.debug_start) 3904074Sbinkertn@umich.edu else: 3915799Snate@binkert.org trace.enable() 3924042Sbinkertn@umich.edu 39311338SMichael.Lebeane@amd.com if options.debug_end: 39411338SMichael.Lebeane@amd.com check_tracing() 39511338SMichael.Lebeane@amd.com e = event.create(trace.disable, event.Event.Debug_Enable_Pri) 39611338SMichael.Lebeane@amd.com event.mainq.schedule(e, options.debug_end) 39711338SMichael.Lebeane@amd.com 3989960Sandreas.hansson@arm.com trace.output(options.debug_file) 3994042Sbinkertn@umich.edu 4009960Sandreas.hansson@arm.com for ignore in options.debug_ignore: 4015799Snate@binkert.org check_tracing() 4025799Snate@binkert.org trace.ignore(ignore) 4032889Sbinkertn@umich.edu 4042889Sbinkertn@umich.edu sys.argv = arguments 4052889Sbinkertn@umich.edu sys.path = [ os.path.dirname(sys.argv[0]) ] + sys.path 4062891Sbinkertn@umich.edu 4075604Snate@binkert.org filename = sys.argv[0] 4085604Snate@binkert.org filedata = file(filename, 'r').read() 4095604Snate@binkert.org filecode = compile(filedata, filename, 'exec') 4105604Snate@binkert.org scope = { '__file__' : filename, 4113887Sbinkertn@umich.edu '__name__' : '__m5_main__' } 4122899Sbinkertn@umich.edu 4132899Sbinkertn@umich.edu # we want readline if we're doing anything interactive 4142899Sbinkertn@umich.edu if options.interactive or options.pdb: 4154042Sbinkertn@umich.edu exec "import readline" in scope 4162899Sbinkertn@umich.edu 4172899Sbinkertn@umich.edu # if pdb was requested, execfile the thing under pdb, otherwise, 4182899Sbinkertn@umich.edu # just do the execfile normally 4192899Sbinkertn@umich.edu if options.pdb: 4205604Snate@binkert.org import pdb 4215604Snate@binkert.org import traceback 4225604Snate@binkert.org 4235604Snate@binkert.org pdb = pdb.Pdb() 4245604Snate@binkert.org try: 4255604Snate@binkert.org pdb.run(filecode, scope) 4265604Snate@binkert.org except SystemExit: 4275604Snate@binkert.org print "The program exited via sys.exit(). Exit status: ", 4285604Snate@binkert.org print sys.exc_info()[1] 4295604Snate@binkert.org except: 4305604Snate@binkert.org traceback.print_exc() 4315604Snate@binkert.org print "Uncaught exception. Entering post mortem debugging" 4325604Snate@binkert.org t = sys.exc_info()[2] 4335604Snate@binkert.org while t.tb_next is not None: 4345604Snate@binkert.org t = t.tb_next 4355604Snate@binkert.org pdb.interaction(t.tb_frame,t) 4362899Sbinkertn@umich.edu else: 4375604Snate@binkert.org exec filecode in scope 4382889Sbinkertn@umich.edu 4392889Sbinkertn@umich.edu # once the script is done 4402889Sbinkertn@umich.edu if options.interactive: 4418219Snate@binkert.org interact(scope) 4422889Sbinkertn@umich.edu 4432889Sbinkertn@umich.eduif __name__ == '__main__': 4442889Sbinkertn@umich.edu from pprint import pprint 4452889Sbinkertn@umich.edu 4468234Snate@binkert.org options, arguments = parse_options() 4478234Snate@binkert.org 4482889Sbinkertn@umich.edu print 'opts:' 4492889Sbinkertn@umich.edu pprint(options, indent=4) 4502889Sbinkertn@umich.edu print 4512889Sbinkertn@umich.edu 4522889Sbinkertn@umich.edu print 'args:' 4532889Sbinkertn@umich.edu pprint(arguments, indent=4) 454