debug.py revision 8269
15860Snate@binkert.org# Copyright (c) 2008 The Hewlett-Packard Development Company
25860Snate@binkert.org# All rights reserved.
35860Snate@binkert.org#
45860Snate@binkert.org# Redistribution and use in source and binary forms, with or without
55860Snate@binkert.org# modification, are permitted provided that the following conditions are
65860Snate@binkert.org# met: redistributions of source code must retain the above copyright
75860Snate@binkert.org# notice, this list of conditions and the following disclaimer;
85860Snate@binkert.org# redistributions in binary form must reproduce the above copyright
95860Snate@binkert.org# notice, this list of conditions and the following disclaimer in the
105860Snate@binkert.org# documentation and/or other materials provided with the distribution;
115860Snate@binkert.org# neither the name of the copyright holders nor the names of its
125860Snate@binkert.org# contributors may be used to endorse or promote products derived from
135860Snate@binkert.org# this software without specific prior written permission.
145860Snate@binkert.org#
155860Snate@binkert.org# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
165860Snate@binkert.org# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
175860Snate@binkert.org# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
185860Snate@binkert.org# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
195860Snate@binkert.org# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
205860Snate@binkert.org# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
215860Snate@binkert.org# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
225860Snate@binkert.org# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
235860Snate@binkert.org# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
245860Snate@binkert.org# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
255860Snate@binkert.org# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
265860Snate@binkert.org#
275860Snate@binkert.org# Authors: Nathan Binkert
285860Snate@binkert.org
298269Snate@binkert.orgfrom UserDict import DictMixin
308269Snate@binkert.org
315801Snate@binkert.orgimport internal
325801Snate@binkert.org
338269Snate@binkert.orgfrom internal.debug import SimpleFlag, CompoundFlag
345801Snate@binkert.orgfrom internal.debug import schedBreakCycle, setRemoteGDBPort
358269Snate@binkert.orgfrom m5.util import printList
368232Snate@binkert.org
378232Snate@binkert.orgdef help():
388232Snate@binkert.org    print "Base Flags:"
398269Snate@binkert.org    for name in sorted(flags):
408269Snate@binkert.org        if name == 'All':
418269Snate@binkert.org            continue
428269Snate@binkert.org        flag = flags[name]
438269Snate@binkert.org        children = [c for c in flag.kids() ]
448269Snate@binkert.org        if not children:
458269Snate@binkert.org            print "    %s: %s" % (name, flag.desc())
468232Snate@binkert.org    print
478232Snate@binkert.org    print "Compound Flags:"
488269Snate@binkert.org    for name in sorted(flags):
498269Snate@binkert.org        if name == 'All':
508232Snate@binkert.org            continue
518269Snate@binkert.org        flag = flags[name]
528269Snate@binkert.org        children = [c for c in flag.kids() ]
538269Snate@binkert.org        if children:
548269Snate@binkert.org            print "    %s: %s" % (name, flag.desc())
558269Snate@binkert.org            printList([ c.name() for c in children ], indent=8)
568269Snate@binkert.org    print
578232Snate@binkert.org
588269Snate@binkert.orgclass AllFlags(DictMixin):
598232Snate@binkert.org    def __init__(self):
608232Snate@binkert.org        self._version = -1
618232Snate@binkert.org        self._dict = {}
628232Snate@binkert.org
638232Snate@binkert.org    def _update(self):
648232Snate@binkert.org        current_version = internal.debug.getAllFlagsVersion()
658232Snate@binkert.org        if self._version == current_version:
668232Snate@binkert.org            return
678232Snate@binkert.org
688232Snate@binkert.org        self._dict.clear()
698232Snate@binkert.org        for flag in internal.debug.getAllFlags():
708232Snate@binkert.org            self._dict[flag.name()] = flag
718232Snate@binkert.org        self._version = current_version
728232Snate@binkert.org
738232Snate@binkert.org    def __contains__(self, item):
748232Snate@binkert.org        self._update()
758232Snate@binkert.org        return item in self._dict
768232Snate@binkert.org
778232Snate@binkert.org    def __getitem__(self, item):
788232Snate@binkert.org        self._update()
798232Snate@binkert.org        return self._dict[item]
808232Snate@binkert.org
818232Snate@binkert.org    def keys(self):
828232Snate@binkert.org        self._update()
838232Snate@binkert.org        return self._dict.keys()
848232Snate@binkert.org
858232Snate@binkert.org    def values(self):
868232Snate@binkert.org        self._update()
878232Snate@binkert.org        return self._dict.values()
888232Snate@binkert.org
898232Snate@binkert.org    def items(self):
908232Snate@binkert.org        self._update()
918232Snate@binkert.org        return self._dict.items()
928232Snate@binkert.org
938232Snate@binkert.org    def iterkeys(self):
948232Snate@binkert.org        self._update()
958232Snate@binkert.org        return self._dict.iterkeys()
968232Snate@binkert.org
978232Snate@binkert.org    def itervalues(self):
988232Snate@binkert.org        self._update()
998232Snate@binkert.org        return self._dict.itervalues()
1008232Snate@binkert.org
1018232Snate@binkert.org    def iteritems(self):
1028232Snate@binkert.org        self._update()
1038232Snate@binkert.org        return self._dict.iteritems()
1048232Snate@binkert.org
1058232Snate@binkert.orgflags = AllFlags()
106