diff options
author | Sascha Bischoff <sascha.bischoff@ARM.com> | 2015-11-05 18:26:23 +0000 |
---|---|---|
committer | Sascha Bischoff <sascha.bischoff@ARM.com> | 2015-11-05 18:26:23 +0000 |
commit | 2d79bf3d4dfd997d352b8399c4c9f3ff9d05de41 (patch) | |
tree | f761619cf3fb81cb41c2f6e205c786b0381f675e /src | |
parent | 47326f54222af99d96ab57508449d1bb62d03842 (diff) | |
download | gem5-2d79bf3d4dfd997d352b8399c4c9f3ff9d05de41.tar.xz |
sim: Disable gzip compression for writefile pseudo instruction
The writefile pseudo instruction uses OutputDirectory::create and
OutputDirectory::openFile to create the output files. However, by
default these will check the file extention for .gz, and create a gzip
compressed stream if the file ending matches. When writing out files,
we want to write them out exactly as they are in the guest simulation,
and never want to compress them with gzio. Additionally, this causes
m5 writefile to fail when checking the error flags for the output
steam.
With this patch we add an additional no_gz argument to
OutputDirectory::create and OutputDirectory::openFile which allows us
to override the gzip compression. Therefore, for m5 writefile we
disable the filename check, and always create a standard ostream.
Diffstat (limited to 'src')
-rw-r--r-- | src/base/output.cc | 10 | ||||
-rw-r--r-- | src/base/output.hh | 10 | ||||
-rw-r--r-- | src/sim/pseudo_inst.cc | 4 |
3 files changed, 16 insertions, 8 deletions
diff --git a/src/base/output.cc b/src/base/output.cc index ce1b49a82..516a1d05a 100644 --- a/src/base/output.cc +++ b/src/base/output.cc @@ -77,9 +77,11 @@ OutputDirectory::checkForStdio(const string &name) const ostream * OutputDirectory::openFile(const string &filename, - ios_base::openmode mode) + ios_base::openmode mode, bool no_gz) { - if (filename.find(".gz", filename.length()-3) < filename.length()) { + bool gz = !no_gz; + gz = gz && filename.find(".gz", filename.length()-3) < filename.length(); + if (gz) { ogzstream *file = new ogzstream(filename.c_str(), mode); if (!file->is_open()) fatal("Cannot open file %s", filename); @@ -153,7 +155,7 @@ OutputDirectory::resolve(const string &name) const } ostream * -OutputDirectory::create(const string &name, bool binary) +OutputDirectory::create(const string &name, bool binary, bool no_gz) { ostream *file = checkForStdio(name); if (file) @@ -162,7 +164,7 @@ OutputDirectory::create(const string &name, bool binary) string filename = resolve(name); ios_base::openmode mode = ios::trunc | (binary ? ios::binary : (ios::openmode)0); - file = openFile(filename, mode); + file = openFile(filename, mode, no_gz); return file; } diff --git a/src/base/output.hh b/src/base/output.hh index ef628882d..67e6ecb18 100644 --- a/src/base/output.hh +++ b/src/base/output.hh @@ -86,10 +86,13 @@ class OutputDirectory * * @param filename file to open * @param mode attributes to open file with + * @param no_gz true to disable opening the file as a gzip compressed output + * stream; false otherwise * @return stream pointer to opened file; will cause sim fail on error */ std::ostream *openFile(const std::string &filename, - std::ios_base::openmode mode = std::ios::trunc); + std::ios_base::openmode mode = std::ios::trunc, + bool no_gz = false); /** * Sets name of this directory. @@ -111,9 +114,12 @@ class OutputDirectory * @param name name of file to create (without this directory's name * leading it) * @param binary true to create a binary file; false otherwise + * @param no_gz true to disable creating a gzip compressed output stream; + * false otherwise * @return stream to the opened file */ - std::ostream *create(const std::string &name, bool binary = false); + std::ostream *create(const std::string &name, bool binary = false, + bool no_gz = false); /** * Closes a file stream. diff --git a/src/sim/pseudo_inst.cc b/src/sim/pseudo_inst.cc index d4e2085df..fb19b21b1 100644 --- a/src/sim/pseudo_inst.cc +++ b/src/sim/pseudo_inst.cc @@ -565,13 +565,13 @@ writefile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset, if (offset == 0) { // create a new file (truncate) - os = simout.create(filename, true); + os = simout.create(filename, true, true); } else { // do not truncate file if offset is non-zero // (ios::in flag is required as well to keep the existing data // intact, otherwise existing data will be zeroed out.) os = simout.openFile(simout.directory() + filename, - ios::in | ios::out | ios::binary); + ios::in | ios::out | ios::binary, true); } if (!os) panic("could not open file %s\n", filename); |