From 1088f0c4ac3999fc3c363cc51daef4cfb360a2bd Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Thu, 30 Nov 2017 17:36:53 -0800 Subject: misc: Rename misc.(hh|cc) to logging.(hh|cc) These files aren't a collection of miscellaneous stuff, they're the definition of the Logger interface, and a few utility macros for calling into that interface (panic, warn, etc.). Change-Id: I84267ac3f45896a83c0ef027f8f19c5e9a5667d1 Reviewed-on: https://gem5-review.googlesource.com/6226 Reviewed-by: Brandon Potter Maintainer: Gabe Black --- src/base/SConscript | 2 +- src/base/addr_range.hh | 2 +- src/base/bigint.hh | 2 +- src/base/bmpwriter.cc | 2 +- src/base/circlebuf.hh | 2 +- src/base/debug.cc | 2 +- src/base/hostinfo.cc | 2 +- src/base/imgwriter.cc | 5 +- src/base/intmath.hh | 2 +- src/base/loader/ecoff_object.cc | 2 +- src/base/loader/elf_object.cc | 2 +- src/base/loader/object_file.hh | 2 +- src/base/loader/symtab.cc | 2 +- src/base/logging.cc | 122 +++++++++++++++++++ src/base/logging.hh | 256 ++++++++++++++++++++++++++++++++++++++++ src/base/misc.cc | 122 ------------------- src/base/misc.hh | 256 ---------------------------------------- src/base/output.cc | 2 +- src/base/pngwriter.cc | 2 +- src/base/pollevent.cc | 2 +- src/base/random.cc | 2 +- src/base/socket.cc | 2 +- src/base/statistics.cc | 2 +- src/base/stats/text.cc | 2 +- src/base/time.cc | 2 +- src/base/trace.cc | 2 +- src/base/trie.hh | 2 +- src/base/vnc/vncinput.cc | 2 +- src/base/vnc/vncserver.cc | 2 +- 29 files changed, 405 insertions(+), 404 deletions(-) create mode 100644 src/base/logging.cc create mode 100644 src/base/logging.hh delete mode 100644 src/base/misc.cc delete mode 100644 src/base/misc.hh (limited to 'src/base') diff --git a/src/base/SConscript b/src/base/SConscript index 13c1ffff5..75759fd37 100644 --- a/src/base/SConscript +++ b/src/base/SConscript @@ -51,8 +51,8 @@ Source('hostinfo.cc') Source('inet.cc') Source('inifile.cc') Source('intmath.cc') +Source('logging.cc') Source('match.cc') -Source('misc.cc') Source('output.cc') Source('pollevent.cc') Source('random.cc') diff --git a/src/base/addr_range.hh b/src/base/addr_range.hh index ac1cbd05a..b243d68aa 100644 --- a/src/base/addr_range.hh +++ b/src/base/addr_range.hh @@ -50,7 +50,7 @@ #include "base/bitfield.hh" #include "base/cprintf.hh" -#include "base/misc.hh" +#include "base/logging.hh" #include "base/types.hh" /** diff --git a/src/base/bigint.hh b/src/base/bigint.hh index 2fa441a73..a078fdd65 100644 --- a/src/base/bigint.hh +++ b/src/base/bigint.hh @@ -30,7 +30,7 @@ #include -#include "base/misc.hh" +#include "base/logging.hh" #include "base/types.hh" #ifndef __BASE_BIGINT_HH__ diff --git a/src/base/bmpwriter.cc b/src/base/bmpwriter.cc index f650074ab..02245c09d 100644 --- a/src/base/bmpwriter.cc +++ b/src/base/bmpwriter.cc @@ -44,7 +44,7 @@ #include -#include "base/misc.hh" +#include "base/logging.hh" const char* BmpWriter::_imgExtension = "bmp"; diff --git a/src/base/circlebuf.hh b/src/base/circlebuf.hh index bf6f9e263..2c93daafc 100644 --- a/src/base/circlebuf.hh +++ b/src/base/circlebuf.hh @@ -44,7 +44,7 @@ #include #include -#include "base/misc.hh" +#include "base/logging.hh" #include "sim/serialize.hh" /** diff --git a/src/base/debug.cc b/src/base/debug.cc index 6be9cdff5..448268585 100644 --- a/src/base/debug.cc +++ b/src/base/debug.cc @@ -37,7 +37,7 @@ #include #include "base/cprintf.hh" -#include "base/misc.hh" +#include "base/logging.hh" using namespace std; diff --git a/src/base/hostinfo.cc b/src/base/hostinfo.cc index 43999a5e5..7ece35dd8 100644 --- a/src/base/hostinfo.cc +++ b/src/base/hostinfo.cc @@ -47,7 +47,7 @@ #include #include -#include "base/misc.hh" +#include "base/logging.hh" #include "base/str.hh" #include "base/types.hh" diff --git a/src/base/imgwriter.cc b/src/base/imgwriter.cc index ba9b58c02..40de3d7cc 100644 --- a/src/base/imgwriter.cc +++ b/src/base/imgwriter.cc @@ -38,13 +38,14 @@ */ #include "base/imgwriter.hh" -#include "base/bmpwriter.hh" -#include "base/misc.hh" +#include "base/bmpwriter.hh" +#include "base/logging.hh" #include "config/use_png.hh" #if USE_PNG #include "base/pngwriter.hh" + #endif std::unique_ptr diff --git a/src/base/intmath.hh b/src/base/intmath.hh index eded26d4a..0b22ba0db 100644 --- a/src/base/intmath.hh +++ b/src/base/intmath.hh @@ -33,7 +33,7 @@ #include -#include "base/misc.hh" +#include "base/logging.hh" #include "base/types.hh" // Returns the prime number one less than n. diff --git a/src/base/loader/ecoff_object.cc b/src/base/loader/ecoff_object.cc index 4e94ecd1e..caeab5f8f 100644 --- a/src/base/loader/ecoff_object.cc +++ b/src/base/loader/ecoff_object.cc @@ -33,7 +33,7 @@ #include #include "base/loader/symtab.hh" -#include "base/misc.hh" +#include "base/logging.hh" #include "base/trace.hh" #include "base/types.hh" #include "debug/Loader.hh" diff --git a/src/base/loader/elf_object.cc b/src/base/loader/elf_object.cc index fe43a7f01..60c79f803 100644 --- a/src/base/loader/elf_object.cc +++ b/src/base/loader/elf_object.cc @@ -54,7 +54,7 @@ #include "base/bitfield.hh" #include "base/loader/symtab.hh" -#include "base/misc.hh" +#include "base/logging.hh" #include "base/trace.hh" #include "debug/Loader.hh" #include "gelf.h" diff --git a/src/base/loader/object_file.hh b/src/base/loader/object_file.hh index 80ffa91f6..c2cdafe47 100644 --- a/src/base/loader/object_file.hh +++ b/src/base/loader/object_file.hh @@ -35,7 +35,7 @@ #include #include -#include "base/misc.hh" +#include "base/logging.hh" #include "base/types.hh" class PortProxy; diff --git a/src/base/loader/symtab.cc b/src/base/loader/symtab.cc index ea7332114..5c81c13e1 100644 --- a/src/base/loader/symtab.cc +++ b/src/base/loader/symtab.cc @@ -35,7 +35,7 @@ #include #include -#include "base/misc.hh" +#include "base/logging.hh" #include "base/str.hh" #include "base/types.hh" #include "sim/serialize.hh" diff --git a/src/base/logging.cc b/src/base/logging.cc new file mode 100644 index 000000000..cec9c8360 --- /dev/null +++ b/src/base/logging.cc @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2014, 2017 ARM Limited + * All rights reserved + * + * The license below extends only to copyright in the software and shall + * not be construed as granting a license to any other intellectual + * property including but not limited to intellectual property relating + * to a hardware implementation of the functionality of the software + * licensed hereunder. You may use the software subject to the license + * terms below provided that you ensure that this notice is replicated + * unmodified and in its entirety in all distributions of the software, + * modified or unmodified, in source code or in binary form. + * + * Copyright (c) 2002-2005 The Regents of The University of Michigan + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Authors: Nathan Binkert + * Andreas Sandberg + */ + +#include "base/logging.hh" + +#include + +#include "base/hostinfo.hh" +#include "base/output.hh" +#include "base/trace.hh" +#include "base/types.hh" +#include "sim/core.hh" + +void +Logger::setLevel(LogLevel ll) +{ + for (int i = 0; i < NUM_LOG_LEVELS; ++i) + get(LogLevel(i)).enabled = (i <= ll); +} + +static void +newline_if_needed(std::ostream &stream, const char *format) +{ + const size_t format_len(strlen(format)); + + switch (format_len ? format[format_len - 1] : '\0') { + case '\n': + case '\r': + break; + default: + stream << std::endl; + } +} + +Logger::Logger(std::ostream &_stream, const char *_prefix) + : enabled(true), verbose(false), stream(_stream), prefix(_prefix) +{ +} + +void +Logger::printEpilogue(const char *func, const char *file, int line, + const char *format) +{ + newline_if_needed(stream, format); + + if (verbose) { + ccprintf(stream, " @ tick %d\n[%s:%s, line %d]\n", + curTick(), func, file, line); + } +} + +class ExitLogger : public Logger +{ + public: + using Logger::Logger; + + void printEpilogue(const char *func, const char *file, int line, + const char *format) override; +}; + +void +ExitLogger::printEpilogue(const char *func, const char *file, int line, + const char *format) +{ + Logger::printEpilogue(func, file, line, format); + + ccprintf(stream, "Memory Usage: %ld KBytes\n", memUsage()); +} + +Logger & +Logger::get(LogLevel ll) +{ + static std::array loggers{{ + new ExitLogger(std::cerr, "panic"), + new ExitLogger(std::cerr, "fatal"), + new Logger(std::cerr, "warn"), + new Logger(std::cerr, "info"), + new Logger(std::cerr, "hack"), + }}; + + return *loggers[ll]; +} diff --git a/src/base/logging.hh b/src/base/logging.hh new file mode 100644 index 000000000..b0a9b0c1b --- /dev/null +++ b/src/base/logging.hh @@ -0,0 +1,256 @@ +/* + * Copyright (c) 2014, 2017 ARM Limited + * All rights reserved + * + * The license below extends only to copyright in the software and shall + * not be construed as granting a license to any other intellectual + * property including but not limited to intellectual property relating + * to a hardware implementation of the functionality of the software + * licensed hereunder. You may use the software subject to the license + * terms below provided that you ensure that this notice is replicated + * unmodified and in its entirety in all distributions of the software, + * modified or unmodified, in source code or in binary form. + * + * Copyright (c) 2002-2005 The Regents of The University of Michigan + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Authors: Nathan Binkert + * Dave Greene + * Andreas Sandberg + */ + +#ifndef __BASE_LOGGING_HH__ +#define __BASE_LOGGING_HH__ + +#include +#include +#include +#include + +#include "base/compiler.hh" +#include "base/cprintf.hh" + +#if defined(__SUNPRO_CC) +#define __FUNCTION__ "how to fix me?" +#endif + +class Logger +{ + public: + enum LogLevel { + PANIC = 0, + FATAL, + WARN, + INFO, + HACK, + NUM_LOG_LEVELS, + }; + + /** + * Set the active log level. + * + * All levels that are lower or equal to the selected log level + * will be activated. + * + * @param ll Maximum log level to print + */ + static void setLevel(LogLevel ll); + + /** + * Get a Logger corresponding to a specific log level + * + * @param ll Log level to access + * @return Reference to the requested logger + */ + static Logger &get(LogLevel ll); + + public: + Logger(std::ostream &stream, const char *prefix); + virtual ~Logger() {}; + + template void + print(const char *func, const char *file, int line, + const char *format, const Args &...args) + { + if (!enabled) + return; + + if (prefix) + stream << prefix << ": "; + ccprintf(stream, format, args...); + + printEpilogue(func, file, line, format); + } + + template void + print(const char *func, const char *file, int line, + const std::string &format, const Args &...args) + { + print(func, file, line, format.c_str(), args...); + } + + protected: + virtual void printEpilogue(const char *func, const char *file, int line, + const char *format); + + public: + bool enabled; + bool verbose; + + protected: + std::ostream &stream; + const char *prefix; +}; + +#define exit_message(logger, code, ...) \ + do { \ + logger.print(__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \ + if (code < 0) \ + ::abort(); \ + else \ + ::exit(code); \ + } while (0) + +// +// This implements a cprintf based panic() function. panic() should +// be called when something happens that should never ever happen +// regardless of what the user does (i.e., an acutal m5 bug). panic() +// calls abort which can dump core or enter the debugger. +// +// +#define panic(...) exit_message(::Logger::get(::Logger::PANIC), -1, \ + __VA_ARGS__) + +// +// This implements a cprintf based fatal() function. fatal() should +// be called when the simulation cannot continue due to some condition +// that is the user's fault (bad configuration, invalid arguments, +// etc.) and not a simulator bug. fatal() calls abort() like +// panic() does. +// +#define fatal(...) exit_message(::Logger::get(::Logger::FATAL), 1, \ + __VA_ARGS__) + +/** + * Conditional panic macro that checks the supplied condition and only panics + * if the condition is true and allows the programmer to specify diagnostic + * printout. Useful to replace if + panic, or if + print + assert, etc. + * + * @param cond Condition that is checked; if true -> panic + * @param ... Printf-based format string with arguments, extends printout. + */ +#define panic_if(cond, ...) \ + do { \ + if ((cond)) { \ + panic("panic condition " # cond " occurred: %s", \ + csprintf(__VA_ARGS__)); \ + } \ + } while (0) + + +/** + * Conditional fatal macro that checks the supplied condition and only causes a + * fatal error if the condition is true and allows the programmer to specify + * diagnostic printout. Useful to replace if + fatal, or if + print + assert, + * etc. + * + * @param cond Condition that is checked; if true -> fatal + * @param ... Printf-based format string with arguments, extends printout. + */ +#define fatal_if(cond, ...) \ + do { \ + if ((cond)) { \ + fatal("fatal condition " # cond " occurred: %s", \ + csprintf(__VA_ARGS__)); \ + } \ + } while (0) + + +#define base_message(logger, ...) \ + logger.print(__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__) + +// Only print the message the first time this expression is +// encountered. i.e. This doesn't check the string itself and +// prevent duplicate strings, this prevents the statement from +// happening more than once. So, even if the arguments change and that +// would have resulted in a different message thoes messages would be +// supressed. +#define base_message_once(...) do { \ + static bool once = false; \ + if (!once) { \ + base_message(__VA_ARGS__); \ + once = true; \ + } \ + } while (0) + + +#define warn(...) \ + base_message(::Logger::get(::Logger::WARN), __VA_ARGS__) +#define inform(...) \ + base_message(::Logger::get(::Logger::INFO), __VA_ARGS__) +#define hack(...) \ + base_message(::Logger::get(::Logger::HACK), __VA_ARGS__) + +#define warn_once(...) \ + base_message_once(::Logger::get(::Logger::WARN), __VA_ARGS__) +#define inform_once(...) \ + base_message_once(::Logger::get(::Logger::INFO), __VA_ARGS__) +#define hack_once(...) \ + base_message_once(::Logger::get(::Logger::HACK), __VA_ARGS__) + +/** + * Conditional warning macro that checks the supplied condition and + * only prints a warning if the condition is true. Useful to replace + * if + warn. + * + * @param cond Condition that is checked; if true -> warn + * @param ... Printf-based format string with arguments, extends printout. + */ +#define warn_if(cond, ...) \ + do { \ + if ((cond)) \ + warn(__VA_ARGS__); \ + } while (0) + +/** + * The chatty assert macro will function like a normal assert, but will allow + * the specification of additional, helpful material to aid debugging why the + * assertion actually failed. Like the normal assertion, the chatty_assert + * will not be active in fast builds. + * + * @param cond Condition that is checked; if false -> assert + * @param ... Printf-based format string with arguments, extends printout. + */ +#ifdef NDEBUG +#define chatty_assert(cond, ...) +#else //!NDEBUG +#define chatty_assert(cond, ...) \ + do { \ + if (!(cond)) \ + panic("assert(" # cond ") failed: %s", csprintf(__VA_ARGS__)); \ + } while (0) +#endif // NDEBUG +#endif // __BASE_LOGGING_HH__ diff --git a/src/base/misc.cc b/src/base/misc.cc deleted file mode 100644 index be97368f3..000000000 --- a/src/base/misc.cc +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2014, 2017 ARM Limited - * All rights reserved - * - * The license below extends only to copyright in the software and shall - * not be construed as granting a license to any other intellectual - * property including but not limited to intellectual property relating - * to a hardware implementation of the functionality of the software - * licensed hereunder. You may use the software subject to the license - * terms below provided that you ensure that this notice is replicated - * unmodified and in its entirety in all distributions of the software, - * modified or unmodified, in source code or in binary form. - * - * Copyright (c) 2002-2005 The Regents of The University of Michigan - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer; - * redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution; - * neither the name of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Authors: Nathan Binkert - * Andreas Sandberg - */ - -#include "base/misc.hh" - -#include - -#include "base/hostinfo.hh" -#include "base/output.hh" -#include "base/trace.hh" -#include "base/types.hh" -#include "sim/core.hh" - -void -Logger::setLevel(LogLevel ll) -{ - for (int i = 0; i < NUM_LOG_LEVELS; ++i) - get(LogLevel(i)).enabled = (i <= ll); -} - -static void -newline_if_needed(std::ostream &stream, const char *format) -{ - const size_t format_len(strlen(format)); - - switch (format_len ? format[format_len - 1] : '\0') { - case '\n': - case '\r': - break; - default: - stream << std::endl; - } -} - -Logger::Logger(std::ostream &_stream, const char *_prefix) - : enabled(true), verbose(false), stream(_stream), prefix(_prefix) -{ -} - -void -Logger::printEpilogue(const char *func, const char *file, int line, - const char *format) -{ - newline_if_needed(stream, format); - - if (verbose) { - ccprintf(stream, " @ tick %d\n[%s:%s, line %d]\n", - curTick(), func, file, line); - } -} - -class ExitLogger : public Logger -{ - public: - using Logger::Logger; - - void printEpilogue(const char *func, const char *file, int line, - const char *format) override; -}; - -void -ExitLogger::printEpilogue(const char *func, const char *file, int line, - const char *format) -{ - Logger::printEpilogue(func, file, line, format); - - ccprintf(stream, "Memory Usage: %ld KBytes\n", memUsage()); -} - -Logger & -Logger::get(LogLevel ll) -{ - static std::array loggers{{ - new ExitLogger(std::cerr, "panic"), - new ExitLogger(std::cerr, "fatal"), - new Logger(std::cerr, "warn"), - new Logger(std::cerr, "info"), - new Logger(std::cerr, "hack"), - }}; - - return *loggers[ll]; -} diff --git a/src/base/misc.hh b/src/base/misc.hh deleted file mode 100644 index 7b0d46274..000000000 --- a/src/base/misc.hh +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Copyright (c) 2014, 2017 ARM Limited - * All rights reserved - * - * The license below extends only to copyright in the software and shall - * not be construed as granting a license to any other intellectual - * property including but not limited to intellectual property relating - * to a hardware implementation of the functionality of the software - * licensed hereunder. You may use the software subject to the license - * terms below provided that you ensure that this notice is replicated - * unmodified and in its entirety in all distributions of the software, - * modified or unmodified, in source code or in binary form. - * - * Copyright (c) 2002-2005 The Regents of The University of Michigan - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer; - * redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution; - * neither the name of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Authors: Nathan Binkert - * Dave Greene - * Andreas Sandberg - */ - -#ifndef __BASE_MISC_HH__ -#define __BASE_MISC_HH__ - -#include -#include -#include -#include - -#include "base/compiler.hh" -#include "base/cprintf.hh" - -#if defined(__SUNPRO_CC) -#define __FUNCTION__ "how to fix me?" -#endif - -class Logger -{ - public: - enum LogLevel { - PANIC = 0, - FATAL, - WARN, - INFO, - HACK, - NUM_LOG_LEVELS, - }; - - /** - * Set the active log level. - * - * All levels that are lower or equal to the selected log level - * will be activated. - * - * @param ll Maximum log level to print - */ - static void setLevel(LogLevel ll); - - /** - * Get a Logger corresponding to a specific log level - * - * @param ll Log level to access - * @return Reference to the requested logger - */ - static Logger &get(LogLevel ll); - - public: - Logger(std::ostream &stream, const char *prefix); - virtual ~Logger() {}; - - template void - print(const char *func, const char *file, int line, - const char *format, const Args &...args) - { - if (!enabled) - return; - - if (prefix) - stream << prefix << ": "; - ccprintf(stream, format, args...); - - printEpilogue(func, file, line, format); - } - - template void - print(const char *func, const char *file, int line, - const std::string &format, const Args &...args) - { - print(func, file, line, format.c_str(), args...); - } - - protected: - virtual void printEpilogue(const char *func, const char *file, int line, - const char *format); - - public: - bool enabled; - bool verbose; - - protected: - std::ostream &stream; - const char *prefix; -}; - -#define exit_message(logger, code, ...) \ - do { \ - logger.print(__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \ - if (code < 0) \ - ::abort(); \ - else \ - ::exit(code); \ - } while (0) - -// -// This implements a cprintf based panic() function. panic() should -// be called when something happens that should never ever happen -// regardless of what the user does (i.e., an acutal m5 bug). panic() -// calls abort which can dump core or enter the debugger. -// -// -#define panic(...) exit_message(::Logger::get(::Logger::PANIC), -1, \ - __VA_ARGS__) - -// -// This implements a cprintf based fatal() function. fatal() should -// be called when the simulation cannot continue due to some condition -// that is the user's fault (bad configuration, invalid arguments, -// etc.) and not a simulator bug. fatal() calls abort() like -// panic() does. -// -#define fatal(...) exit_message(::Logger::get(::Logger::FATAL), 1, \ - __VA_ARGS__) - -/** - * Conditional panic macro that checks the supplied condition and only panics - * if the condition is true and allows the programmer to specify diagnostic - * printout. Useful to replace if + panic, or if + print + assert, etc. - * - * @param cond Condition that is checked; if true -> panic - * @param ... Printf-based format string with arguments, extends printout. - */ -#define panic_if(cond, ...) \ - do { \ - if ((cond)) { \ - panic("panic condition " # cond " occurred: %s", \ - csprintf(__VA_ARGS__)); \ - } \ - } while (0) - - -/** - * Conditional fatal macro that checks the supplied condition and only causes a - * fatal error if the condition is true and allows the programmer to specify - * diagnostic printout. Useful to replace if + fatal, or if + print + assert, - * etc. - * - * @param cond Condition that is checked; if true -> fatal - * @param ... Printf-based format string with arguments, extends printout. - */ -#define fatal_if(cond, ...) \ - do { \ - if ((cond)) { \ - fatal("fatal condition " # cond " occurred: %s", \ - csprintf(__VA_ARGS__)); \ - } \ - } while (0) - - -#define base_message(logger, ...) \ - logger.print(__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__) - -// Only print the message the first time this expression is -// encountered. i.e. This doesn't check the string itself and -// prevent duplicate strings, this prevents the statement from -// happening more than once. So, even if the arguments change and that -// would have resulted in a different message thoes messages would be -// supressed. -#define base_message_once(...) do { \ - static bool once = false; \ - if (!once) { \ - base_message(__VA_ARGS__); \ - once = true; \ - } \ - } while (0) - - -#define warn(...) \ - base_message(::Logger::get(::Logger::WARN), __VA_ARGS__) -#define inform(...) \ - base_message(::Logger::get(::Logger::INFO), __VA_ARGS__) -#define hack(...) \ - base_message(::Logger::get(::Logger::HACK), __VA_ARGS__) - -#define warn_once(...) \ - base_message_once(::Logger::get(::Logger::WARN), __VA_ARGS__) -#define inform_once(...) \ - base_message_once(::Logger::get(::Logger::INFO), __VA_ARGS__) -#define hack_once(...) \ - base_message_once(::Logger::get(::Logger::HACK), __VA_ARGS__) - -/** - * Conditional warning macro that checks the supplied condition and - * only prints a warning if the condition is true. Useful to replace - * if + warn. - * - * @param cond Condition that is checked; if true -> warn - * @param ... Printf-based format string with arguments, extends printout. - */ -#define warn_if(cond, ...) \ - do { \ - if ((cond)) \ - warn(__VA_ARGS__); \ - } while (0) - -/** - * The chatty assert macro will function like a normal assert, but will allow the - * specification of additional, helpful material to aid debugging why the - * assertion actually failed. Like the normal assertion, the chatty_assert - * will not be active in fast builds. - * - * @param cond Condition that is checked; if false -> assert - * @param ... Printf-based format string with arguments, extends printout. - */ -#ifdef NDEBUG -#define chatty_assert(cond, ...) -#else //!NDEBUG -#define chatty_assert(cond, ...) \ - do { \ - if (!(cond)) \ - panic("assert(" # cond ") failed: %s", csprintf(__VA_ARGS__)); \ - } while (0) -#endif // NDEBUG -#endif // __BASE_MISC_HH__ diff --git a/src/base/output.cc b/src/base/output.cc index dc85c2a54..48581c3fe 100644 --- a/src/base/output.cc +++ b/src/base/output.cc @@ -58,7 +58,7 @@ #include #include -#include "base/misc.hh" +#include "base/logging.hh" using namespace std; diff --git a/src/base/pngwriter.cc b/src/base/pngwriter.cc index 3b49d479d..3251ac885 100644 --- a/src/base/pngwriter.cc +++ b/src/base/pngwriter.cc @@ -51,7 +51,7 @@ extern "C" #include #include -#include "base/misc.hh" +#include "base/logging.hh" const char* PngWriter::_imgExtension = "png"; diff --git a/src/base/pollevent.cc b/src/base/pollevent.cc index 79814e077..2101f8d71 100644 --- a/src/base/pollevent.cc +++ b/src/base/pollevent.cc @@ -45,7 +45,7 @@ #include #include -#include "base/misc.hh" +#include "base/logging.hh" #include "base/types.hh" #include "sim/async.hh" #include "sim/core.hh" diff --git a/src/base/random.cc b/src/base/random.cc index 0121581d6..1c6b1cb4a 100644 --- a/src/base/random.cc +++ b/src/base/random.cc @@ -46,7 +46,7 @@ #include -#include "base/misc.hh" +#include "base/logging.hh" #include "sim/serialize.hh" Random::Random() diff --git a/src/base/socket.cc b/src/base/socket.cc index a09b51fb2..ece4a6ac4 100644 --- a/src/base/socket.cc +++ b/src/base/socket.cc @@ -38,7 +38,7 @@ #include -#include "base/misc.hh" +#include "base/logging.hh" #include "base/types.hh" #include "sim/byteswap.hh" diff --git a/src/base/statistics.cc b/src/base/statistics.cc index 96747f0a9..123351b80 100644 --- a/src/base/statistics.cc +++ b/src/base/statistics.cc @@ -40,7 +40,7 @@ #include "base/cprintf.hh" #include "base/debug.hh" #include "base/hostinfo.hh" -#include "base/misc.hh" +#include "base/logging.hh" #include "base/str.hh" #include "base/time.hh" #include "base/trace.hh" diff --git a/src/base/stats/text.cc b/src/base/stats/text.cc index 9403ed3ff..10e94a770 100644 --- a/src/base/stats/text.cc +++ b/src/base/stats/text.cc @@ -52,7 +52,7 @@ #include #include "base/cast.hh" -#include "base/misc.hh" +#include "base/logging.hh" #include "base/stats/info.hh" #include "base/str.hh" diff --git a/src/base/time.cc b/src/base/time.cc index 5509bccaf..6e9d7ccfb 100644 --- a/src/base/time.cc +++ b/src/base/time.cc @@ -35,7 +35,7 @@ #include #include -#include "base/misc.hh" +#include "base/logging.hh" #include "config/use_posix_clock.hh" #include "sim/core.hh" #include "sim/serialize.hh" diff --git a/src/base/trace.cc b/src/base/trace.cc index dfd99686a..06f9eeb21 100644 --- a/src/base/trace.cc +++ b/src/base/trace.cc @@ -42,7 +42,7 @@ #include #include "base/debug.hh" -#include "base/misc.hh" +#include "base/logging.hh" #include "base/output.hh" #include "base/str.hh" diff --git a/src/base/trie.hh b/src/base/trie.hh index 1d110b4e1..e256377c1 100644 --- a/src/base/trie.hh +++ b/src/base/trie.hh @@ -34,7 +34,7 @@ #include #include "base/cprintf.hh" -#include "base/misc.hh" +#include "base/logging.hh" #include "base/types.hh" // Key has to be an integral type. diff --git a/src/base/vnc/vncinput.cc b/src/base/vnc/vncinput.cc index b9d1d2546..da3c913b2 100644 --- a/src/base/vnc/vncinput.cc +++ b/src/base/vnc/vncinput.cc @@ -46,7 +46,7 @@ #include -#include "base/misc.hh" +#include "base/logging.hh" #include "base/output.hh" #include "base/trace.hh" diff --git a/src/base/vnc/vncserver.cc b/src/base/vnc/vncserver.cc index 00ff5602f..97515ac16 100644 --- a/src/base/vnc/vncserver.cc +++ b/src/base/vnc/vncserver.cc @@ -64,7 +64,7 @@ #include #include "base/atomicio.hh" -#include "base/misc.hh" +#include "base/logging.hh" #include "base/output.hh" #include "base/socket.hh" #include "base/trace.hh" -- cgit v1.2.3