From a6159a640f09bc2628005b588340773a316969cf Mon Sep 17 00:00:00 2001 From: Jonathan Marler Date: Wed, 10 Oct 2018 15:03:37 -0600 Subject: [PATCH] Remove obslete DBG_printf_gcc, all compilers now support DBG_printf_c99 (#20338) --- src/pal/src/include/pal/dbgmsg.h | 127 +++++------------------------------ src/pal/src/misc/dbgmsg.cpp | 138 +++++---------------------------------- 2 files changed, 32 insertions(+), 233 deletions(-) diff --git a/src/pal/src/include/pal/dbgmsg.h b/src/pal/src/include/pal/dbgmsg.h index 052c6fa..63b3c89 100644 --- a/src/pal/src/include/pal/dbgmsg.h +++ b/src/pal/src/include/pal/dbgmsg.h @@ -322,32 +322,20 @@ bool DBG_ShouldCheckStackAlignment(); BOOL __bHeader = bHeader;\ DBG_PRINTF2 -#ifdef __GNUC__ -#define DBG_PRINTF2(args...)\ - DBG_printf_gcc(__chanid,__levid,__bHeader,__FUNCTION__,__FILE__,\ - __LINE__,args);\ - }\ -} -#else /* __GNUC__ */ #define DBG_PRINTF2(...)\ - DBG_printf_c99(__chanid,__levid,__bHeader,__FILE__,__LINE__,__VA_ARGS__);\ + DBG_printf(__chanid,__levid,__bHeader,__FUNCTION__,__FILE__,__LINE__,__VA_ARGS__);\ }\ } -#endif /* __GNUC__ */ #endif /* _ENABLE_DEBUG_MESSAGES_ */ -/* Use GNU C-specific features if available : __FUNCTION__ pseudo-macro, - variable-argument macros */ -#ifdef __GNUC__ - /* define NOTRACE as nothing; this will absorb the variable-argument list used in tracing macros */ -#define NOTRACE(args...) +#define NOTRACE(...) #if defined(__cplusplus) && defined(FEATURE_PAL_SXS) #define __ASSERT_ENTER() \ - /* DBG_printf_gcc() and DebugBreak() need a PAL thread */ \ + /* DBG_printf_c99() and DebugBreak() need a PAL thread */ \ PAL_EnterHolder __holder(PALIsThreadDataInitialized() && \ (CorUnix::InternalGetCurrentThread() == NULL || \ !CorUnix::InternalGetCurrentThread()->IsInPal())); @@ -357,49 +345,6 @@ bool DBG_ShouldCheckStackAlignment(); #if !defined(_DEBUG) -#define ASSERT(args...) -#define _ASSERT(expr) -#define _ASSERTE(expr) -#define _ASSERT_MSG(args...) - -#else /* defined(_DEBUG) */ - -#define ASSERT(args...) \ -{ \ - __ASSERT_ENTER(); \ - if (output_file && dbg_master_switch) \ - { \ - DBG_printf_gcc(defdbgchan,DLI_ASSERT,TRUE,__FUNCTION__,__FILE__,__LINE__,args); \ - } \ - if (g_Dbg_asserts_enabled) \ - { \ - DebugBreak(); \ - } \ -} - -#define _ASSERT(expr) do { if (!(expr)) { ASSERT(""); } } while(0) -#define _ASSERTE(expr) do { if (!(expr)) { ASSERT("Expression: " #expr "\n"); } } while(0) -#define _ASSERT_MSG(expr, args...) \ - do { \ - if (!(expr)) \ - { \ - ASSERT("Expression: " #expr ", Description: " args); \ - } \ - } while(0) - -#endif /* defined(_DEBUG) */ - -#else /* __GNUC__ */ -/* Not GNU C : C99 [the latest version of the ISO C Standard] specifies - a different syntax for variable-argument macros, so try using that*/ -#if defined __STDC_VERSION__ && __STDC_VERSION__ >=199901L - -/* define NOTRACE as nothing; this will absorb the variable-argument list used - in tracing macros */ -#define NOTRACE(...) - -#if !defined(_DEBUG) - #define ASSERT(...) #define _ASSERT(expr) #define _ASSERTE(expr) @@ -412,11 +357,10 @@ bool DBG_ShouldCheckStackAlignment(); __ASSERT_ENTER(); \ if (output_file && dbg_master_switch) \ { \ - DBG_printf_c99(defdbgchan,DLI_ASSERT,TRUE,__FILE__,__LINE__,__VA_ARGS__); \ + DBG_printf(defdbgchan,DLI_ASSERT,TRUE,__FUNCTION__,__FILE__,__LINE__,__VA_ARGS__); \ } \ if(g_Dbg_asserts_enabled) \ { \ - PAL_Leave(); \ DebugBreak(); \ } \ } @@ -433,17 +377,6 @@ bool DBG_ShouldCheckStackAlignment(); #endif /* !_DEBUG */ -#else /* __STDC_VERSION__ */ -/* Not GNU C, not C99 : - possible work around for the lack of variable-argument macros: - by using 2 function calls; must wrap the whole thing in a critical - section to avoid interleaved output from multiple threads */ - -#error The compiler is missing support for variable-argument macros. - -#endif /* __STDC_VERSION__*/ -#endif /* __GNUC__ */ - /* Function declarations */ /*++ @@ -496,68 +429,42 @@ BOOL DBG_preprintf(DBG_CHANNEL_ID channel, DBG_LEVEL_ID level, BOOL bHeader, /*++ Function : - DBG_printf_gcc + DBG_printf Internal function for debug channels; don't use. - This function outputs a complete debug message, including the function name. + This function outputs a complete debug message, without function name. Parameters : DBG_CHANNEL_ID channel : debug channel to use DBG_LEVEL_ID level : debug message level BOOL bHeader : whether or not to output message header (thread id, etc) - LPSTR function : current function - LPSTR file : current file + LPCSTR function : current function + LPCSTR file : current file INT line : line number - LPSTR format, ... : standard printf parameter list. + LPCSTR format, ... : standard printf parameter list. Return Value : always 1. Notes : - This version is for gnu compilers that support variable-argument macros - and the __FUNCTION__ pseudo-macro. + This function requires that the compiler support the C99 flavor of + variable-argument macros, and that they support the __FUNCTION__ + pseudo-macro. --*/ #if __GNUC__ && CHECK_TRACE_SPECIFIERS /* if requested, use an __attribute__ feature to ask gcc to check that format specifiers match their parameters */ -int DBG_printf_gcc(DBG_CHANNEL_ID channel, DBG_LEVEL_ID level, BOOL bHeader, - LPCSTR function, LPCSTR file, INT line, LPCSTR format, ...) - __attribute__ ((format (printf,7, 8))); +int DBG_printf(DBG_CHANNEL_ID channel, DBG_LEVEL_ID level, BOOL bHeader, + LPCSTR function, LPCSTR file, INT line, LPCSTR format, ...) + __attribute__ ((format (printf,7, 8))); #else -int DBG_printf_gcc(DBG_CHANNEL_ID channel, DBG_LEVEL_ID level, BOOL bHeader, - LPCSTR function, LPCSTR file, INT line, LPCSTR format, ...); +int DBG_printf(DBG_CHANNEL_ID channel, DBG_LEVEL_ID level, BOOL bHeader, + LPCSTR function, LPCSTR file, INT line, LPCSTR format, ...); #endif /*++ Function : - DBG_printf_c99 - - Internal function for debug channels; don't use. - This function outputs a complete debug message, without function name. - -Parameters : - DBG_CHANNEL_ID channel : debug channel to use - DBG_LEVEL_ID level : debug message level - BOOL bHeader : whether or not to output message header (thread id, etc) - LPSTR file : current file - INT line : line number - LPSTR format, ... : standard printf parameter list. - -Return Value : - always 1. - -Notes : - This version is for compilers that support the C99 flavor of - variable-argument macros but not the gnu flavor, and do not support the - __FUNCTION__ pseudo-macro. - ---*/ -int DBG_printf_c99(DBG_CHANNEL_ID channel, DBG_LEVEL_ID level, BOOL bHeader, - LPSTR file, INT line, LPSTR format, ...); - -/*++ -Function : DBG_printf_plain Internal function for debug channels; don't use. diff --git a/src/pal/src/misc/dbgmsg.cpp b/src/pal/src/misc/dbgmsg.cpp index d9bb40e..f130d6b 100644 --- a/src/pal/src/misc/dbgmsg.cpp +++ b/src/pal/src/misc/dbgmsg.cpp @@ -442,10 +442,9 @@ static const void *DBG_get_module_id() #define MODULE_FORMAT #endif // FEATURE_PAL_SXS - /*++ Function : - DBG_printf_gcc + DBG_printf Internal function for debug channels; don't use. This function outputs a complete debug message, including the function name. @@ -454,21 +453,22 @@ Parameters : DBG_CHANNEL_ID channel : debug channel to use DBG_LEVEL_ID level : debug message level BOOL bHeader : whether or not to output message header (thread id, etc) - LPSTR function : current function - LPSTR file : current file + LPCSTR function : current function + LPCSTR file : current file INT line : line number - LPSTR format, ... : standard printf parameter list. + LPCSTR format, ... : standard printf parameter list. Return Value : always 1. Notes : - This version is for gnu compilers that support variable-argument macros - and the __FUNCTION__ pseudo-macro. + This version is for compilers that support the C99 flavor of + variable-argument macros but not the gnu flavor, and do not support the + __FUNCTION__ pseudo-macro. --*/ -int DBG_printf_gcc(DBG_CHANNEL_ID channel, DBG_LEVEL_ID level, BOOL bHeader, - LPCSTR function, LPCSTR file, INT line, LPCSTR format, ...) +int DBG_printf(DBG_CHANNEL_ID channel, DBG_LEVEL_ID level, BOOL bHeader, + LPCSTR function, LPCSTR file, INT line, LPCSTR format, ...) { CHAR *buffer = (CHAR*)alloca(DBG_BUFFER_SIZE); CHAR indent[MAX_NESTING+1]; @@ -494,7 +494,7 @@ int DBG_printf_gcc(DBG_CHANNEL_ID channel, DBG_LEVEL_ID level, BOOL bHeader, /* also print file name for ASSERTs, to match Win32 behavior */ if( DLI_ENTRY == level || DLI_ASSERT == level || DLI_EXIT == level) { - output_size=snprintf(buffer, DBG_BUFFER_SIZE, + output_size=snprintf(buffer, DBG_BUFFER_SIZE, "{%p" MODULE_FORMAT "} %-5s [%-7s] at %s.%d: ", thread_id, MODULE_ID dbg_level_names[level], dbg_channel_names[channel], file, line); @@ -506,10 +506,10 @@ int DBG_printf_gcc(DBG_CHANNEL_ID channel, DBG_LEVEL_ID level, BOOL bHeader, thread_id, MODULE_ID dbg_level_names[level], dbg_channel_names[channel], function, line); } - + if(output_size + 1 > DBG_BUFFER_SIZE) { - fprintf(stderr, "ERROR : buffer overflow in DBG_printf_gcc"); + fprintf(stderr, "ERROR : buffer overflow in DBG_printf"); return 1; } @@ -529,7 +529,7 @@ int DBG_printf_gcc(DBG_CHANNEL_ID channel, DBG_LEVEL_ID level, BOOL bHeader, if( output_size > DBG_BUFFER_SIZE ) { - fprintf(stderr, "ERROR : buffer overflow in DBG_printf_gcc"); + fprintf(stderr, "ERROR : buffer overflow in DBG_printf"); } /* Use a Critical section before calling printf code to @@ -543,7 +543,7 @@ int DBG_printf_gcc(DBG_CHANNEL_ID channel, DBG_LEVEL_ID level, BOOL bHeader, /* flush the output to file */ if ( fflush(output_file) != 0 ) { - fprintf(stderr, "ERROR : fflush() failed errno:%d (%s)\n", + fprintf(stderr, "ERROR : fflush() failed errno:%d (%s)\n", errno, strerror(errno)); } @@ -553,115 +553,7 @@ int DBG_printf_gcc(DBG_CHANNEL_ID channel, DBG_LEVEL_ID level, BOOL bHeader, if ( old_errno != errno ) { - fprintf( stderr,"ERROR: errno changed by DBG_printf_gcc\n" ); - errno = old_errno; - } - - return 1; -} - -/*++ -Function : - DBG_printf_c99 - - Internal function for debug channels; don't use. - This function outputs a complete debug message, without function name. - -Parameters : - DBG_CHANNEL_ID channel : debug channel to use - DBG_LEVEL_ID level : debug message level - BOOL bHeader : whether or not to output message header (thread id, etc) - LPSTR file : current file - INT line : line number - LPSTR format, ... : standard printf parameter list. - -Return Value : - always 1. - -Notes : - This version is for compilers that support the C99 flavor of - variable-argument macros but not the gnu flavor, and do not support the - __FUNCTION__ pseudo-macro. - ---*/ -int DBG_printf_c99(DBG_CHANNEL_ID channel, DBG_LEVEL_ID level, BOOL bHeader, - LPSTR file, INT line, LPSTR format, ...) -{ - CHAR *buffer = (CHAR*)alloca(DBG_BUFFER_SIZE); - CHAR indent[MAX_NESTING+1]; - LPSTR buffer_ptr; - INT output_size; - va_list args; - static INT call_count=0; // only use inside the crit section - void *thread_id; - int old_errno = 0; - - old_errno = errno; - - if(!DBG_get_indent(level, format, indent)) - { - return 1; - } - - thread_id= (void *)THREADSilentGetCurrentThreadId(); - - if(bHeader) - { - output_size=snprintf(buffer, DBG_BUFFER_SIZE, - "{%p" MODULE_FORMAT "} %-5s [%-7s] at %s.%d: ", thread_id, MODULE_ID - dbg_level_names[level], dbg_channel_names[channel], - file, line); - - if(output_size + 1 > DBG_BUFFER_SIZE) - { - fprintf(stderr, "ERROR : buffer overflow in DBG_printf_gcc"); - return 1; - } - - buffer_ptr=buffer+output_size; - } - else - { - output_size = 0; - buffer_ptr = buffer; - } - - va_start(args, format); - output_size+=_vsnprintf_s(buffer_ptr, DBG_BUFFER_SIZE-output_size, _TRUNCATE, - format, args); - va_end(args); - - if(output_size>DBG_BUFFER_SIZE) - fprintf(stderr, "ERROR : buffer overflow in DBG_printf_c99"); - - /* Use a Critical section before calling printf code to - avoid holding a libc lock while another thread is calling - SuspendThread on this one. */ - - BOOL do_flush = FALSE; - InternalEnterCriticalSection(NULL, &fprintf_crit_section); - fprintf( output_file, "%s", buffer ); - call_count++; // can use call_count because we are in the crit section - if (call_count>5) - { - call_count = 0; - do_flush = TRUE; - } - InternalLeaveCriticalSection(NULL, &fprintf_crit_section); - - /* flush the output to file every once in a while */ - if (do_flush) - { - if ( fflush(output_file) != 0 ) - { - fprintf(stderr, "ERROR : fflush() failed errno:%d (%s)\n", - errno, strerror(errno)); - } - } - - if ( old_errno != errno ) - { - fprintf( stderr, "ERROR: DBG_printf_c99 changed the errno.\n" ); + fprintf( stderr,"ERROR: errno changed by DBG_printf\n" ); errno = old_errno; } -- 2.7.4