scons,debug: Implement the "All" flag in C++ and not scons.
Create an AllFlagsFlag class which inherits from the CompoundFlag class. This class is a singleton, and the SimpleFlags install themselves in it instead of having SCons collect them. The allFlagsVersion global variable was supposed to be for debugging according to a comment, but was actually an important part of the "All" flags inner workings. It was not exposed in the header, but was redefined/pulled through in src/python/pybind11/debug.cc. The AllFlagsFlag class now tracks that value, and it can be accessed without reaching behind the curtain. This also somewhat decentralizes the debug flag building process in SCons. The debug/flags.cc still includes all flags at once which centralizes them, but at least now the "All" flag won't also. Change-Id: I8430e0fe9022846aade028fb46c80777169a2007 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/48370 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br> Reviewed-by: Nathanael Premillieu <nathanael.premillieu@huawei.com> Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com> Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
This commit is contained in:
@@ -71,13 +71,17 @@ breakpoint()
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
// Flags for debugging purposes. Primarily for trace.hh
|
||||
//
|
||||
int allFlagsVersion = 0;
|
||||
// Used to check the freshness of cached views of all flags.
|
||||
FlagsMap &
|
||||
allFlags()
|
||||
{
|
||||
// Ensure that the special "All" compound debug flag has been created,
|
||||
// and avoid infinite recursion.
|
||||
static bool done = false;
|
||||
if (!done) {
|
||||
done = true;
|
||||
AllFlagsFlag::instance();
|
||||
}
|
||||
static FlagsMap flags;
|
||||
return flags;
|
||||
}
|
||||
@@ -88,8 +92,9 @@ Flag *
|
||||
findFlag(const std::string &name)
|
||||
{
|
||||
FlagsMap::iterator i = allFlags().find(name);
|
||||
if (i == allFlags().end())
|
||||
if (i == allFlags().end()) {
|
||||
return NULL;
|
||||
}
|
||||
return i->second;
|
||||
}
|
||||
|
||||
@@ -101,8 +106,6 @@ Flag::Flag(const char *name, const char *desc)
|
||||
|
||||
panic_if(!result.second, "Flag %s already defined!", name);
|
||||
|
||||
++allFlagsVersion;
|
||||
|
||||
sync();
|
||||
}
|
||||
|
||||
@@ -127,6 +130,14 @@ Flag::globalDisable()
|
||||
i.second->sync();
|
||||
}
|
||||
|
||||
SimpleFlag::SimpleFlag(const char *name, const char *desc, bool is_format)
|
||||
: Flag(name, desc), _isFormat(is_format)
|
||||
{
|
||||
// Add non-format flags to the special "All" compound flag.
|
||||
if (!isFormat())
|
||||
AllFlagsFlag::instance().add(this);
|
||||
}
|
||||
|
||||
void
|
||||
CompoundFlag::enable()
|
||||
{
|
||||
@@ -141,6 +152,26 @@ CompoundFlag::disable()
|
||||
k->disable();
|
||||
}
|
||||
|
||||
AllFlagsFlag::AllFlagsFlag() : CompoundFlag("All",
|
||||
"Controls all debug flags. It should not be used within C++ code.", {})
|
||||
{}
|
||||
|
||||
void
|
||||
AllFlagsFlag::add(SimpleFlag *flag)
|
||||
{
|
||||
++_version;
|
||||
_kids.push_back(flag);
|
||||
}
|
||||
|
||||
int AllFlagsFlag::_version = 0;
|
||||
|
||||
AllFlagsFlag &
|
||||
AllFlagsFlag::instance()
|
||||
{
|
||||
static AllFlagsFlag flag;
|
||||
return flag;
|
||||
}
|
||||
|
||||
bool
|
||||
changeFlag(const char *s, bool value)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user