[78b3f52] | 1 | //
|
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
|
---|
| 3 | //
|
---|
| 4 | // The contents of this file are covered under the licence agreement in the
|
---|
| 5 | // file "LICENCE" distributed with Cforall.
|
---|
| 6 | //
|
---|
| 7 | // libdebug.h --
|
---|
| 8 | //
|
---|
| 9 | // Author : Thierry Delisle
|
---|
| 10 | // Created On : Mon Nov 28 12:27:26 2016
|
---|
[6b0b624] | 11 | // Last Modified By : Peter A. Buhr
|
---|
| 12 | // Last Modified On : Sat Jul 22 10:02:24 2017
|
---|
| 13 | // Update Count : 1
|
---|
[78b3f52] | 14 | //
|
---|
| 15 |
|
---|
[6b0b624] | 16 | #pragma once
|
---|
[78b3f52] | 17 |
|
---|
| 18 | #ifdef __CFA_DEBUG__
|
---|
[aa3d77b] | 19 | #define LIB_DEBUG_DO(...) __VA_ARGS__
|
---|
| 20 | #define LIB_NO_DEBUG_DO(...)
|
---|
[2ac095d] | 21 | #define DEBUG_CTX __PRETTY_FUNCTION__
|
---|
| 22 | #define DEBUG_CTX2 , __PRETTY_FUNCTION__
|
---|
| 23 | #define DEBUG_CTX_PARAM const char * caller
|
---|
| 24 | #define DEBUG_CTX_PARAM2 , const char * caller
|
---|
[78b3f52] | 25 | #else
|
---|
[aa3d77b] | 26 | #define LIB_DEBUG_DO(...)
|
---|
| 27 | #define LIB_NO_DEBUG_DO(...) __VA_ARGS__
|
---|
[2ac095d] | 28 | #define DEBUG_CTX
|
---|
| 29 | #define DEBUG_CTX2
|
---|
| 30 | #define DEBUG_CTX_PARAM
|
---|
| 31 | #define DEBUG_CTX_PARAM2
|
---|
[78b3f52] | 32 | #endif
|
---|
| 33 |
|
---|
[4aa2fb2] | 34 | #if !defined(NDEBUG) && (defined(__CFA_DEBUG__) || defined(__CFA_VERIFY__))
|
---|
| 35 | #define verify(x) assert(x)
|
---|
| 36 | #define verifyf(x, ...) assertf(x, __VA_ARGS__)
|
---|
| 37 | #else
|
---|
| 38 | #define verify(x)
|
---|
| 39 | #define verifyf(x, ...)
|
---|
| 40 | #endif
|
---|
| 41 |
|
---|
| 42 |
|
---|
[9d944b2] | 43 | #ifdef __cforall
|
---|
| 44 | extern "C" {
|
---|
| 45 | #endif
|
---|
| 46 | #include <stdarg.h>
|
---|
| 47 |
|
---|
| 48 | extern void __lib_debug_write( int fd, const char *buffer, int len );
|
---|
| 49 | extern void __lib_debug_acquire();
|
---|
| 50 | extern void __lib_debug_release();
|
---|
| 51 | extern void __lib_debug_print_safe ( const char fmt[], ... ) __attribute__(( format (printf, 1, 2) ));
|
---|
| 52 | extern void __lib_debug_print_nolock( const char fmt[], ... ) __attribute__(( format (printf, 1, 2) ));
|
---|
| 53 | extern void __lib_debug_print_vararg( const char fmt[], va_list arg );
|
---|
| 54 | extern void __lib_debug_print_buffer( char buffer[], int buffer_size, const char fmt[], ... ) __attribute__(( format (printf, 3, 4) ));
|
---|
| 55 | #ifdef __cforall
|
---|
| 56 | }
|
---|
| 57 | #endif
|
---|
| 58 |
|
---|
[d9c44c3] | 59 | #ifdef __CFA_DEBUG_PRINT__
|
---|
[aa3d77b] | 60 | #define LIB_DEBUG_WRITE( fd, buffer, len ) __lib_debug_write( fd, buffer, len )
|
---|
| 61 | #define LIB_DEBUG_ACQUIRE() __lib_debug_acquire()
|
---|
| 62 | #define LIB_DEBUG_RELEASE() __lib_debug_release()
|
---|
| 63 | #define LIB_DEBUG_PRINT_SAFE(...) __lib_debug_print_safe (__VA_ARGS__)
|
---|
| 64 | #define LIB_DEBUG_PRINT_NOLOCK(...) __lib_debug_print_nolock (__VA_ARGS__)
|
---|
| 65 | #define LIB_DEBUG_PRINT_BUFFER(...) __lib_debug_print_buffer (__VA_ARGS__)
|
---|
| 66 | #define LIB_DEBUG_PRINT_BUFFER_DECL(fd, ...) char text[256]; int len = snprintf( text, 256, __VA_ARGS__ ); __lib_debug_write( fd, text, len );
|
---|
| 67 | #define LIB_DEBUG_PRINT_BUFFER_LOCAL(fd, ...) len = snprintf( text, 256, __VA_ARGS__ ); __lib_debug_write( fd, text, len );
|
---|
[d9c44c3] | 68 | #else
|
---|
[aa3d77b] | 69 | #define LIB_DEBUG_WRITE(...) ((void)0)
|
---|
| 70 | #define LIB_DEBUG_ACQUIRE() ((void)0)
|
---|
| 71 | #define LIB_DEBUG_RELEASE() ((void)0)
|
---|
| 72 | #define LIB_DEBUG_PRINT_SAFE(...) ((void)0)
|
---|
| 73 | #define LIB_DEBUG_PRINT_NOLOCK(...) ((void)0)
|
---|
| 74 | #define LIB_DEBUG_PRINT_BUFFER(...) ((void)0)
|
---|
| 75 | #define LIB_DEBUG_PRINT_BUFFER_DECL(...) ((void)0)
|
---|
| 76 | #define LIB_DEBUG_PRINT_BUFFER_LOCAL(...) ((void)0)
|
---|
[d9c44c3] | 77 | #endif
|
---|
| 78 |
|
---|
[78b3f52] | 79 | // Local Variables: //
|
---|
| 80 | // mode: c //
|
---|
| 81 | // tab-width: 4 //
|
---|
| 82 | // End: //
|
---|