Changeset - r25654:e264fd698eb2
[Not reviewed]
master
0 3 0
rubidium42 - 3 years ago 2021-06-11 19:17:07
rubidium@openttd.org
Codechange: use the fmt library for simpler debug formats
3 files changed with 15 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/debug.cpp
Show inline comments
 
@@ -100,13 +100,13 @@ char *DumpDebugFacilityNames(char *buf, 
 

	
 
/**
 
 * Internal function for outputting the debug line.
 
 * @param dbg Debug category.
 
 * @param buf Text line to output.
 
 */
 
static void debug_print(const char *dbg, const char *buf)
 
void debug_print(const char *dbg, const char *buf)
 
{
 
	if (_debug_socket != INVALID_SOCKET) {
 
		char buf2[1024 + 32];
 

	
 
		seprintf(buf2, lastof(buf2), "%sdbg: [%s] %s\n", GetLogPrefix(), dbg, buf);
 
		/* Sending out an error when this fails would be nice, however... the error
src/debug.h
Show inline comments
 
@@ -9,12 +9,13 @@
 

	
 
#ifndef DEBUG_H
 
#define DEBUG_H
 

	
 
#include "cpu.h"
 
#include <chrono>
 
#include "3rdparty/fmt/format.h"
 

	
 
/* Debugging messages policy:
 
 * These should be the severities used for direct DEBUG() calls
 
 * maximum debugging level should be 10 if really deep, deep
 
 * debugging is needed.
 
 * (there is room for exceptions, but you have to have a good cause):
 
@@ -24,12 +25,22 @@
 
 * 3   - important debugging messages (function entry)
 
 * 4   - debugging messages (crude loop status, etc.)
 
 * 5   - detailed debugging information
 
 * 6.. - extremely detailed spamming
 
 */
 

	
 
void debug_print(const char *dbg, const char *buf);
 

	
 
/**
 
 * Ouptut a line of debugging information.
 
 * @param name The category of debug information.
 
 * @param level The maximum debug level this message should be shown at. When the debug level for this category is set lower, then the message will not be shown.
 
 * @param format_string The formatting string of the message.
 
 */
 
#define Debug(name, level, format_string, ...) if ((level) == 0 || _debug_ ## name ## _level >= (level)) debug_print(#name, fmt::format(FMT_STRING(format_string), ## __VA_ARGS__).c_str())
 

	
 
/**
 
 * Output a line of debugging information.
 
 * @param name Category
 
 * @param level Debugging level, higher levels means more detailed information.
 
 */
 
#define DEBUG(name, level, ...) if ((level) == 0 || _debug_ ## name ## _level >= (level)) debug(#name, __VA_ARGS__)
src/stdafx.h
Show inline comments
 
@@ -422,12 +422,15 @@ static_assert(SIZE_MAX >= UINT32_MAX);
 
#	define unlikely(x) __builtin_expect(!!(x), 0)
 
#else
 
#	define likely(x)   (x)
 
#	define unlikely(x) (x)
 
#endif /* __GNUC__ || __clang__ */
 

	
 
/* For the FMT library we only want to use the headers, not link to some library. */
 
#define FMT_HEADER_ONLY
 

	
 
void NORETURN CDECL usererror(const char *str, ...) WARN_FORMAT(1, 2);
 
void NORETURN CDECL error(const char *str, ...) WARN_FORMAT(1, 2);
 
#define NOT_REACHED() error("NOT_REACHED triggered at line %i of %s", __LINE__, __FILE__)
 

	
 
/* For non-debug builds with assertions enabled use the special assertion handler. */
 
#if defined(NDEBUG) && defined(WITH_ASSERT)
0 comments (0 inline, 0 general)