Nathanael Premillieu has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/39055 )

Change subject: base: Reinstate Debug::All flag
......................................................................

base: Reinstate Debug::All flag

Reinstate the All debug flags that activates all
the debug flags, except for FmtStackTrace and FmtStackTrace.
This flag is now listed in the Compound Flags list.
This flag is quite helpful when debugging a difficult
to understand bug or a bug that takes a long time to reach.

Change-Id: I9e66265896b6ef5882bb8935300679c9ad30a9c9
---
M src/base/debug.cc
M src/base/debug.hh
M src/python/m5/debug.py
M src/python/pybind11/debug.cc
4 files changed, 83 insertions(+), 5 deletions(-)



diff --git a/src/base/debug.cc b/src/base/debug.cc
index 45d9f9d..136187b 100644
--- a/src/base/debug.cc
+++ b/src/base/debug.cc
@@ -79,6 +79,18 @@
     return flags;
 }

+// mostFlags is defined to be used in the AllFlag class. It is constructed the
+// same way as allFlags but only with SimpleFlag (no CompoundFlag, as it is
+// redundant) and without including the "FmtFlag", "FmtStackTrace" and
+// "FmtTicksOff" flags as they modify the printing behavior
+// of the debug information and should not be activated by default.
+FlagsMap &
+mostFlags()
+{
+    static FlagsMap flags;
+    return flags;
+}
+
 bool Flag::_globalEnable = false;

 Flag *
@@ -123,6 +135,20 @@
         i.second->sync();
 }

+SimpleFlag::SimpleFlag(const char *name, const char *desc)
+    : Flag(name, desc), _status(false)
+{
+    if (strcmp(name, "FmtFlag") != 0 &&
+        strcmp(name, "FmtStackTrace") != 0 &&
+        strcmp(name, "FmtTicksOff") != 0) {
+        pair<FlagsMap::iterator, bool> result =
+            mostFlags().insert(make_pair(name, this));
+
+        if (!result.second)
+ panic("Flag %s has already been added to the 'All' flag!", name);
+    }
+}
+
 void
 CompoundFlag::enable()
 {
@@ -151,6 +177,38 @@
     return true;
 }

+void
+AllFlag::enable ()
+{
+    FlagsMap::iterator i = mostFlags().begin();
+    FlagsMap::iterator end = mostFlags().end();
+    for (; i != end; ++i)
+        i->second->enable();
+}
+
+void
+AllFlag::disable ()
+{
+    FlagsMap::iterator i = mostFlags().begin();
+    FlagsMap::iterator end = mostFlags().end();
+    for (; i != end; ++i)
+        i->second->disable();
+}
+
+bool
+AllFlag::status() const
+{
+    FlagsMap::iterator i = mostFlags().begin();
+    FlagsMap::iterator end = mostFlags().end();
+    for (; i != end; ++i)
+        if (i->second->status())
+            return true;
+    return false;
+}
+
+AllFlag theAllFlags;
+const Flag *All = &theAllFlags;
+
 bool
 changeFlag(const char *s, bool value)
 {
diff --git a/src/base/debug.hh b/src/base/debug.hh
index 7cc7137..2d8a41f 100644
--- a/src/base/debug.hh
+++ b/src/base/debug.hh
@@ -88,9 +88,7 @@
     void sync() override { _tracing = _globalEnable && _status; }

   public:
-    SimpleFlag(const char *name, const char *desc)
-        : Flag(name, desc), _status(false)
-    { }
+    SimpleFlag(const char *name, const char *desc);

     bool status() const override { return _tracing; }

@@ -119,11 +117,27 @@
     bool status() const override;
 };

+class AllFlag : public Flag
+{
+    public:
+    AllFlag()
+        : Flag("All", "All Flags, except FmtFlag, FmtStackTrace and"
+                       "FmtTicksOff")
+    {}
+
+    void enable () override;
+    void disable () override;
+    bool status() const override;
+};
+
 typedef std::map<std::string, Flag *> FlagsMap;
 FlagsMap &allFlags();
+FlagsMap &mostFlags();

 Flag *findFlag(const std::string &name);

+extern const Flag *All;
+
 bool changeFlag(const char *s, bool value);

 } // namespace Debug
diff --git a/src/python/m5/debug.py b/src/python/m5/debug.py
index 6b45b16..30c5a44 100644
--- a/src/python/m5/debug.py
+++ b/src/python/m5/debug.py
@@ -29,7 +29,7 @@
 from collections import Mapping

 import _m5.debug
-from _m5.debug import SimpleFlag, CompoundFlag
+from _m5.debug import SimpleFlag, CompoundFlag, AllFlag
 from _m5.debug import schedBreak, setRemoteGDBPort
 from m5.util import printList

@@ -37,11 +37,16 @@
     sorted_flags = sorted(flags.items(), key=lambda kv: kv[0])

     print("Base Flags:")
- for name, flag in filter(lambda kv: not isinstance(kv[1], CompoundFlag), + for name, flag in filter(lambda kv: not (isinstance(kv[1], CompoundFlag) + or isinstance(kv[1], AllFlag)),
                              sorted_flags):
         print("    %s: %s" % (name, flag.desc))
     print()
     print("Compound Flags:")
+    # Special case for AllFlag
+    for name, flag in filter(lambda kv: isinstance(kv[1], AllFlag),
+                             sorted_flags):
+        print("    %s: %s" % (name, flag.desc))
     for name, flag in filter(lambda kv: isinstance(kv[1], CompoundFlag),
                              sorted_flags):
         print("    %s: %s" % (name, flag.desc))
diff --git a/src/python/pybind11/debug.cc b/src/python/pybind11/debug.cc
index 84673f1..681c27a 100644
--- a/src/python/pybind11/debug.cc
+++ b/src/python/pybind11/debug.cc
@@ -114,6 +114,7 @@
     py::class_<Debug::CompoundFlag>(m_debug, "CompoundFlag", c_flag)
         .def("kids", &Debug::CompoundFlag::kids)
         ;
+    py::class_<Debug::AllFlag>(m_debug, "AllFlag", c_flag);


     py::module m_trace = m_native.def_submodule("trace");

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/39055
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I9e66265896b6ef5882bb8935300679c9ad30a9c9
Gerrit-Change-Number: 39055
Gerrit-PatchSet: 1
Gerrit-Owner: Nathanael Premillieu <nathanael.premill...@huawei.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to