Updated all logging to use new macro's

Removed DbgFunc* variadic macro's.
This commit is contained in:
PatrickvL 2016-11-10 23:57:21 +01:00
parent b379ca30da
commit 21ac7bc71d
3 changed files with 454 additions and 440 deletions

View File

@ -107,10 +107,20 @@ extern thread_local std::string _logPrefix;
// TODO :
// LPCSTR
// PLARGE_INTEGER
// PULONG value, *value
// POBJECT_ATTRIBUTES ->ObjectName->Buffer
// PVOID * value, *value
// PLARGE_INTEGER ->QuadPart
// LARGE_INTEGER.QuadPart
// PXDEVICE_PREALLOC_TYPE
// PXPP_DEVICE_TYPE
// PXINPUT_CAPABILITIES
// PXINPUT_STATE
// PXTHREAD_NOTIFICATION -> pfnNotifyRoutine
// PMM_STATISTICS->Length
// PIO_STATUS_BLOCK ->u1.Pointer, ->Information
// PUNICODE_STRING
// PSTRING (value != 0) ? value->Buffer : ""
// UCHAR
#endif _LOGGING_H

View File

@ -113,95 +113,4 @@ extern volatile bool g_bPrintfOn;
// MSVC_EXPAND works around a Visual C++ problem, expanding __VA_ARGS__ incorrectly:
#define MSVC_EXPAND( x ) x
// From https://codecraft.co/2014/11/25/variadic-macros-tricks/
// And https://groups.google.com/d/msg/comp.std.c/d-6Mj5Lko_s/jqonQLK20HcJ
// Accept any number of args >= N, but expand to just the Nth one. In this case,
// we have settled on 10 as N. We could pick a different number by adjusting
// the count of throwaway args before N. Note that this macro is preceded by
// an underscore--it's an implementation detail, not something we expect people
// to call directly.
#define _GET_NTH_ARG( \
_19, _18, _17, _16, _15, _14, _13, _12, _11, _10, \
_9, _8, _7, _6, _5, _4, _3, _2, _1, _0, \
N, ...) N
// COUNT_VARARGS returns the number of arguments that have been passed to it.
// Count how many args are in a variadic macro. We now use GCC/Clang's extension to
// handle the case where ... expands to nothing. We must add a placeholder arg before
// ##__VA_ARGS__ (its value is totally irrelevant, but it's necessary to preserve
// the shifting offset we want). In addition, we must add 0 as a valid value to be in
// the N position.
#define COUNT_VARARGS(...) MSVC_EXPAND(_GET_NTH_ARG("ignored", ##__VA_ARGS__, \
19, 18, 17, 16, 15, 14, 13, 12, 11, 10, \
9, 8, 7, 6, 5, 4, 3, 2, 1, 0) )
// Define some macros to help us create overrides based on the
// arity of a for-each-style macro.
#define _fe_0(_call, ...)
#define _fe_1(_call, x) _call(x)
#define _fe_2(_call, x, ...) _call(x) _fe_1(_call, __VA_ARGS__)
#define _fe_3(_call, x, ...) _call(x) _fe_2(_call, __VA_ARGS__)
#define _fe_4(_call, x, ...) _call(x) _fe_3(_call, __VA_ARGS__)
#define _fe_5(_call, x, ...) _call(x) _fe_4(_call, __VA_ARGS__)
#define _fe_6(_call, x, ...) _call(x) _fe_5(_call, __VA_ARGS__)
#define _fe_7(_call, x, ...) _call(x) _fe_6(_call, __VA_ARGS__)
#define _fe_8(_call, x, ...) _call(x) _fe_7(_call, __VA_ARGS__)
#define _fe_9(_call, x, ...) _call(x) _fe_8(_call, __VA_ARGS__)
#define _fe_10(_call, x, ...) _call(x) _fe_9(_call, __VA_ARGS__)
#define _fe_11(_call, x, ...) _call(x) _fe_10(_call, __VA_ARGS__)
#define _fe_12(_call, x, ...) _call(x) _fe_11(_call, __VA_ARGS__)
#define _fe_13(_call, x, ...) _call(x) _fe_12(_call, __VA_ARGS__)
#define _fe_14(_call, x, ...) _call(x) _fe_13(_call, __VA_ARGS__)
#define _fe_15(_call, x, ...) _call(x) _fe_14(_call, __VA_ARGS__)
#define _fe_16(_call, x, ...) _call(x) _fe_15(_call, __VA_ARGS__)
#define _fe_17(_call, x, ...) _call(x) _fe_16(_call, __VA_ARGS__)
#define _fe_18(_call, x, ...) _call(x) _fe_17(_call, __VA_ARGS__)
#define _fe_19(_call, x, ...) _call(x) _fe_18(_call, __VA_ARGS__)
/**
* Provide a for-each construct for variadic macros. Supports up
* to 10 args.
*
* Example usage1:
* #define FWD_DECLARE_CLASS(cls) class cls;
* CALL_MACRO_X_FOR_EACH(FWD_DECLARE_CLASS, Foo, Bar)
*
* Example usage 2:
* #define START_NS(ns) namespace ns {
* #define END_NS(ns) }
* #define MY_NAMESPACES System, Net, Http
* CALL_MACRO_X_FOR_EACH(START_NS, MY_NAMESPACES)
* typedef foo int;
* CALL_MACRO_X_FOR_EACH(END_NS, MY_NAMESPACES)
*/
#define CALL_MACRO_X_FOR_EACH(x, ...) MSVC_EXPAND(_GET_NTH_ARG("ignored", ##__VA_ARGS__, \
_fe_19, _fe_18,_fe_17,_fe_16,_fe_15,_fe_14,_fe_13,_fe_12,_fe_11,_fe_10, \
_fe_9, _fe_8, _fe_7, _fe_6, _fe_5, _fe_4, _fe_3, _fe_2, _fe_1, _fe_0)(x, ##__VA_ARGS__))
#define DBG_ARG_WIDTH 18
#define DbgPrintHexArg(arg) printf("\n %*s : 0x%.08X", DBG_ARG_WIDTH, #arg, arg);
// See https://gcc.gnu.org/onlinedocs/gcc/Variadic-Macros.html
// TODO : change multiple printf calls into 1, to avoid mixing output of multiple threads
// perhaps via http://stackoverflow.com/a/2342176/12170
#define DbgFuncHexArgs(...) do { if (_DEBUG_TRACE) if(g_bPrintfOn) \
printf("%s (0x%X): %s(", __FILENAME__, GetCurrentThreadId(), __func__); \
if (COUNT_VARARGS(##__VA_ARGS__) > 0) { \
} \
printf(");\n"); \
} while (0)
/* TODO : Get this going inside DbgFuncHexArgs :
CALL_MACRO_X_FOR_EACH(DbgPrintHexArg, __VA_ARGS__); \
printf("\n"); \
*/
// See https://gcc.gnu.org/onlinedocs/gcc/Variadic-Macros.html
// See http://stackoverflow.com/questions/1644868/c-define-macro-for-debug-printing
#define DbgFuncFmtArgs(fmt, ...) \
do { if (_DEBUG_TRACE) if(g_bPrintfOn) \
printf("%s (0x%X): %s(\n" fmt ");\n", __FILENAME__, GetCurrentThreadId(), __func__, __VA_ARGS__); \
} while (0)
#endif

File diff suppressed because it is too large Load Diff