Ciro Santilli has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/37575 )
Change subject: sim,base: make checkpointMapIn warn if an unknown key is
found
......................................................................
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.
Change-Id: I23340a953f3e604642b97690a7328b10fdd740a8
---
M src/base/inifile.cc
M src/base/inifile.hh
M src/sim/serialize.cc
M src/sim/serialize.hh
4 files changed, 75 insertions(+), 0 deletions(-)
diff --git a/src/base/inifile.cc b/src/base/inifile.cc
index 1fbebb4..acbe422 100644
--- a/src/base/inifile.cc
+++ b/src/base/inifile.cc
@@ -345,3 +345,26 @@
i->second->dump(i->first);
}
}
+
+/// Iterate key values of a given section.
+IniFile::Section::EntryTable::const_iterator
+IniFile::Section::cbegin() const
+{
+ return table.cbegin();
+}
+
+IniFile::Section::EntryTable::const_iterator
+IniFile::Section::cend() const
+{
+ return table.cend();
+}
+
+std::pair<IniFile::SectionIterator,IniFile::SectionIterator>
+IniFile::iterSection(const std::string §ionName)
+{
+ const auto& section = table.at(sectionName);
+ return std::make_pair(
+ SectionIterator(section->cbegin()),
+ SectionIterator(section->cend())
+ );
+}
diff --git a/src/base/inifile.hh b/src/base/inifile.hh
index 095d132..f1101cf 100644
--- a/src/base/inifile.hh
+++ b/src/base/inifile.hh
@@ -84,11 +84,17 @@
void appendValue(const std::string &v) { value += " "; value += v;
}
};
+ public:
+ class SectionIterator;
+
+ protected:
///
/// A section.
///
class Section
{
+ friend class SectionIterator;
+
/// EntryTable type. Map of strings to Entry object pointers.
typedef std::unordered_map<std::string, Entry *> EntryTable;
@@ -132,6 +138,9 @@
/// Print the contents of this section to cout (for debugging).
void dump(const std::string §ionName);
+
+ EntryTable::const_iterator cbegin() const;
+ EntryTable::const_iterator cend() const;
};
/// SectionTable type. Map of strings to Section object pointers.
@@ -151,6 +160,25 @@
Section *findSection(const std::string §ionName) const;
public:
+ class SectionIterator {
+ private:
+ using It = Section::EntryTable::const_iterator;
+ It it;
+ public:
+ using value_type = std::pair<std::string,std::string>;
+ SectionIterator(It it) : it(it) {}
+ SectionIterator& operator++() {it++; return *this;}
+ SectionIterator operator++(int) {auto retval = *this;
+ ++(*this); return retval;}
+ bool operator==(SectionIterator other) const { return it ==
other.it; }
+ bool operator!=(SectionIterator other) const {
+ return !(*this == other); }
+ value_type operator*() {
+ auto pair = *it;
+ return std::make_pair(pair.first, pair.second->getValue());
+ }
+ };
+
/// Constructor.
IniFile();
@@ -203,6 +231,10 @@
/// Dump contents to cout. For debugging.
void dump();
+
+ /// Iterate key values of a given section.
+ std::pair<SectionIterator,SectionIterator>
+ iterSection(const std::string §ionName);
};
#endif // __INIFILE_HH__
diff --git a/src/sim/serialize.cc b/src/sim/serialize.cc
index e502d9a..3732a28 100644
--- a/src/sim/serialize.cc
+++ b/src/sim/serialize.cc
@@ -337,6 +337,12 @@
return db->sectionExists(section);
}
+std::pair<IniFile::SectionIterator,IniFile::SectionIterator>
+CheckpointIn::iterSection(const string §ion)
+{
+ return db->iterSection(section);
+}
+
void
objParamIn(CheckpointIn &cp, const string &name, SimObject * ¶m)
{
diff --git a/src/sim/serialize.hh b/src/sim/serialize.hh
index c774eab..74567a6 100644
--- a/src/sim/serialize.hh
+++ b/src/sim/serialize.hh
@@ -55,6 +55,7 @@
#include <unordered_map>
#include <vector>
+#include "base/inifile.hh"
#include "base/logging.hh"
#include "sim/serialize_handlers.hh"
@@ -94,6 +95,8 @@
bool entryExists(const std::string §ion, const std::string &entry);
bool sectionExists(const std::string §ion);
+ std::pair<IniFile::SectionIterator,IniFile::SectionIterator>
+ iterSection(const std::string §ion);
/** @}*/ //end of api_checkout group
// The following static functions have to do with checkpoint
@@ -557,6 +560,17 @@
param[name_to_index[key]] = value;
}
}
+ auto start_end = os.iterSection(Serializable::currentSection());
+ auto start = start_end.first;
+ const auto end = start_end.second;
+ while (start != end) {
+ const auto& key = (*start).first;
+ if (!name_to_index.count(key)) {
+ warn("unknown entry found in checkpoint: %s %s\n",
+ Serializable::currentSection(), key);
+ }
+ start++;
+ }
}
//
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/37575
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: I23340a953f3e604642b97690a7328b10fdd740a8
Gerrit-Change-Number: 37575
Gerrit-PatchSet: 1
Gerrit-Owner: Ciro Santilli <ciro.santi...@arm.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