main.py revision 13670
15124Sgblack@eecs.umich.edu# Copyright (c) 2016 ARM Limited 27087Snate@binkert.org# All rights reserved. 37087Snate@binkert.org# 47087Snate@binkert.org# The license below extends only to copyright in the software and shall 57087Snate@binkert.org# not be construed as granting a license to any other intellectual 67087Snate@binkert.org# property including but not limited to intellectual property relating 77087Snate@binkert.org# to a hardware implementation of the functionality of the software 87087Snate@binkert.org# licensed hereunder. You may use the software subject to the license 97087Snate@binkert.org# terms below provided that you ensure that this notice is replicated 107087Snate@binkert.org# unmodified and in its entirety in all distributions of the software, 117087Snate@binkert.org# modified or unmodified, in source code or in binary form. 127087Snate@binkert.org# 137087Snate@binkert.org# Copyright (c) 2005 The Regents of The University of Michigan 145124Sgblack@eecs.umich.edu# All rights reserved. 155124Sgblack@eecs.umich.edu# 165124Sgblack@eecs.umich.edu# Redistribution and use in source and binary forms, with or without 175124Sgblack@eecs.umich.edu# modification, are permitted provided that the following conditions are 185124Sgblack@eecs.umich.edu# met: redistributions of source code must retain the above copyright 195124Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer; 205124Sgblack@eecs.umich.edu# redistributions in binary form must reproduce the above copyright 215124Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the 225124Sgblack@eecs.umich.edu# documentation and/or other materials provided with the distribution; 235124Sgblack@eecs.umich.edu# neither the name of the copyright holders nor the names of its 245124Sgblack@eecs.umich.edu# contributors may be used to endorse or promote products derived from 255124Sgblack@eecs.umich.edu# this software without specific prior written permission. 265124Sgblack@eecs.umich.edu# 275124Sgblack@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 285124Sgblack@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 295124Sgblack@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 305124Sgblack@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 315124Sgblack@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 325124Sgblack@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 335124Sgblack@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 345124Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 355124Sgblack@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 365124Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 375124Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 385124Sgblack@eecs.umich.edu# 395124Sgblack@eecs.umich.edu# Authors: Nathan Binkert 405124Sgblack@eecs.umich.edu 415124Sgblack@eecs.umich.edufrom __future__ import print_function 425124Sgblack@eecs.umich.edu 438961Sgblack@eecs.umich.eduimport code 445124Sgblack@eecs.umich.eduimport datetime 458740Sgblack@eecs.umich.eduimport os 465124Sgblack@eecs.umich.eduimport socket 475124Sgblack@eecs.umich.eduimport sys 488232Snate@binkert.org 498740Sgblack@eecs.umich.edu__all__ = [ 'options', 'arguments', 'main' ] 505124Sgblack@eecs.umich.edu 515124Sgblack@eecs.umich.eduusage="%prog [gem5 options] script.py [script options]" 525124Sgblack@eecs.umich.eduversion="%prog 2.0" 537678Sgblack@eecs.umich.edubrief_copyright=\ 545124Sgblack@eecs.umich.edu "gem5 is copyrighted software; use the --copyright option for details." 558806Sgblack@eecs.umich.edu 568806Sgblack@eecs.umich.edudef parse_options(): 578806Sgblack@eecs.umich.edu import config 588806Sgblack@eecs.umich.edu from options import OptionParser 598806Sgblack@eecs.umich.edu 608806Sgblack@eecs.umich.edu options = OptionParser(usage=usage, version=version, 618806Sgblack@eecs.umich.edu description=brief_copyright) 628806Sgblack@eecs.umich.edu option = options.add_option 638806Sgblack@eecs.umich.edu group = options.set_group 648806Sgblack@eecs.umich.edu 658806Sgblack@eecs.umich.edu listener_modes = ( "on", "off", "auto" ) 668806Sgblack@eecs.umich.edu 678806Sgblack@eecs.umich.edu # Help options 688806Sgblack@eecs.umich.edu option('-B', "--build-info", action="store_true", default=False, 698806Sgblack@eecs.umich.edu help="Show build information") 708806Sgblack@eecs.umich.edu option('-C', "--copyright", action="store_true", default=False, 718806Sgblack@eecs.umich.edu help="Show full copyright information") 728806Sgblack@eecs.umich.edu option('-R', "--readme", action="store_true", default=False, 738806Sgblack@eecs.umich.edu help="Show the readme") 748806Sgblack@eecs.umich.edu 758806Sgblack@eecs.umich.edu # Options for configuring the base simulator 768806Sgblack@eecs.umich.edu option('-d', "--outdir", metavar="DIR", default="m5out", 778806Sgblack@eecs.umich.edu help="Set the output directory to DIR [Default: %default]") 788806Sgblack@eecs.umich.edu option('-r', "--redirect-stdout", action="store_true", default=False, 798740Sgblack@eecs.umich.edu help="Redirect stdout (& stderr, without -e) to file") 808806Sgblack@eecs.umich.edu option('-e', "--redirect-stderr", action="store_true", default=False, 815858Sgblack@eecs.umich.edu help="Redirect stderr to file") 828806Sgblack@eecs.umich.edu option("--stdout-file", metavar="FILE", default="simout", 838806Sgblack@eecs.umich.edu help="Filename for -r redirection [Default: %default]") 845858Sgblack@eecs.umich.edu option("--stderr-file", metavar="FILE", default="simerr", 858806Sgblack@eecs.umich.edu help="Filename for -e redirection [Default: %default]") 868806Sgblack@eecs.umich.edu option("--listener-mode", metavar="{on,off,auto}", 878806Sgblack@eecs.umich.edu choices=listener_modes, default="auto", 888806Sgblack@eecs.umich.edu help="Port (e.g., gdb) listener mode (auto: Enable if running " \ 895681Sgblack@eecs.umich.edu "interactively) [Default: %default]") 908806Sgblack@eecs.umich.edu option("--listener-loopback-only", action="store_true", default=False, 918806Sgblack@eecs.umich.edu help="Port listeners will only accept connections over the " \ 928806Sgblack@eecs.umich.edu "loopback device") 935124Sgblack@eecs.umich.edu option('-i', "--interactive", action="store_true", default=False, 945909Sgblack@eecs.umich.edu help="Invoke the interactive interpreter after running the script") 955909Sgblack@eecs.umich.edu option("--pdb", action="store_true", default=False, 965909Sgblack@eecs.umich.edu help="Invoke the python debugger before running the script") 975909Sgblack@eecs.umich.edu option('-p', "--path", metavar="PATH[:PATH]", action='append', split=':', 985909Sgblack@eecs.umich.edu help="Prepend PATH to the system path when invoking the script") 995909Sgblack@eecs.umich.edu option('-q', "--quiet", action="count", default=0, 1005909Sgblack@eecs.umich.edu help="Reduce verbosity") 1015909Sgblack@eecs.umich.edu option('-v', "--verbose", action="count", default=0, 1025909Sgblack@eecs.umich.edu help="Increase verbosity") 1035909Sgblack@eecs.umich.edu 1045909Sgblack@eecs.umich.edu # Statistics options 1055909Sgblack@eecs.umich.edu group("Statistics Options") 1065858Sgblack@eecs.umich.edu option("--stats-file", metavar="FILE", default="stats.txt", 1077678Sgblack@eecs.umich.edu help="Sets the output file for statistics [Default: %default]") 1085858Sgblack@eecs.umich.edu 1095858Sgblack@eecs.umich.edu # Configuration Options 1108806Sgblack@eecs.umich.edu group("Configuration Options") 1118806Sgblack@eecs.umich.edu option("--dump-config", metavar="FILE", default="config.ini", 1128806Sgblack@eecs.umich.edu help="Dump configuration output file [Default: %default]") 1138806Sgblack@eecs.umich.edu option("--json-config", metavar="FILE", default="config.json", 1148806Sgblack@eecs.umich.edu help="Create JSON output of the configuration [Default: %default]") 1158806Sgblack@eecs.umich.edu option("--dot-config", metavar="FILE", default="config.dot", 1168806Sgblack@eecs.umich.edu help="Create DOT & pdf outputs of the configuration [Default: %default]") 1175858Sgblack@eecs.umich.edu option("--dot-dvfs-config", metavar="FILE", default=None, 1185858Sgblack@eecs.umich.edu help="Create DOT & pdf outputs of the DVFS configuration" + \ 1197678Sgblack@eecs.umich.edu " [Default: %default]") 1205858Sgblack@eecs.umich.edu 1215858Sgblack@eecs.umich.edu # Debugging options 1225858Sgblack@eecs.umich.edu group("Debugging Options") 1235858Sgblack@eecs.umich.edu option("--debug-break", metavar="TICK[,TICK]", action='append', split=',', 1248740Sgblack@eecs.umich.edu help="Create breakpoint(s) at TICK(s) " \ 1258740Sgblack@eecs.umich.edu "(kills process if no debugger attached)") 1268740Sgblack@eecs.umich.edu option("--debug-help", action='store_true', 1278740Sgblack@eecs.umich.edu help="Print help on debug flags") 1288740Sgblack@eecs.umich.edu option("--debug-flags", metavar="FLAG[,FLAG]", action='append', split=',', 1298740Sgblack@eecs.umich.edu help="Sets the flags for debug output (-FLAG disables a flag)") 1308740Sgblack@eecs.umich.edu option("--debug-start", metavar="TICK", type='int', 1318740Sgblack@eecs.umich.edu help="Start debug output at TICK") 1328740Sgblack@eecs.umich.edu option("--debug-end", metavar="TICK", type='int', 1338740Sgblack@eecs.umich.edu help="End debug output at TICK") 1348740Sgblack@eecs.umich.edu option("--debug-file", metavar="FILE", default="cout", 1357678Sgblack@eecs.umich.edu help="Sets the output file for debug [Default: %default]") 1365858Sgblack@eecs.umich.edu option("--debug-ignore", metavar="EXPR", action='append', split=':', 1378740Sgblack@eecs.umich.edu help="Ignore EXPR sim objects") 1388740Sgblack@eecs.umich.edu option("--remote-gdb-port", type='int', default=7000, 1398740Sgblack@eecs.umich.edu help="Remote gdb base port (set to 0 to disable listening)") 1408740Sgblack@eecs.umich.edu 1418740Sgblack@eecs.umich.edu # Help options 1428740Sgblack@eecs.umich.edu group("Help Options") 1438740Sgblack@eecs.umich.edu option("--list-sim-objects", action='store_true', default=False, 1448740Sgblack@eecs.umich.edu help="List all built-in SimObjects, their params and default values") 1458740Sgblack@eecs.umich.edu 1468740Sgblack@eecs.umich.edu # load the options.py config file to allow people to set their own 1478740Sgblack@eecs.umich.edu # default options 1488740Sgblack@eecs.umich.edu options_file = config.get('options.py') 1498740Sgblack@eecs.umich.edu if options_file: 1508740Sgblack@eecs.umich.edu scope = { 'options' : options } 1515858Sgblack@eecs.umich.edu execfile(options_file, scope) 1528740Sgblack@eecs.umich.edu 1538740Sgblack@eecs.umich.edu arguments = options.parse_args() 1548740Sgblack@eecs.umich.edu return options,arguments 1558740Sgblack@eecs.umich.edu 1568740Sgblack@eecs.umich.edudef interact(scope): 1578740Sgblack@eecs.umich.edu banner = "gem5 Interactive Console" 1588740Sgblack@eecs.umich.edu 1598740Sgblack@eecs.umich.edu ipshell = None 1608740Sgblack@eecs.umich.edu prompt_in1 = "gem5 \\#> " 1615858Sgblack@eecs.umich.edu prompt_out = "gem5 \\#: " 1625858Sgblack@eecs.umich.edu 1635237Sgblack@eecs.umich.edu # Is IPython version 0.10 or earlier available? 1645909Sgblack@eecs.umich.edu try: 1655909Sgblack@eecs.umich.edu from IPython.Shell import IPShellEmbed 1665909Sgblack@eecs.umich.edu ipshell = IPShellEmbed(argv=["-prompt_in1", prompt_in1, 1675909Sgblack@eecs.umich.edu "-prompt_out", prompt_out], 1685909Sgblack@eecs.umich.edu banner=banner, user_ns=scope) 1695909Sgblack@eecs.umich.edu except ImportError: 1705909Sgblack@eecs.umich.edu pass 1715909Sgblack@eecs.umich.edu 1726048Sgblack@eecs.umich.edu # Is IPython version 0.11 or later available? 1737678Sgblack@eecs.umich.edu if not ipshell: 1746048Sgblack@eecs.umich.edu try: 1756048Sgblack@eecs.umich.edu import IPython 1766048Sgblack@eecs.umich.edu from IPython.config.loader import Config 1776048Sgblack@eecs.umich.edu from IPython.terminal.embed import InteractiveShellEmbed 1786048Sgblack@eecs.umich.edu 1796048Sgblack@eecs.umich.edu cfg = Config() 1806048Sgblack@eecs.umich.edu cfg.PromptManager.in_template = prompt_in1 1816048Sgblack@eecs.umich.edu cfg.PromptManager.out_template = prompt_out 1826048Sgblack@eecs.umich.edu ipshell = InteractiveShellEmbed(config=cfg, user_ns=scope, 1836048Sgblack@eecs.umich.edu banner1=banner) 1846048Sgblack@eecs.umich.edu except ImportError: 1856048Sgblack@eecs.umich.edu pass 1866048Sgblack@eecs.umich.edu 1876048Sgblack@eecs.umich.edu if ipshell: 1886048Sgblack@eecs.umich.edu ipshell() 1896048Sgblack@eecs.umich.edu else: 1906048Sgblack@eecs.umich.edu # Use the Python shell in the standard library if IPython 1916048Sgblack@eecs.umich.edu # isn't available. 1926048Sgblack@eecs.umich.edu code.InteractiveConsole(scope).interact(banner) 1936048Sgblack@eecs.umich.edu 1946048Sgblack@eecs.umich.edudef main(*args): 1956222Sgblack@eecs.umich.edu import m5 1966222Sgblack@eecs.umich.edu 1976222Sgblack@eecs.umich.edu import core 1986222Sgblack@eecs.umich.edu import debug 1996222Sgblack@eecs.umich.edu import defines 2006222Sgblack@eecs.umich.edu import event 2016222Sgblack@eecs.umich.edu import info 2026222Sgblack@eecs.umich.edu import stats 2036048Sgblack@eecs.umich.edu import trace 2046048Sgblack@eecs.umich.edu 2056048Sgblack@eecs.umich.edu from util import inform, fatal, panic, isInteractive 2066222Sgblack@eecs.umich.edu 2076048Sgblack@eecs.umich.edu if len(args) == 0: 2086048Sgblack@eecs.umich.edu options, arguments = parse_options() 2096048Sgblack@eecs.umich.edu elif len(args) == 2: 2106048Sgblack@eecs.umich.edu options, arguments = args 2116048Sgblack@eecs.umich.edu else: 2126048Sgblack@eecs.umich.edu raise TypeError("main() takes 0 or 2 arguments (%d given)" % len(args)) 2136048Sgblack@eecs.umich.edu 2146048Sgblack@eecs.umich.edu m5.options = options 2156048Sgblack@eecs.umich.edu 2166048Sgblack@eecs.umich.edu def check_tracing(): 2176222Sgblack@eecs.umich.edu if defines.TRACING_ON: 2186222Sgblack@eecs.umich.edu return 2196222Sgblack@eecs.umich.edu 2206222Sgblack@eecs.umich.edu fatal("Tracing is not enabled. Compile with TRACING_ON") 2216222Sgblack@eecs.umich.edu 2226222Sgblack@eecs.umich.edu # Set the main event queue for the main thread. 2236222Sgblack@eecs.umich.edu event.mainq = event.getEventQueue(0) 2246222Sgblack@eecs.umich.edu event.setEventQueue(event.mainq) 2256048Sgblack@eecs.umich.edu 2266048Sgblack@eecs.umich.edu if not os.path.isdir(options.outdir): 2276048Sgblack@eecs.umich.edu os.makedirs(options.outdir) 2286222Sgblack@eecs.umich.edu 2296048Sgblack@eecs.umich.edu # These filenames are used only if the redirect_std* options are set 2306048Sgblack@eecs.umich.edu stdout_file = os.path.join(options.outdir, options.stdout_file) 2316048Sgblack@eecs.umich.edu stderr_file = os.path.join(options.outdir, options.stderr_file) 2326048Sgblack@eecs.umich.edu 2336048Sgblack@eecs.umich.edu # Print redirection notices here before doing any redirection 2346048Sgblack@eecs.umich.edu if options.redirect_stdout and not options.redirect_stderr: 2356048Sgblack@eecs.umich.edu print("Redirecting stdout and stderr to", stdout_file) 2366048Sgblack@eecs.umich.edu else: 2376048Sgblack@eecs.umich.edu if options.redirect_stdout: 2386048Sgblack@eecs.umich.edu print("Redirecting stdout to", stdout_file) 2397720Sgblack@eecs.umich.edu if options.redirect_stderr: 2407720Sgblack@eecs.umich.edu print("Redirecting stderr to", stderr_file) 2416048Sgblack@eecs.umich.edu 2426048Sgblack@eecs.umich.edu # Now redirect stdout/stderr as desired 2436048Sgblack@eecs.umich.edu if options.redirect_stdout: 2446048Sgblack@eecs.umich.edu redir_fd = os.open(stdout_file, os. O_WRONLY | os.O_CREAT | os.O_TRUNC) 2456048Sgblack@eecs.umich.edu os.dup2(redir_fd, sys.stdout.fileno()) 2466048Sgblack@eecs.umich.edu if not options.redirect_stderr: 2476048Sgblack@eecs.umich.edu os.dup2(redir_fd, sys.stderr.fileno()) 2486048Sgblack@eecs.umich.edu 2496048Sgblack@eecs.umich.edu if options.redirect_stderr: 2506048Sgblack@eecs.umich.edu redir_fd = os.open(stderr_file, os. O_WRONLY | os.O_CREAT | os.O_TRUNC) 2516048Sgblack@eecs.umich.edu os.dup2(redir_fd, sys.stderr.fileno()) 2526048Sgblack@eecs.umich.edu 2536048Sgblack@eecs.umich.edu done = False 2546048Sgblack@eecs.umich.edu 2556048Sgblack@eecs.umich.edu if options.build_info: 2566048Sgblack@eecs.umich.edu done = True 2576048Sgblack@eecs.umich.edu print('Build information:') 2586048Sgblack@eecs.umich.edu print() 2596048Sgblack@eecs.umich.edu print('compiled %s' % defines.compileDate) 2606048Sgblack@eecs.umich.edu print('build options:') 2616048Sgblack@eecs.umich.edu keys = defines.buildEnv.keys() 2626048Sgblack@eecs.umich.edu keys.sort() 2636048Sgblack@eecs.umich.edu for key in keys: 2646048Sgblack@eecs.umich.edu val = defines.buildEnv[key] 2656048Sgblack@eecs.umich.edu print(' %s = %s' % (key, val)) 2666048Sgblack@eecs.umich.edu print() 2676048Sgblack@eecs.umich.edu 2686048Sgblack@eecs.umich.edu if options.copyright: 2696048Sgblack@eecs.umich.edu done = True 2706048Sgblack@eecs.umich.edu print(info.COPYING) 2716140Sgblack@eecs.umich.edu print() 2726140Sgblack@eecs.umich.edu 2736048Sgblack@eecs.umich.edu if options.readme: 2747720Sgblack@eecs.umich.edu done = True 2757720Sgblack@eecs.umich.edu print('Readme:') 2767720Sgblack@eecs.umich.edu print() 2776048Sgblack@eecs.umich.edu print(info.README) 2786048Sgblack@eecs.umich.edu print() 2796049Sgblack@eecs.umich.edu 2807678Sgblack@eecs.umich.edu if options.debug_help: 2816049Sgblack@eecs.umich.edu done = True 2826049Sgblack@eecs.umich.edu check_tracing() 2836049Sgblack@eecs.umich.edu debug.help() 2846049Sgblack@eecs.umich.edu 2856049Sgblack@eecs.umich.edu if options.list_sim_objects: 2866140Sgblack@eecs.umich.edu import SimObject 2876049Sgblack@eecs.umich.edu done = True 2886049Sgblack@eecs.umich.edu print("SimObjects:") 2896049Sgblack@eecs.umich.edu objects = SimObject.allClasses.keys() 2906049Sgblack@eecs.umich.edu objects.sort() 2916049Sgblack@eecs.umich.edu for name in objects: 2926049Sgblack@eecs.umich.edu obj = SimObject.allClasses[name] 2936049Sgblack@eecs.umich.edu print(" %s" % obj) 2946049Sgblack@eecs.umich.edu params = obj._params.keys() 2957720Sgblack@eecs.umich.edu params.sort() 2966049Sgblack@eecs.umich.edu for pname in params: 2975124Sgblack@eecs.umich.edu param = obj._params[pname] 2985124Sgblack@eecs.umich.edu default = getattr(param, 'default', '') 299 print(" %s" % pname) 300 if default: 301 print(" default: %s" % default) 302 print(" desc: %s" % param.desc) 303 print() 304 print() 305 306 if done: 307 sys.exit(0) 308 309 # setting verbose and quiet at the same time doesn't make sense 310 if options.verbose > 0 and options.quiet > 0: 311 options.usage(2) 312 313 verbose = options.verbose - options.quiet 314 if verbose >= 0: 315 print("gem5 Simulator System. http://gem5.org") 316 print(brief_copyright) 317 print() 318 319 print("gem5 compiled %s" % defines.compileDate) 320 321 print("gem5 started %s" % 322 datetime.datetime.now().strftime("%b %e %Y %X")) 323 print("gem5 executing on %s, pid %d" % 324 (socket.gethostname(), os.getpid())) 325 326 # in Python 3 pipes.quote() is moved to shlex.quote() 327 import pipes 328 print("command line:", " ".join(map(pipes.quote, sys.argv))) 329 print() 330 331 # check to make sure we can find the listed script 332 if not arguments or not os.path.isfile(arguments[0]): 333 if arguments and not os.path.isfile(arguments[0]): 334 print("Script %s not found" % arguments[0]) 335 336 options.usage(2) 337 338 # tell C++ about output directory 339 core.setOutputDir(options.outdir) 340 341 # update the system path with elements from the -p option 342 sys.path[0:0] = options.path 343 344 # set stats options 345 stats.addStatVisitor(options.stats_file) 346 347 # Disable listeners unless running interactively or explicitly 348 # enabled 349 if options.listener_mode == "off": 350 m5.disableAllListeners() 351 elif options.listener_mode == "auto": 352 if not isInteractive(): 353 inform("Standard input is not a terminal, disabling listeners.") 354 m5.disableAllListeners() 355 elif options.listener_mode == "on": 356 pass 357 else: 358 panic("Unhandled listener mode: %s" % options.listener_mode) 359 360 if options.listener_loopback_only: 361 m5.listenersLoopbackOnly() 362 363 # set debugging options 364 debug.setRemoteGDBPort(options.remote_gdb_port) 365 for when in options.debug_break: 366 debug.schedBreak(int(when)) 367 368 if options.debug_flags: 369 check_tracing() 370 371 on_flags = [] 372 off_flags = [] 373 for flag in options.debug_flags: 374 off = False 375 if flag.startswith('-'): 376 flag = flag[1:] 377 off = True 378 379 if flag not in debug.flags: 380 print("invalid debug flag '%s'" % flag, file=sys.stderr) 381 sys.exit(1) 382 383 if off: 384 debug.flags[flag].disable() 385 else: 386 debug.flags[flag].enable() 387 388 if options.debug_start: 389 check_tracing() 390 e = event.create(trace.enable, event.Event.Debug_Enable_Pri) 391 event.mainq.schedule(e, options.debug_start) 392 else: 393 trace.enable() 394 395 if options.debug_end: 396 check_tracing() 397 e = event.create(trace.disable, event.Event.Debug_Enable_Pri) 398 event.mainq.schedule(e, options.debug_end) 399 400 trace.output(options.debug_file) 401 402 for ignore in options.debug_ignore: 403 check_tracing() 404 trace.ignore(ignore) 405 406 sys.argv = arguments 407 sys.path = [ os.path.dirname(sys.argv[0]) ] + sys.path 408 409 filename = sys.argv[0] 410 filedata = open(filename, 'r').read() 411 filecode = compile(filedata, filename, 'exec') 412 scope = { '__file__' : filename, 413 '__name__' : '__m5_main__' } 414 415 # if pdb was requested, execfile the thing under pdb, otherwise, 416 # just do the execfile normally 417 if options.pdb: 418 import pdb 419 import traceback 420 421 pdb = pdb.Pdb() 422 try: 423 pdb.run(filecode, scope) 424 except SystemExit: 425 print("The program exited via sys.exit(). Exit status: ", end=' ') 426 print(sys.exc_info()[1]) 427 except: 428 traceback.print_exc() 429 print("Uncaught exception. Entering post mortem debugging") 430 t = sys.exc_info()[2] 431 while t.tb_next is not None: 432 t = t.tb_next 433 pdb.interaction(t.tb_frame,t) 434 else: 435 exec filecode in scope 436 437 # once the script is done 438 if options.interactive: 439 interact(scope) 440 441if __name__ == '__main__': 442 from pprint import pprint 443 444 options, arguments = parse_options() 445 446 print('opts:') 447 pprint(options, indent=4) 448 print() 449 450 print('args:') 451 pprint(arguments, indent=4) 452