p_debug.h

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  * 
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  * 
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  * 
00026  **************************************************************************/
00027 
00038 #ifndef P_DEBUG_H_
00039 #define P_DEBUG_H_
00040 
00041 
00042 #include <stdarg.h>
00043 
00044 #include "p_compiler.h"
00045 
00046 
00047 #ifdef  __cplusplus
00048 extern "C" {
00049 #endif
00050 
00051 
00052 #if defined(DBG) || defined(DEBUG)
00053 #ifndef DEBUG
00054 #define DEBUG 1
00055 #endif
00056 #else
00057 #ifndef NDEBUG
00058 #define NDEBUG 1
00059 #endif
00060 #endif
00061 
00062    
00063 /* MSVC bebore VC7 does not have the __FUNCTION__ macro */
00064 #if defined(_MSC_VER) && _MSC_VER < 1300
00065 #define __FUNCTION__ "???"
00066 #endif
00067 
00068 
00069 void _debug_vprintf(const char *format, va_list ap);
00070    
00071 
00072 static INLINE void
00073 _debug_printf(const char *format, ...)
00074 {
00075    va_list ap;
00076    va_start(ap, format);
00077    _debug_vprintf(format, ap);
00078    va_end(ap);
00079 }
00080 
00081 
00091 static INLINE void
00092 debug_printf(const char *format, ...)
00093 {
00094 #ifdef DEBUG
00095    va_list ap;
00096    va_start(ap, format);
00097    _debug_vprintf(format, ap);
00098    va_end(ap);
00099 #else
00100    (void) format; /* silence warning */
00101 #endif
00102 }
00103 
00104 
00105 #ifdef DEBUG
00106 #define debug_vprintf(_format, _ap) _debug_vprintf(_format, _ap)
00107 #else
00108 #define debug_vprintf(_format, _ap) ((void)0)
00109 #endif
00110 
00111 
00112 #ifdef DEBUG
00113 
00117 void debug_print_blob( const char *name, const void *blob, unsigned size );
00118 
00119 /* Print a message along with a prettified format string
00120  */
00121 void debug_print_format(const char *msg, unsigned fmt );
00122 #else
00123 #define debug_print_blob(_name, _blob, _size) ((void)0)
00124 #define debug_print_format(_msg, _fmt) ((void)0)
00125 #endif
00126 
00127 
00128 void _debug_break(void);
00129 
00130 
00134 #ifdef DEBUG
00135 #if defined(PIPE_ARCH_X86) && defined(PIPE_CC_GCC)
00136 #define debug_break() __asm("int3")
00137 #elif defined(PIPE_ARCH_X86) && defined(PIPE_CC_MSVC)
00138 #define debug_break()  do { _asm {int 3} } while(0)
00139 #else
00140 #define debug_break() _debug_break()
00141 #endif
00142 #else /* !DEBUG */
00143 #define debug_break() ((void)0)
00144 #endif /* !DEBUG */
00145 
00146 
00147 long
00148 debug_get_num_option(const char *name, long dfault);
00149 
00150 void _debug_assert_fail(const char *expr, 
00151                         const char *file, 
00152                         unsigned line, 
00153                         const char *function);
00154 
00155 
00162 #ifdef DEBUG
00163 #define debug_assert(expr) ((expr) ? (void)0 : _debug_assert_fail(#expr, __FILE__, __LINE__, __FUNCTION__))
00164 #else
00165 #define debug_assert(expr) ((void)0)
00166 #endif
00167 
00168 
00170 #ifdef assert
00171 #undef assert
00172 #endif
00173 #define assert(expr) debug_assert(expr)
00174 
00175 
00179 #ifdef DEBUG
00180 #define debug_checkpoint() \
00181    _debug_printf("%s\n", __FUNCTION__)
00182 #else
00183 #define debug_checkpoint() \
00184    ((void)0) 
00185 #endif
00186 
00187 
00191 #ifdef DEBUG
00192 #define debug_checkpoint_full() \
00193    _debug_printf("%s:%u:%s", __FILE__, __LINE__, __FUNCTION__) 
00194 #else
00195 #define debug_checkpoint_full() \
00196    ((void)0) 
00197 #endif
00198 
00199 
00203 #ifdef DEBUG
00204 #define debug_warning(__msg) \
00205    _debug_printf("%s:%u:%s: warning: %s\n", __FILE__, __LINE__, __FUNCTION__, __msg)
00206 #else
00207 #define debug_warning(__msg) \
00208    ((void)0) 
00209 #endif
00210 
00211 
00215 #ifdef DEBUG
00216 #define debug_error(__msg) \
00217    _debug_printf("%s:%u:%s: error: %s\n", __FILE__, __LINE__, __FUNCTION__, __msg) 
00218 #else
00219 #define debug_error(__msg) \
00220    _debug_printf("error: %s\n", __msg)
00221 #endif
00222 
00223 
00227 struct debug_named_value
00228 {
00229    const char *name;
00230    unsigned long value;
00231 };
00232 
00233 
00253 #define DEBUG_NAMED_VALUE(__symbol) {#__symbol, (unsigned long)__symbol} 
00254 #define DEBUG_NAMED_VALUE_END {NULL, 0} 
00255 
00256 
00260 const char *
00261 debug_dump_enum(const struct debug_named_value *names, 
00262                 unsigned long value);
00263 
00264 
00268 const char *
00269 debug_dump_flags(const struct debug_named_value *names, 
00270                  unsigned long value);
00271 
00272 
00285 const char *
00286 debug_get_option(const char *name, const char *dfault);
00287 
00288 boolean
00289 debug_get_bool_option(const char *name, boolean dfault);
00290 
00291 long
00292 debug_get_num_option(const char *name, long dfault);
00293 
00294 unsigned long
00295 debug_get_flags_option(const char *name, 
00296                        const struct debug_named_value *flags,
00297                        unsigned long dfault);
00298 
00299 
00300 void *
00301 debug_malloc(const char *file, unsigned line, const char *function,
00302              size_t size);
00303 
00304 void
00305 debug_free(const char *file, unsigned line, const char *function,
00306            void *ptr);
00307 
00308 void *
00309 debug_calloc(const char *file, unsigned line, const char *function,
00310              size_t count, size_t size );
00311 
00312 void *
00313 debug_realloc(const char *file, unsigned line, const char *function,
00314               void *old_ptr, size_t old_size, size_t new_size );
00315 
00316 unsigned long
00317 debug_memory_begin(void);
00318 
00319 void 
00320 debug_memory_end(unsigned long beginning);
00321 
00322 
00323 #if defined(PROFILE) && defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
00324 
00325 void
00326 debug_profile_start(void);
00327 
00328 void 
00329 debug_profile_stop(void);
00330 
00331 #endif
00332 
00333 
00334 #ifdef DEBUG
00335 struct pipe_surface;
00336 void debug_dump_image(const char *prefix,
00337                       unsigned format, unsigned cpp,
00338                       unsigned width, unsigned height,
00339                       unsigned stride,
00340                       const void *data);
00341 void debug_dump_surface(const char *prefix,
00342                         struct pipe_surface *surface);   
00343 void debug_dump_surface_bmp(const char *filename,
00344                             struct pipe_surface *surface);
00345 #else
00346 #define debug_dump_image(prefix, format, cpp, width, height, stride, data) ((void)0)
00347 #define debug_dump_surface(prefix, surface) ((void)0)
00348 #define debug_dump_surface_bmp(filename, surface) ((void)0)
00349 #endif
00350 
00351 
00352 #ifdef  __cplusplus
00353 }
00354 #endif
00355 
00356 #endif /* P_DEBUG_H_ */

Generated on Tue Sep 29 06:25:17 2009 for Gallium3D by  doxygen 1.5.4