From 6b5c22d8680573c8a6b259d78ba3c8435514fde9 Mon Sep 17 00:00:00 2001 From: Paulo Cesar Pereira de Andrade Date: Mon, 22 Sep 2008 17:05:21 -0300 Subject: Rework/simplify debug macros. Instead of cut&paste of the name of the current function everywhere, just use cpp's __FUNCTION__ predefined macro. Create two macros to exit a function, named LEAVE() and RETURN(). Functions returning void should call LEAVE() and then explicitly return for now. "Logged" function calls are indented, so a review was done to ensure functions with a ENTER() also have the proper exit macro. The DEBUG macro was changed to have variadic arguments, and this way it is no longer required to prefix arguments with VERBLEV, but now it also is not possible to use another "verbosity value", but it wasn't used in any of the DEBUG macro calls. --- src/smi.h | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'src/smi.h') diff --git a/src/smi.h b/src/smi.h index 583a0c4..bcc0d2d 100644 --- a/src/smi.h +++ b/src/smi.h @@ -65,7 +65,7 @@ authorization from the XFree86 Project and Silicon Motion. /******************************************************************************/ #ifndef SMI_DEBUG -# define SMI_DEBUG 0 +#define SMI_DEBUG 0 #endif #define SMI_USE_IMAGE_WRITES 0 @@ -276,20 +276,25 @@ typedef struct /******************************************************************************/ #if SMI_DEBUG -# define VERBLEV 1 -# define ENTER_PROC(PROCNAME) xf86ErrorFVerb(VERBLEV, "ENTER\t" PROCNAME \ - "(%d)\n", __LINE__); xf86Break1() -# define DEBUG_PROC(PROCNAME) xf86ErrorFVerb(VERBLEV, "DEBUG\t" PROCNAME \ - "(%d)\n", __LINE__); xf86Break2() -# define LEAVE_PROC(PROCNAME) xf86ErrorFVerb(VERBLEV, "LEAVE\t" PROCNAME \ - "(%d)\n", __LINE__); xf86Break1() -# define DEBUG(arg) xf86ErrorFVerb arg +extern int smi_indent; +# define VERBLEV 1 +# define ENTER() xf86ErrorFVerb(VERBLEV, "%*c %s\n",\ + smi_indent++, '>', __FUNCTION__) +# define LEAVE() xf86ErrorFVerb(VERBLEV, "%*c %s\n",\ + --smi_indent, '<', __FUNCTION__) +# define RETURN(value) \ + do { \ + xf86ErrorFVerb(VERBLEV, "%*c %s\n", \ + --smi_indent, '<', __FUNCTION__); \ + return (value); \ + } while (0) +# define DEBUG(...) xf86ErrorFVerb(VERBLEV, __VA_ARGS__) #else -# define VERBLEV 4 -# define ENTER_PROC(PROCNAME) -# define DEBUG_PROC(PROCNAME) -# define LEAVE_PROC(PROCNAME) -# define DEBUG(arg) +# define VERBLEV 4 +# define ENTER() /**/ +# define LEAVE() /**/ +# define RETURN(value) return (value) +# define DEBUG(...) /**/ #endif /* Some Silicon Motion structs & registers */ -- cgit v1.2.3