41#ifndef __BASE_LOGGING_HH__
42#define __BASE_LOGGING_HH__
97 template<
typename ...Args>
void
100 std::stringstream
ss;
102 const std::string str =
ss.str();
104 std::stringstream ss_formatted;
105 ss_formatted <<
prefix << str;
106 if (str.length() && str.back() !=
'\n' && str.back() !=
'\r')
107 ss_formatted << std::endl;
110 log(loc, ss_formatted.str());
113 template<
typename ...Args>
void
133 std::cerr << loc.
file <<
":" << loc.
line <<
": " <<
s;
141#define base_message(logger, ...) \
142 [&log = logger](const auto&... args) { \
143 log.print(::gem5::Logger::Loc(__FILE__, __LINE__), args...); \
154#define base_message_once(logger, ...) \
155 [&log = logger](const auto&... args) { \
156 static bool once{false}; \
157 if (GEM5_UNLIKELY(!once)) { \
159 base_message(log, args...); \
170#define exit_message(logger, ...) \
172 [&log = logger](const auto&... args) { \
173 base_message(log, args...); \
175 logger.exit_helper() \
188#define panic(...) exit_message(::gem5::Logger::getPanic(), __VA_ARGS__)
200#define fatal(...) exit_message(::gem5::Logger::getFatal(), __VA_ARGS__)
214#define panic_if(cond, ...) \
216 GEM5_UNLIKELY(static_cast<bool>(cond)) ? \
217 panic("panic condition " # cond " occurred: %s", \
218 ::gem5::csprintf(__VA_ARGS__)) : \
236#define fatal_if(cond, ...) \
238 GEM5_UNLIKELY(static_cast<bool>(cond)) ? \
239 fatal("fatal condition " # cond " occurred: %s", \
240 ::gem5::csprintf(__VA_ARGS__)) : \
256#define warn(...) base_message(::gem5::Logger::getWarn(), __VA_ARGS__)
257#define inform(...) base_message(::gem5::Logger::getInfo(), __VA_ARGS__)
258#define hack(...) base_message(::gem5::Logger::getHack(), __VA_ARGS__)
260#define warn_once(...) \
261 base_message_once(::gem5::Logger::getWarn(), __VA_ARGS__)
262#define inform_once(...) \
263 base_message_once(::gem5::Logger::getInfo(), __VA_ARGS__)
264#define hack_once(...) \
265 base_message_once(::gem5::Logger::getHack(), __VA_ARGS__)
283#define warn_if(cond, ...) \
285 static_cast<bool>(cond) ? \
286 warn(__VA_ARGS__) : \
290#define warn_if_once(cond, ...) \
292 static_cast<bool>(cond) ? \
293 warn_once(__VA_ARGS__) : \
300#define NDEBUG_DEFINED 1
302#define NDEBUG_DEFINED 0
317#define gem5_assert(cond, ...) \
319 GEM5_UNLIKELY(NDEBUG_DEFINED || static_cast<bool>(cond)) ? \
321 [](const auto&... args) { \
323 if constexpr (sizeof...(args) == 0) return ""; \
324 else return std::string(": ") + csprintf(args...); \
326 panic("assert(" #cond ") failed%s", msg()); \
332#define chatty_assert(...) \
334 gem5_assert(args...), \
335 GEM5_DEPRECATED_MACRO(chatty_assert, {}, "Please use gem5_assert()") \
virtual void log(const Loc &loc, std::string s)
Generates the log message.
static Logger & getWarn()
Logger(const char *prefix)
void print(const Loc &loc, const std::string &format, const Args &...args)
static Logger & getInfo()
static Logger & getHack()
void print(const Loc &loc, const char *format, const Args &...args)
static Logger & getPanic()
Get a Logger for the specified type of message.
void exit_helper()
This helper is necessary since noreturn isn't inherited by virtual functions, and gcc will get mad if...
static Logger & getFatal()
static void setLevel(LogLevel ll)
Bitfield< 31, 29 > format
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
void ccprintf(cp::Print &print)
Loc(const char *file, int line)