Small cleanuo, macro's not fully functional yet

This commit is contained in:
PatrickvL 2016-11-08 00:45:40 +01:00
parent 966745cfe6
commit 1e15027bd0
4 changed files with 21 additions and 17 deletions

View File

@ -70,7 +70,7 @@ typedef signed long sint32;
#endif
/*! define this to trace intercepted function calls */
#ifdef _DEBUG
#define _DEBUG_TRACE
#define _DEBUG_TRACE 1
#endif
/*! define this to trace warnings */
#define _DEBUG_WARNINGS
@ -82,6 +82,8 @@ typedef signed long sint32;
/*! define this to dump textures that are registered */
//#define _DEBUG_DUMP_TEXTURE_REGISTER "D:\\cxbx\\_textures\\"
#include "Version.h"
/*! version string dependent on trace flag */
#ifndef _DEBUG_TRACE
#define _CXBX_VERSION _GIT_VERSION " ("__DATE__ ")"
@ -103,7 +105,7 @@ extern volatile bool g_bPrintfOn;
#endif
/*! DbgPrintf enabled if _DEBUG_TRACE is set */
#define DbgPrintf(fmt, ...) do { if (_DEBUG_TRACE) if(g_bPrintfOn) printf(fmt, ## __VA_ARGS__); } while (0)
#define DbgPrintf(fmt, ...) do { if (_DEBUG_TRACE) if(g_bPrintfOn) printf(fmt, ##__VA_ARGS__); } while (0)
// From https://codecraft.co/2014/11/25/variadic-macros-tricks/
// And https://groups.google.com/d/msg/comp.std.c/d-6Mj5Lko_s/jqonQLK20HcJ
@ -113,7 +115,7 @@ extern volatile bool g_bPrintfOn;
// 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(\
#define _GET_NTH_ARG( \
_01,_02,_03,_04,_05,_06,_07,_08,_09,_10, \
_11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
_21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
@ -121,7 +123,7 @@ extern volatile bool g_bPrintfOn;
_41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
_51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
_61,_62,_63,N,...) N
#define __RSEQ_N() \
62, 61, 60, \
59, 58, 57, 56, 55, 54, 53, 52, 51, 50, \
@ -137,7 +139,7 @@ extern volatile bool g_bPrintfOn;
// ##__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(...) (_GET_NTH_ARG(_00, ##__VA_ARGS__, __RSEQ_N()))
#define COUNT_VARARGS(...) (_GET_NTH_ARG(_00, ##__VA_ARGS__, __RSEQ_N()))
// Define some macros to help us create overrides based on the
// arity of a for-each-style macro.
@ -180,20 +182,21 @@ extern volatile bool g_bPrintfOn;
#define DbgPrintHexArg(arg) printf("\n %*s : 0x%.08X", DBG_ARG_WIDTH, #arg, arg);
// See https://gcc.gnu.org/onlinedocs/gcc/Variadic-Macros.html
// See https://gcc.gnu.org/onlinedocs/gcc/Variadic-Macros.html
#define DbgFuncHexArgs(...) do { if (_DEBUG_TRACE) if(g_bPrintfOn) \
printf(__FILE__ " (0x%X): " __func__ "(", GetCurrentThreadID()); \
printf("%s (0x%X): %s(", __FILE__, GetCurrentThreadId(), __func__); \
if (COUNT_VARARGS(##__VA_ARGS__) > 0) { \
CALL_MACRO_X_FOR_EACH(DbgPrintHexArg, ##__VA_ARGS__); \
CALL_MACRO_X_FOR_EACH(DbgPrintHexArg, __VA_ARGS__); \
printf("\n"); \
} \
printf(");\n"); \
} while (0)
// 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(__FILE__ " (0x%X): " __func__ "(" fmt ");\n", GetCurrentThreadID(), __VA_ARGS__); \
printf("%s (0x%X): %s(" fmt ");\n", __FILE__, GetCurrentThreadId(), __func__, __VA_ARGS__); \
} while (0)
#endif

View File

@ -2377,12 +2377,13 @@ HRESULT WINAPI XTL::EmuIDirectSoundBuffer8_SetMaxDistance
DWORD dwApply
)
{
DbgPrintf("EmuDSound (0x%X): EmuIDirectSoundBuffer8_SetMaxDistance\n"
"(\n"
" pThis : 0x%.08X\n"
" flMaxDistance : %f\n"
" dwApply : 0x%.08X\n"
");\n",
DbgPrintf("EmuDSound (0x%X): EmuIDirectSoundBuffer8_SetMaxDistance\n"
"(\n"
" pThis : 0x%.08X\n"
" flMaxDistance : %f\n"
" dwApply : 0x%.08X\n"
");\n",
GetCurrentThreadId(), pThis, flMaxDistance, dwApply);
// TODO: Actually do something

View File

@ -2523,7 +2523,7 @@ XBSYSAPI EXPORTNUM(181) xboxkrnl::NTSTATUS NTAPI xboxkrnl::MmQueryStatistics
DbgFuncFmtArgs(
" MemoryStatistics : 0x%.08X (MemoryStatistics->Length = 0x%.08X)\n"
" MemoryStatistics : 0x%.08X (MemoryStatistics->Length = 0x%.08X)\n",
MemoryStatistics, MemoryStatistics->Length);
MEMORYSTATUS MemoryStatus;

View File

@ -661,7 +661,7 @@ VOID WINAPI XTL::EmuXapiThreadStartup
DWORD dwDummy2
)
{
DbgDbgFuncNewFuncArgs(dwDummy1, dwDummy2);
DbgFuncHexArgs(dwDummy1, dwDummy2);
typedef int (__stdcall *pfDummyFunc)(DWORD dwDummy);