From: Ciro Santilli Date: Tue, 20 Oct 2020 15:28:26 +0000 (+0100) Subject: sim,base: make checkpointMapIn warn if an unknown key is found X-Git-Tag: develop-gem5-snapshot~258 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=83bbe530b9c608301337e6fd4ee76d423d6b4efe;p=gem5.git sim,base: make checkpointMapIn warn if an unknown key is found The warning happens when a key is present in the checkpoint but not in the values that gem5 source code knows about. To do this, we must expose iteration over IniFile section keys. To not have to make those classes public, a visitor method is implemented. Change-Id: I23340a953f3e604642b97690a7328b10fdd740a8 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/37575 Reviewed-by: Daniel Carvalho Maintainer: Bobby R. Bruce Tested-by: kokoro --- diff --git a/src/base/inifile.cc b/src/base/inifile.cc index 1fbebb46b..b2eeafcbe 100644 --- a/src/base/inifile.cc +++ b/src/base/inifile.cc @@ -345,3 +345,25 @@ IniFile::dump() i->second->dump(i->first); } } + +IniFile::Section::EntryTable::const_iterator +IniFile::Section::begin() const +{ + return table.begin(); +} + +IniFile::Section::EntryTable::const_iterator +IniFile::Section::end() const +{ + return table.end(); +} + +void +IniFile::visitSection(const std::string §ionName, + IniFile::VisitSectionCallback cb) +{ + const auto& section = *table.at(sectionName); + for (const auto& pair : section) { + cb(pair.first, pair.second->getValue()); + } +} diff --git a/src/base/inifile.hh b/src/base/inifile.hh index 095d13266..ae6dc4501 100644 --- a/src/base/inifile.hh +++ b/src/base/inifile.hh @@ -30,6 +30,7 @@ #define __INIFILE_HH__ #include +#include #include #include #include @@ -132,6 +133,9 @@ class IniFile /// Print the contents of this section to cout (for debugging). void dump(const std::string §ionName); + + EntryTable::const_iterator begin() const; + EntryTable::const_iterator end() const; }; /// SectionTable type. Map of strings to Section object pointers. @@ -203,6 +207,13 @@ class IniFile /// Dump contents to cout. For debugging. void dump(); + + /// Visitor callback that receives key/value pairs. + using VisitSectionCallback = std::function; + + /// Iterate over key/value pairs of the given section. + void visitSection(const std::string §ionName, VisitSectionCallback cb); }; #endif // __INIFILE_HH__ diff --git a/src/sim/serialize.cc b/src/sim/serialize.cc index e502d9aa7..a563332a1 100644 --- a/src/sim/serialize.cc +++ b/src/sim/serialize.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 ARM Limited + * Copyright (c) 2015, 2020 ARM Limited * All rights reserved * * The license below extends only to copyright in the software and shall @@ -337,6 +337,13 @@ CheckpointIn::sectionExists(const string §ion) return db->sectionExists(section); } +void +CheckpointIn::visitSection(const std::string §ion, + IniFile::VisitSectionCallback cb) +{ + db->visitSection(section, cb); +} + void objParamIn(CheckpointIn &cp, const string &name, SimObject * ¶m) { diff --git a/src/sim/serialize.hh b/src/sim/serialize.hh index 9e25d0987..80fac6661 100644 --- a/src/sim/serialize.hh +++ b/src/sim/serialize.hh @@ -55,6 +55,7 @@ #include #include +#include "base/inifile.hh" #include "base/logging.hh" #include "sim/serialize_handlers.hh" @@ -94,6 +95,8 @@ class CheckpointIn bool entryExists(const std::string §ion, const std::string &entry); bool sectionExists(const std::string §ion); + void visitSection(const std::string §ion, + IniFile::VisitSectionCallback cb); /** @}*/ //end of api_checkout group // The following static functions have to do with checkpoint @@ -555,6 +558,16 @@ mappingParamIn(CheckpointIn &cp, const char* sectionName, param[name_to_index[key]] = value; } } + cp.visitSection( + Serializable::currentSection(), + [name_to_index](const std::string& key, const std::string& val) + { + if (!name_to_index.count(key)) { + warn("unknown entry found in checkpoint: %s %s %s\n", + Serializable::currentSection(), key, val); + } + } + ); } //