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 <odanrc@yahoo.com.br> Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#define __INIFILE_HH__
|
||||
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
@@ -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<void(
|
||||
const std::string&, const std::string&)>;
|
||||
|
||||
/// Iterate over key/value pairs of the given section.
|
||||
void visitSection(const std::string §ionName, VisitSectionCallback cb);
|
||||
};
|
||||
|
||||
#endif // __INIFILE_HH__
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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 @@ 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);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user