UTDebug.h

Go to the documentation of this file.
00001 //==================================================================================================
00002 // Copyright (C) 2010  Brian Tietz    sdbtietz at yahoo dot com
00003 //
00004 // This program is free software; you can redistribute it and/or modify it under the terms of the
00005 // GNU General Public License as published by the Free Software Foundation, version 2.0 of the
00006 // License.
00007 //
00008 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
00009 // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00010 // General Public License for more details.
00011 //
00012 // You should have received a copy of the GNU General Public License along with this program; if
00013 // not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00014 // 02110-1301, USA.
00015 //
00016 // For commercial software, the copyright holder (Brian Tietz, email sdbtietz at yahoo dot com)
00017 // reserves the right and is willing to waive the proprietary source code disclosure aspects of that
00018 // license as applied to the UT library in exchange for either substantial contributions to the
00019 // development of the UT library or other forms of compensation.  Any such waiver must be
00020 // established in writing between the copyright holder and the commercial entity obtaining such a
00021 // waiver.
00022 //==================================================================================================
00023 
00024 
00025 #ifndef _UT_H_
00026 #error "DO NOT INCLUDE THIS FILE - INCLUDE UT.h INSTEAD"
00027 #endif
00028 
00029 
00030 EXTERN_C_BEGIN
00031 
00032 
00033 //==================================================================================================
00034 //=== Extended debugging facilities
00035 //==================================================================================================
00036 // \cond DOXYGEN_DOCUMENT_NEVER
00037 extern UT_EXPORT void debug_printf_IMPL( stringliteral* format, ... );
00038 #if __cplusplus
00039 #define CAST_VOID(arg)  ( static_cast<void>(arg) )
00040 #else
00041 #define CAST_VOID(arg)  ( (void)(arg) )
00042 #endif
00043 // \endcond
00044 
00045 
00046 //--------------------------------------------------------------------------------------------------
00047 // debug_printf( format, ... )
00048 //--------------------------------------------------------------------------------------------------
00061 #if DEBUG
00062     #define debug_printf                                debug_printf_IMPL
00063     #define debug_printf1                               debug_printf_IMPL
00064     #define debug_printf2                               debug_printf_IMPL
00065     #define debug_printf3                               debug_printf_IMPL
00066     #define debug_printf4                               debug_printf_IMPL
00067     #define debug_printf5                               debug_printf_IMPL
00068     #define debug_printf6                               debug_printf_IMPL
00069     #define debug_printf7                               debug_printf_IMPL
00070     #define debug_printf8                               debug_printf_IMPL
00071     #define debug_printf9                               debug_printf_IMPL
00072 #else
00073     #define debug_printf(a)                             CAST_VOID(0)
00074     #define debug_printf1(a,b)                          CAST_VOID(0)
00075     #define debug_printf2(a,b,c)                        CAST_VOID(0)
00076     #define debug_printf3(a,b,c,d)                      CAST_VOID(0)
00077     #define debug_printf4(a,b,c,d,e)                    CAST_VOID(0)
00078     #define debug_printf5(a,b,c,d,e,f)                  CAST_VOID(0)
00079     #define debug_printf6(a,b,c,d,e,f,g)                CAST_VOID(0)
00080     #define debug_printf7(a,b,c,d,e,f,g,h)              CAST_VOID(0)
00081     #define debug_printf8(a,b,c,d,e,f,g,h,i)            CAST_VOID(0)
00082     #define debug_printf9(a,b,c,d,e,f,g,h,i,j)          CAST_VOID(0)
00083 #endif
00084 
00085 
00086 //--------------------------------------------------------------------------------------------------
00087 // rel_debug_printf( const utf8* format, ... )
00088 //--------------------------------------------------------------------------------------------------
00091 #define rel_debug_printf                                debug_printf_IMPL
00092 
00093 
00094 //--------------------------------------------------------------------------------------------------
00095 // enable_debug_print_to_file( stringliteral*, ... )
00096 //--------------------------------------------------------------------------------------------------
00101 extern UT_EXPORT void enable_debug_print_to_file(   stringliteral* path,
00102                                                     bool exclusive,
00103                                                     bool append,
00104                                                     int buffer_size );
00105 
00106 
00107 //--------------------------------------------------------------------------------------------------
00108 #if __cplusplus
00109 EXTERN_C_END
00110 class Path_t;
00111 class OutputStream_t;
00112 //--------------------------------------------------------------------------------------------------
00113 
00114 
00115 //--------------------------------------------------------------------------------------------------
00116 // enable_debug_print_to_file( const Path_t& path, bool exclusive, bool append, int buffer_size )
00117 //--------------------------------------------------------------------------------------------------
00122 extern UT_EXPORT void enable_debug_print_to_file(   const Path_t& path,
00123                                                     bool exclusive,
00124                                                     bool append,
00125                                                     int buffer_size );
00126 
00127 
00128 //--------------------------------------------------------------------------------------------------
00129 // enable_debug_print_to_stream( takes OutputStream_t* stream, bool exclusive )
00130 //--------------------------------------------------------------------------------------------------
00138 extern UT_EXPORT void enable_debug_print_to_stream( takes OutputStream_t* stream, bool exclusive );
00139 
00140 
00141 //--------------------------------------------------------------------------------------------------
00142 EXTERN_C_BEGIN
00143 #endif // __cplusplus
00144 //--------------------------------------------------------------------------------------------------
00145 
00146 
00147 //--------------------------------------------------------------------------------------------------
00148 // flush_debug_printf(void)
00149 //--------------------------------------------------------------------------------------------------
00151 extern UT_EXPORT void flush_debug_printf(void);
00152 
00153 
00154 //==================================================================================================
00155 //=== Augmented assert implementation
00156 //==================================================================================================
00157 #undef assert
00158 
00159 //--------------------------------------------------------------------------------------------------
00160 // assert(expression)
00161 //--------------------------------------------------------------------------------------------------
00174 #if DEBUG
00175     #define assert(exp)                         CAST_VOID(  (exp)                                  \
00176                                                             || (    assert_PLUS(    #exp,          \
00177                                                                                     __FILE__,      \
00178                                                                                     __LINE__ ),    \
00179                                                                     false ) )
00180 #else
00181     #define assert(exp)                         CAST_VOID(0)
00182 #endif
00183 
00184 // \cond DOXYGEN_DOCUMENT_NEVER
00185 extern UT_EXPORT void assert_PLUS( const void* expr, const void* file, uint32 line );
00186 // \endcond
00187 
00188 
00189 //--------------------------------------------------------------------------------------------------
00190 // rel_assert(expression )
00191 //--------------------------------------------------------------------------------------------------
00193 #define rel_assert(exp)                         CAST_VOID(  (exp)                                  \
00194                                                             || (    assert_PLUS(    #exp,          \
00195                                                                                     __FILE__,      \
00196                                                                                     __LINE__ ),    \
00197                                                                     false ) )
00198 
00199 
00200 //--------------------------------------------------------------------------------------------------
00201 // debug_error(const utf8* message)
00202 //--------------------------------------------------------------------------------------------------
00204 #if DEBUG
00205     #define debug_error(message)                assert_PLUS(    message,                           \
00206                                                                 __FILE__,                          \
00207                                                                 __LINE__ )
00208 #else
00209     #define debug_error(message)                CAST_VOID(0)
00210 #endif
00211 
00212 
00213 //--------------------------------------------------------------------------------------------------
00214 // rel_error(const utf8* message)
00215 //--------------------------------------------------------------------------------------------------
00217 #define rel_error(message)                      assert_PLUS(    message,                           \
00218                                                                 __FILE__,                          \
00219                                                                 __LINE__ )
00220 
00221 
00222 //==================================================================================================
00223 //=== Other debug-related utility functions
00224 //==================================================================================================
00225 
00226 #ifndef debugger
00227 
00228 //--------------------------------------------------------------------------------------------------
00229 // debugger(void)
00230 //--------------------------------------------------------------------------------------------------
00232 extern UT_EXPORT void debugger(void);
00233 
00234 #endif
00235 
00236 //--------------------------------------------------------------------------------------------------
00237 // running_in_debugger(void)
00238 //--------------------------------------------------------------------------------------------------
00240 extern UT_EXPORT bool running_in_debugger(void);
00241 
00242 
00243 //--------------------------------------------------------------------------------------------------
00244 // suicide(void)
00245 //--------------------------------------------------------------------------------------------------
00249 extern UT_EXPORT void suicide(void);
00250 
00251 
00252 //--------------------------------------------------------------------------------------------------
00253 // get_call_stack( uint, uint, out void** )
00254 //--------------------------------------------------------------------------------------------------
00258 extern UT_EXPORT uint get_call_stack(
00259                             uint skip_levels,
00263                             uint max_levels,
00265                             out void** call_stack
00275                     );
00276 
00277 //--------------------------------------------------------------------------------------------------
00278 // debug_print_call_stack(uint)
00279 //--------------------------------------------------------------------------------------------------
00281 extern UT_EXPORT void debug_print_call_stack(
00282                             stringliteral* label,
00290                             uint skip_levels,
00294                             uint print_levels
00296                     );
00297 
00298 
00299 //--------------------------------------------------------------------------------------------------
00300 // is_valid_read_pointer( const void* pointer, int block_size, ValidReadBlock_t optimize )
00301 //--------------------------------------------------------------------------------------------------
00302 
00305 struct ValidReadBlock_t
00306 {
00307     ptr_as_uint_t start;
00308     ptr_as_uint_t end;
00309     bool can_read;
00310 
00311     #if __cplusplus
00312     inline ValidReadBlock_t()
00313     {
00314         start = 0;
00315         end = 0;
00316         can_read = false;
00317     }
00318     #endif
00319 };
00320 
00326 extern UT_EXPORT bool is_valid_read_pointer(    const void* block_address,
00327                                                 int block_size,
00328                                                 struct ValidReadBlock_t* optimize );
00329 
00330 
00331 //--------------------------------------------------------------------------------------------------
00332 // is_valid_string_pointer(const utf8* string)
00333 //--------------------------------------------------------------------------------------------------
00335 extern UT_EXPORT bool is_valid_string_pointer(const utf8* string);
00336 
00337 
00338 //--------------------------------------------------------------------------------------------------
00339 // is_valid_unicode_pointer(const wchar_t* string)
00340 //--------------------------------------------------------------------------------------------------
00342 extern UT_EXPORT bool is_valid_unicode_pointer(const wchar_t* string);
00343 
00344 
00345 EXTERN_C_END

Generated on Tue Dec 14 22:35:05 2010 for UT library by  doxygen 1.6.1