From d2af40faa0a16d17173f71a353f0664a461c263e Mon Sep 17 00:00:00 2001 From: Andreas Sandberg Date: Fri, 4 Sep 2020 17:12:27 +0100 Subject: [PATCH] python: Add the ability to check if a debug flag has been enabled There is currently no Python API to check if a debug flag is enabled. Add a new status property that can be read or set to control the status of a flag. The stat of a flag can also be queried by converting it to a bool. For example: m5.debug.flags["XBar"].status = True if m5.debug.flags["XBar"]: print("XBar debugging is on") Change-Id: I5a50c39ced182ab44e18c061c463d7d9c41ef186 Signed-off-by: Andreas Sandberg Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/34119 Reviewed-by: Jason Lowe-Power Reviewed-by: Gabe Black Maintainer: Jason Lowe-Power Tested-by: kokoro --- src/python/pybind11/debug.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/python/pybind11/debug.cc b/src/python/pybind11/debug.cc index ed2942bc7..69c497c1d 100644 --- a/src/python/pybind11/debug.cc +++ b/src/python/pybind11/debug.cc @@ -98,6 +98,20 @@ pybind_init_debug(py::module &m_native) .def_property_readonly("desc", &Debug::Flag::desc) .def("enable", &Debug::Flag::enable) .def("disable", &Debug::Flag::disable) + .def_property("status", + [](const Debug::Flag *flag) { + return flag->status(); + }, + [](Debug::Flag *flag, bool state) { + if (state) { + flag->enable(); + } else { + flag->disable(); + } + }) + .def("__bool__", [](const Debug::Flag *flag) { + return flag->status(); + }) ; py::class_(m_debug, "SimpleFlag", c_flag); -- 2.30.2